ccif_c2k_platform.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. #include <linux/platform_device.h>
  2. #include <linux/interrupt.h>
  3. #include <mach/mt_spm_sleep.h>
  4. #include "ccci_core.h"
  5. #include "ccci_platform.h"
  6. #include "ccif_c2k_platform.h"
  7. #include "modem_ccif.h"
  8. #include "modem_reg_base.h"
  9. #include <mach/upmu_common.h>
  10. #include <mach/mt_boot.h>
  11. #ifdef CONFIG_OF
  12. #include <linux/of.h>
  13. #include <linux/of_fdt.h>
  14. #include <linux/of_irq.h>
  15. #include <linux/of_address.h>
  16. #endif
  17. #define TAG "cif"
  18. #if !defined(CONFIG_MTK_LEGACY)
  19. #include <linux/clk.h>
  20. static struct clk *clk_scp_sys_md2_main;
  21. static struct clk *clk_scp_sys_md3_main;
  22. #else
  23. #include <mach/mt_clkmgr.h>
  24. #endif
  25. #define PCCIF_BUSY (0x4)
  26. #define PCCIF_TCHNUM (0xC)
  27. #define PCCIF_ACK (0x14)
  28. #define PCCIF_CHDATA (0x100)
  29. #define PCCIF_SRAM_SIZE (512)
  30. int md_ccif_get_modem_hw_info(struct platform_device *dev_ptr,
  31. struct ccci_dev_cfg *dev_cfg,
  32. struct md_hw_info *hw_info)
  33. {
  34. struct device_node *node = NULL;
  35. memset(dev_cfg, 0, sizeof(struct ccci_dev_cfg));
  36. memset(hw_info, 0, sizeof(struct md_hw_info));
  37. #ifdef CONFIG_OF
  38. if (dev_ptr->dev.of_node == NULL) {
  39. CCCI_ERR_MSG(dev_cfg->index, TAG, "modem OF node NULL\n");
  40. return -1;
  41. }
  42. of_property_read_u32(dev_ptr->dev.of_node, "cell-index",
  43. &dev_cfg->index);
  44. CCCI_INF_MSG(dev_cfg->index, TAG, "modem hw info get idx:%d\n",
  45. dev_cfg->index);
  46. if (!get_modem_is_enabled(dev_cfg->index)) {
  47. CCCI_ERR_MSG(dev_cfg->index, TAG, "modem %d not enable, exit\n",
  48. dev_cfg->index + 1);
  49. return -1;
  50. }
  51. #else
  52. struct ccci_dev_cfg *dev_cfg_ptr =
  53. (struct ccci_dev_cfg *)dev->dev.platform_data;
  54. dev_cfg->index = dev_cfg_ptr->index;
  55. CCCI_INF_MSG(dev_cfg->index, TAG, "modem hw info get idx:%d\n",
  56. dev_cfg->index);
  57. if (!get_modem_is_enabled(dev_cfg->index)) {
  58. CCCI_ERR_MSG(dev_cfg->index, TAG, "modem %d not enable, exit\n",
  59. dev_cfg->index + 1);
  60. return -1;
  61. }
  62. #endif
  63. switch (dev_cfg->index) {
  64. case 1: /*MD_SYS2 */
  65. #ifdef CONFIG_OF
  66. of_property_read_u32(dev_ptr->dev.of_node, "ccif,major",
  67. &dev_cfg->major);
  68. of_property_read_u32(dev_ptr->dev.of_node, "ccif,minor_base",
  69. &dev_cfg->minor_base);
  70. of_property_read_u32(dev_ptr->dev.of_node, "ccif,capability",
  71. &dev_cfg->capability);
  72. hw_info->ap_ccif_base = of_iomap(dev_ptr->dev.of_node, 0);
  73. /*hw_info->md_ccif_base = hw_info->ap_ccif_base+0x1000; */
  74. node = of_find_compatible_node(NULL, NULL, "mediatek,MD_CCIF1");
  75. hw_info->md_ccif_base = of_iomap(node, 0);
  76. hw_info->ap_ccif_irq_id =
  77. irq_of_parse_and_map(dev_ptr->dev.of_node, 0);
  78. hw_info->md_wdt_irq_id =
  79. irq_of_parse_and_map(dev_ptr->dev.of_node, 1);
  80. /*Device tree using none flag to register irq, sensitivity has set at "irq_of_parse_and_map" */
  81. hw_info->ap_ccif_irq_flags = IRQF_TRIGGER_NONE;
  82. hw_info->md_wdt_irq_flags = IRQF_TRIGGER_NONE;
  83. #endif
  84. hw_info->sram_size = CCIF_SRAM_SIZE;
  85. hw_info->md_rgu_base = MD2_RGU_BASE;
  86. hw_info->md_boot_slave_Vector = MD2_BOOT_VECTOR;
  87. hw_info->md_boot_slave_Key = MD2_BOOT_VECTOR_KEY;
  88. hw_info->md_boot_slave_En = MD2_BOOT_VECTOR_EN;
  89. #if !defined(CONFIG_MTK_LEGACY)
  90. clk_scp_sys_md2_main =
  91. devm_clk_get(&dev_ptr->dev, "scp-sys-md2-main");
  92. if (IS_ERR(clk_scp_sys_md2_main)) {
  93. CCCI_ERR_MSG(dev_cfg->index, TAG,
  94. "modem %d get scp-sys-md2-main failed\n",
  95. dev_cfg->index + 1);
  96. return -1;
  97. }
  98. #endif
  99. break;
  100. case 2: /*MD_SYS3 */
  101. #ifdef CONFIG_OF
  102. of_property_read_u32(dev_ptr->dev.of_node, "ccif,major",
  103. &dev_cfg->major);
  104. of_property_read_u32(dev_ptr->dev.of_node, "ccif,minor_base",
  105. &dev_cfg->minor_base);
  106. of_property_read_u32(dev_ptr->dev.of_node, "ccif,capability",
  107. &dev_cfg->capability);
  108. hw_info->ap_ccif_base = of_iomap(dev_ptr->dev.of_node, 0);
  109. /*hw_info->md_ccif_base = hw_info->ap_ccif_base+0x1000; */
  110. node = of_find_compatible_node(NULL, NULL, "mediatek,MD_CCIF1");
  111. hw_info->md_ccif_base = of_iomap(node, 0);
  112. hw_info->ap_ccif_irq_id =
  113. irq_of_parse_and_map(dev_ptr->dev.of_node, 0);
  114. hw_info->md_wdt_irq_id =
  115. irq_of_parse_and_map(dev_ptr->dev.of_node, 1);
  116. /*Device tree using none flag to register irq, sensitivity has set at "irq_of_parse_and_map" */
  117. hw_info->ap_ccif_irq_flags = IRQF_TRIGGER_NONE;
  118. hw_info->md_wdt_irq_flags = IRQF_TRIGGER_NONE;
  119. hw_info->md1_pccif_base =
  120. (unsigned long)of_iomap(dev_ptr->dev.of_node, 1);
  121. hw_info->md3_pccif_base =
  122. (unsigned long)of_iomap(dev_ptr->dev.of_node, 2);
  123. node =
  124. of_find_compatible_node(NULL, NULL, "mediatek,INFRACFG_AO");
  125. hw_info->infra_ao_base = (unsigned long)of_iomap(node, 0);
  126. node = of_find_compatible_node(NULL, NULL, "mediatek,SLEEP");
  127. hw_info->sleep_base = (unsigned long)of_iomap(node, 0);
  128. node = of_find_compatible_node(NULL, NULL, "mediatek,TOPRGU");
  129. hw_info->toprgu_base = (unsigned long)of_iomap(node, 0);
  130. CCCI_INF_MSG(dev_cfg->index, TAG,
  131. "infra_ao_base=0x%lx, sleep_base=0x%lx, toprgu_base=0x%lx\n",
  132. hw_info->infra_ao_base, hw_info->sleep_base,
  133. hw_info->toprgu_base);
  134. #endif
  135. hw_info->sram_size = CCIF_SRAM_SIZE;
  136. hw_info->md_rgu_base = MD3_RGU_BASE;
  137. #if !defined(CONFIG_MTK_LEGACY)
  138. clk_scp_sys_md3_main =
  139. devm_clk_get(&dev_ptr->dev, "scp-sys-md2-main");
  140. if (IS_ERR(clk_scp_sys_md3_main)) {
  141. CCCI_ERR_MSG(dev_cfg->index, TAG,
  142. "modem %d get scp-sys-md2-main failed\n",
  143. dev_cfg->index + 1);
  144. return -1;
  145. }
  146. #endif
  147. /*no boot slave for md3 */
  148. /*
  149. hw_info->md_boot_slave_Vector = MD3_BOOT_VECTOR;
  150. hw_info->md_boot_slave_Key = MD3_BOOT_VECTOR_KEY;
  151. hw_info->md_boot_slave_En = MD3_BOOT_VECTOR_EN;
  152. */
  153. break;
  154. default:
  155. return -1;
  156. }
  157. CCCI_INF_MSG(dev_cfg->index, TAG,
  158. "modem ccif of node get dev_major:%d\n", dev_cfg->major);
  159. CCCI_INF_MSG(dev_cfg->index, TAG,
  160. "modem ccif of node get minor_base:%d\n",
  161. dev_cfg->minor_base);
  162. CCCI_INF_MSG(dev_cfg->index, TAG,
  163. "modem ccif of node get capability:%d\n",
  164. dev_cfg->capability);
  165. CCCI_INF_MSG(dev_cfg->index, TAG, "ap_ccif_base:0x%p\n",
  166. (void *)hw_info->ap_ccif_base);
  167. CCCI_INF_MSG(dev_cfg->index, TAG, "ccif_irq_id:%d\n",
  168. hw_info->ap_ccif_irq_id);
  169. CCCI_INF_MSG(dev_cfg->index, TAG, "md_wdt_irq_id:%d\n",
  170. hw_info->md_wdt_irq_id);
  171. return 0;
  172. }
  173. int md_ccif_io_remap_md_side_register(struct ccci_modem *md)
  174. {
  175. struct md_ccif_ctrl *md_ctrl = (struct md_ccif_ctrl *)md->private_data;
  176. switch (md->index) {
  177. case MD_SYS2:
  178. md_ctrl->md_boot_slave_Vector =
  179. ioremap_nocache(md_ctrl->hw_info->md_boot_slave_Vector,
  180. 0x4);
  181. md_ctrl->md_boot_slave_Key =
  182. ioremap_nocache(md_ctrl->hw_info->md_boot_slave_Key, 0x4);
  183. md_ctrl->md_boot_slave_En =
  184. ioremap_nocache(md_ctrl->hw_info->md_boot_slave_En, 0x4);
  185. md_ctrl->md_rgu_base =
  186. ioremap_nocache(md_ctrl->hw_info->md_rgu_base, 0x40);
  187. break;
  188. case MD_SYS3:
  189. break;
  190. }
  191. return 0;
  192. }
  193. /*need modify according to dummy ap*/
  194. int md_ccif_let_md_go(struct ccci_modem *md)
  195. {
  196. struct md_ccif_ctrl *md_ctrl = (struct md_ccif_ctrl *)md->private_data;
  197. if (MD_IN_DEBUG(md)) {
  198. CCCI_INF_MSG(md->index, TAG, "DBG_FLAG_JTAG is set\n");
  199. return -1;
  200. }
  201. CCCI_INF_MSG(md->index, TAG, "md_ccif_let_md_go\n");
  202. switch (md->index) {
  203. case MD_SYS2:
  204. /*set the start address to let modem to run */
  205. /*make boot vector programmable */
  206. ccif_write32(md_ctrl->md_boot_slave_Key, 0, MD2_BOOT_VECTOR_KEY_VALUE);
  207. /*after remap, MD ROM address is 0 from MD's view */
  208. ccif_write32(md_ctrl->md_boot_slave_Vector, 0, MD2_BOOT_VECTOR_VALUE);
  209. /*make boot vector take effect */
  210. ccif_write32(md_ctrl->md_boot_slave_En, 0, MD2_BOOT_VECTOR_EN_VALUE);
  211. break;
  212. case MD_SYS3:
  213. /*check if meta mode */
  214. if (is_meta_mode() || get_boot_mode() == FACTORY_BOOT) {
  215. ccif_write32(md_ctrl->hw_info->infra_ao_base,
  216. INFRA_AO_C2K_CONFIG,
  217. (ccif_read32
  218. (md_ctrl->hw_info->infra_ao_base,
  219. INFRA_AO_C2K_CONFIG) | ETS_SEL_BIT));
  220. }
  221. /*step 1: set C2K boot mode */
  222. ccif_write32(md_ctrl->hw_info->infra_ao_base,
  223. INFRA_AO_C2K_CONFIG,
  224. (ccif_read32
  225. (md_ctrl->hw_info->infra_ao_base,
  226. INFRA_AO_C2K_CONFIG) & (~(0x7 << 8))) | (0x5 <<
  227. 8));
  228. CCCI_INF_MSG(md->index, TAG, "C2K_CONFIG = 0x%x\n",
  229. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  230. INFRA_AO_C2K_CONFIG));
  231. /*step 2: config srcclkena selection mask */
  232. ccif_write32(md_ctrl->hw_info->infra_ao_base,
  233. INFRA_AO_C2K_SPM_CTRL,
  234. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  235. INFRA_AO_C2K_SPM_CTRL) & (~(0x3 <<
  236. 4)));
  237. ccif_write32(md_ctrl->hw_info->infra_ao_base,
  238. INFRA_AO_C2K_SPM_CTRL,
  239. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  240. INFRA_AO_C2K_SPM_CTRL) | (0x2 << 4));
  241. CCCI_INF_MSG(md->index, TAG, "C2K_SPM_CTRL = 0x%x\n",
  242. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  243. INFRA_AO_C2K_SPM_CTRL));
  244. ccif_write32(md_ctrl->hw_info->sleep_base, SLEEP_CLK_CON,
  245. ccif_read32(md_ctrl->hw_info->sleep_base,
  246. SLEEP_CLK_CON) | 0xc);
  247. ccif_write32(md_ctrl->hw_info->sleep_base, SLEEP_CLK_CON,
  248. ccif_read32(md_ctrl->hw_info->sleep_base,
  249. SLEEP_CLK_CON) & (~(0x1 << 14)));
  250. ccif_write32(md_ctrl->hw_info->sleep_base, SLEEP_CLK_CON,
  251. ccif_read32(md_ctrl->hw_info->sleep_base,
  252. SLEEP_CLK_CON) | (0x1 << 12));
  253. ccif_write32(md_ctrl->hw_info->sleep_base, SLEEP_CLK_CON,
  254. ccif_read32(md_ctrl->hw_info->sleep_base,
  255. SLEEP_CLK_CON) | (0x1 << 27));
  256. CCCI_INF_MSG(md->index, TAG, "SLEEP_CLK_CON = 0x%x\n",
  257. ccif_read32(md_ctrl->hw_info->sleep_base,
  258. SLEEP_CLK_CON));
  259. /*step 3: PMIC VTCXO_1 enable */
  260. pmic_config_interface(0x0A02, 0xA12E, 0xFFFF, 0x0);
  261. /*step 4: reset C2K */
  262. #if 0
  263. ccif_write32(md_ctrl->hw_info->toprgu_base,
  264. TOP_RGU_WDT_SWSYSRST,
  265. (ccif_read32
  266. (md_ctrl->hw_info->toprgu_base,
  267. TOP_RGU_WDT_SWSYSRST) | 0x88000000) & (~(0x1 <<
  268. 15)));
  269. #else
  270. mtk_wdt_set_c2k_sysrst(1);
  271. #endif
  272. CCCI_INF_MSG(md->index, TAG,
  273. "[C2K] TOP_RGU_WDT_SWSYSRST = 0x%x\n",
  274. ccif_read32(md_ctrl->hw_info->toprgu_base,
  275. TOP_RGU_WDT_SWSYSRST));
  276. /*step 5: mpu already set */
  277. /*step 6: wake up C2K */
  278. ccif_write32(md_ctrl->hw_info->infra_ao_base,
  279. INFRA_AO_C2K_SPM_CTRL,
  280. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  281. INFRA_AO_C2K_SPM_CTRL) | 0x1);
  282. while (!
  283. ((ccif_read32
  284. (md_ctrl->hw_info->infra_ao_base,
  285. INFRA_AO_C2K_STATUS) >> 1) & 0x1)) {
  286. CCCI_INF_MSG(md->index, TAG,
  287. "[C2K] C2K_STATUS = 0x%x\n",
  288. ccif_read32(md_ctrl->hw_info->
  289. infra_ao_base,
  290. INFRA_AO_C2K_STATUS));
  291. }
  292. ccif_write32(md_ctrl->hw_info->infra_ao_base,
  293. INFRA_AO_C2K_SPM_CTRL,
  294. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  295. INFRA_AO_C2K_SPM_CTRL) & (~0x1));
  296. CCCI_INF_MSG(md->index, TAG,
  297. "[C2K] C2K_SPM_CTRL = 0x%x, C2K_STATUS = 0x%x\n",
  298. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  299. INFRA_AO_C2K_SPM_CTRL),
  300. ccif_read32(md_ctrl->hw_info->infra_ao_base,
  301. INFRA_AO_C2K_STATUS));
  302. break;
  303. }
  304. return 0;
  305. }
  306. int md_ccif_power_on(struct ccci_modem *md)
  307. {
  308. int ret = 0;
  309. struct md_ccif_ctrl *md_ctrl = (struct md_ccif_ctrl *)md->private_data;
  310. switch (md->index) {
  311. case MD_SYS2:
  312. #if defined(CONFIG_MTK_LEGACY)
  313. CCCI_INF_MSG(md->index, TAG, "Call start md_power_on()\n");
  314. ret = md_power_on(SYS_MD2);
  315. CCCI_INF_MSG(md->index, TAG, "Call end md_power_on() ret=%d\n",
  316. ret);
  317. #else
  318. CCCI_INF_MSG(md->index, TAG,
  319. "Call start clk_prepare_enable()\n");
  320. clk_prepare_enable(clk_scp_sys_md2_main);
  321. CCCI_INF_MSG(md->index, TAG, "Call end clk_prepare_enable()\n");
  322. #endif
  323. break;
  324. case MD_SYS3:
  325. #if defined(CONFIG_MTK_LEGACY)
  326. CCCI_INF_MSG(md->index, TAG, "Call start md_power_on()\n");
  327. ret = md_power_on(SYS_MD2);
  328. CCCI_INF_MSG(md->index, TAG, "Call end md_power_on() ret=%d\n",
  329. ret);
  330. #else
  331. CCCI_INF_MSG(md->index, TAG,
  332. "Call start clk_prepare_enable()\n");
  333. clk_prepare_enable(clk_scp_sys_md3_main);
  334. CCCI_INF_MSG(md->index, TAG, "Call end clk_prepare_enable()\n");
  335. #endif
  336. break;
  337. }
  338. CCCI_INF_MSG(md->index, TAG, "md_ccif_power_on:ret=%d\n", ret);
  339. if (ret == 0 && md->index != MD_SYS3) {
  340. /*disable MD WDT */
  341. ccif_write32(md_ctrl->md_rgu_base, WDT_MD_MODE,
  342. WDT_MD_MODE_KEY);
  343. }
  344. return ret;
  345. }
  346. int md_ccif_power_off(struct ccci_modem *md, unsigned int timeout)
  347. {
  348. int ret = 0;
  349. switch (md->index) {
  350. case MD_SYS2:
  351. #if defined(CONFIG_MTK_LEGACY)
  352. ret = md_power_off(SYS_MD2, timeout);
  353. #else
  354. clk_disable_unprepare(clk_scp_sys_md2_main);
  355. #endif
  356. break;
  357. case MD_SYS3:
  358. #if defined(CONFIG_MTK_LEGACY)
  359. ret = md_power_off(SYS_MD1, timeout);
  360. #else
  361. clk_disable_unprepare(clk_scp_sys_md3_main);
  362. #endif
  363. break;
  364. }
  365. CCCI_INF_MSG(md->index, TAG, "md_ccif_power_off:ret=%d\n", ret);
  366. return ret;
  367. }
  368. void reset_md1_md3_pccif(struct ccci_modem *md)
  369. {
  370. unsigned int tx_channel = 0;
  371. int i;
  372. struct md_ccif_ctrl *md_ctrl = (struct md_ccif_ctrl *)md->private_data;
  373. struct md_hw_info *hw_info = md_ctrl->hw_info;
  374. /* clear occupied channel */
  375. while (tx_channel < 16) {
  376. if (ccif_read32(hw_info->md1_pccif_base, PCCIF_BUSY) & (1<<tx_channel))
  377. ccif_write32(hw_info->md1_pccif_base, PCCIF_TCHNUM, tx_channel);
  378. if (ccif_read32(hw_info->md3_pccif_base, PCCIF_BUSY) & (1<<tx_channel))
  379. ccif_write32(hw_info->md3_pccif_base, PCCIF_TCHNUM, tx_channel);
  380. tx_channel++;
  381. }
  382. /* clear un-ached channel *.
  383. ccif_write32(hw_info->md1_pccif_base, PCCIF_ACK, ccif_read32(hw_info->md3_pccif_base, PCCIF_BUSY));
  384. ccif_write32(hw_info->md3_pccif_base, PCCIF_ACK, ccif_read32(hw_info->md1_pccif_base, PCCIF_BUSY));
  385. /* clear SRAM */
  386. for (i = 0; i < PCCIF_SRAM_SIZE/sizeof(unsigned int); i++) {
  387. ccif_write32(hw_info->md1_pccif_base, PCCIF_CHDATA + i*sizeof(unsigned int), 0);
  388. ccif_write32(hw_info->md3_pccif_base, PCCIF_CHDATA + i*sizeof(unsigned int), 0);
  389. }
  390. pr_debug("[C2K] Dump MD1 PCCIF\n");
  391. ccci_mem_dump(-1, hw_info->md1_pccif_base, 0x300);
  392. pr_debug("[C2K] Dump MD3 PCCIF\n");
  393. ccci_mem_dump(-1, hw_info->md3_pccif_base, 0x300);
  394. }