ccci_off.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. #include <linux/delay.h>
  2. #include <linux/kthread.h>
  3. #include <mt-plat/sync_write.h>
  4. #include <mt-plat/mt_boot_common.h>
  5. #if defined(CONFIG_MTK_CLKMGR)
  6. #include <mach/mt_clkmgr.h>
  7. #else
  8. #include <linux/clk.h>
  9. #endif /*CONFIG_MTK_CLKMGR */
  10. #include <linux/platform_device.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. #include "ccci_off.h"
  18. #if !defined(CONFIG_MTK_CLKMGR)
  19. static struct clk *clk_scp_sys_md1_main;
  20. #endif
  21. #if !defined(CONFIG_MTK_ECCCI_DRIVER) || defined(CONFIG_MTK_KERNEL_POWER_OFF_CHARGING)
  22. #define sync_write32(v, a) mt_reg_sync_writel(v, a)
  23. #define sync_write16(v, a) mt_reg_sync_writew(v, a)
  24. #define sync_write8(v, a) mt_reg_sync_writeb(v, a)
  25. #define MD_TOPSM_BASE (0x20030000)
  26. #define MD_TOPSM_RM_TMR_PWR0(base) ((base)+0x0018)
  27. #define MD_TOPSM_RM_PWR_CON0(base) ((base)+0x0800)
  28. #define MD_TOPSM_RM_PWR_CON1(base) ((base)+0x0804)
  29. #define MD_TOPSM_RM_PWR_CON2(base) ((base)+0x0808)
  30. #define MD_TOPSM_RM_PWR_CON3(base) ((base)+0x080C)
  31. #define MD_TOPSM_RM_PLL_MASK0(base) ((base)+0x0830)
  32. #define MD_TOPSM_RM_PLL_MASK1(base) ((base)+0x0834)
  33. #define MD_TOPSM_SM_REQ_MASK(base) ((base)+0x08B0)
  34. #define MODEM_LITE_TOPSM_BASE (0x23010000)
  35. #define MODEM_LITE_TOPSM_RM_TMR_PWR0(base) ((base)+0x0018)
  36. #define MODEM_LITE_TOPSM_RM_TMR_PWR1(base) ((base)+0x001C)
  37. #define MODEM_LITE_TOPSM_RM_PWR_CON0(base) ((base)+0x0800)
  38. #define MODEM_LITE_TOPSM_RM_PLL_MASK0(base) ((base)+0x0830)
  39. #define MODEM_LITE_TOPSM_RM_PLL_MASK1(base) ((base)+0x0834)
  40. #define MODEM_LITE_TOPSM_SM_REQ_MASK(base) ((base)+0x08B0)
  41. #define MODEM_TOPSM_BASE (0x27010000)
  42. #define MODEM_TOPSM_RM_TMR_PWR0(base) ((base)+0x0018)
  43. #define MODEM_TOPSM_RM_TMR_PWR1(base) ((base)+0x001C)
  44. #define MODEM_TOPSM_RM_PWR_CON1(base) ((base)+0x0804)
  45. #define MODEM_TOPSM_RM_PWR_CON2(base) ((base)+0x0808)
  46. #define MODEM_TOPSM_RM_PWR_CON3(base) ((base)+0x080C)
  47. #define MODEM_TOPSM_RM_PWR_CON4(base) ((base)+0x0810)
  48. #define MODEM_TOPSM_RM_PLL_MASK0(base) ((base)+0x0830)
  49. #define MODEM_TOPSM_RM_PLL_MASK1(base) ((base)+0x0834)
  50. #define MODEM_TOPSM_SM_REQ_MASK(base) ((base)+0x08B0)
  51. #define TDD_BASE (0x24000000)
  52. #define TDD_HALT_CFG_ADDR(base) ((base)+0x00000000)
  53. #define TDD_HALT_STATUS_ADDR(base) ((base)+0x00000002)
  54. #define LTEL1_BASE (0x26600000)
  55. #define MD_PLL_MIXEDSYS_BASE (0x20120000)
  56. #define PLL_PLL_CON2_1(base) ((base)+0x0024)
  57. #define PLL_PLL_CON4(base) ((base)+0x0050)
  58. #define PLL_CLKSW_CKSEL4(base) ((base)+0x0094)
  59. #define PLL_CLKSW_CKSEL6(base) ((base)+0x009C)
  60. #define PLL_DFS_CON7(base) ((base)+0x00AC)
  61. #define PLL_MDPLL_CON0(base) ((base)+0x0100)
  62. #define PLL_ARM7PLL_CON0(base) ((base)+0x0150)
  63. #define PLL_ARM7PLL_CON1(base) ((base)+0x0154)
  64. static void internal_md_power_down(void)
  65. {
  66. int ret = 0;
  67. unsigned short status, i;
  68. void __iomem *md_topsm_base, *modem_lite_topsm_base, *modem_topsm_base,
  69. *tdd_base, *ltelt1_base, *ltelt1_base_1, *ltelt1_base_2,
  70. *md_pll_mixedsys_base;
  71. pr_debug("[ccci-off]shutdown MDSYS1 !!!\n");
  72. #if defined(CONFIG_MTK_CLKMGR)
  73. pr_debug("[ccci-off]Call start md_power_on()\n");
  74. ret = md_power_on(SYS_MD1);
  75. pr_debug("[ccci-off]Call end md_power_on() ret=%d\n", ret);
  76. #else
  77. pr_debug("[ccci-off]Call start clk_prepare_enable()\n");
  78. ret = clk_prepare_enable(clk_scp_sys_md1_main);
  79. pr_debug("[ccci-off]Call end clk_prepare_enable()ret=%d\n", ret);
  80. #endif
  81. pr_debug("[ccci-off]0.power on MD_INFRA/MODEM_TOP ret=%d\n", ret);
  82. if (ret)
  83. return;
  84. md_topsm_base = ioremap_nocache(MD_TOPSM_BASE, 0x8C0);
  85. modem_lite_topsm_base = ioremap_nocache(MODEM_LITE_TOPSM_BASE, 0x08C0);
  86. modem_topsm_base = ioremap_nocache(MODEM_TOPSM_BASE, 0x8C0);
  87. tdd_base = ioremap_nocache(TDD_BASE, 0x010);
  88. ltelt1_base = ioremap_nocache(LTEL1_BASE, 0x60000);
  89. ltelt1_base_1 = ioremap_nocache(0x2012045C, 0x4);
  90. ltelt1_base_2 = ioremap_nocache(0x200308B0, 0x4);
  91. md_pll_mixedsys_base = ioremap_nocache(MD_PLL_MIXEDSYS_BASE, 0x160);
  92. pr_debug("[ccci-off]1.power on MD2G/HSPA\n");
  93. /* power on MD2G */
  94. sync_write32(ioread32(MODEM_LITE_TOPSM_RM_PWR_CON0(modem_lite_topsm_base)) | 0x44,
  95. MODEM_LITE_TOPSM_RM_PWR_CON0(modem_lite_topsm_base));
  96. /* power on MD2G SRAM */
  97. #if 0
  98. sync_write32(ioread32(MODEM_LITE_TOPSM_RM_PWR_CON0(modem_lite_topsm_base)) | 0x88,
  99. MODEM_LITE_TOPSM_RM_PWR_CON0(modem_lite_topsm_base));
  100. #endif
  101. /* power on HSPA */
  102. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON1(modem_topsm_base)) | 0x44,
  103. MODEM_TOPSM_RM_PWR_CON1(modem_topsm_base));
  104. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON2(modem_topsm_base)) | 0x44,
  105. MODEM_TOPSM_RM_PWR_CON2(modem_topsm_base));
  106. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON3(modem_topsm_base)) | 0x44,
  107. MODEM_TOPSM_RM_PWR_CON3(modem_topsm_base));
  108. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON4(modem_topsm_base)) | 0x44,
  109. MODEM_TOPSM_RM_PWR_CON4(modem_topsm_base));
  110. /* power on HSPA SRAM */
  111. #if 0
  112. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON1(modem_topsm_base)) | 0x88,
  113. MODEM_TOPSM_RM_PWR_CON1(modem_topsm_base));
  114. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON2(modem_topsm_base)) | 0x88,
  115. MODEM_TOPSM_RM_PWR_CON2(modem_topsm_base));
  116. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON3(modem_topsm_base)) | 0x88,
  117. MODEM_TOPSM_RM_PWR_CON3(modem_topsm_base));
  118. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON4(modem_topsm_base)) | 0x88,
  119. MODEM_TOPSM_RM_PWR_CON4(modem_topsm_base));
  120. #endif
  121. pr_debug("[ccci-off]2.power off MD2G/HSPA\n");
  122. /* power off MD2G */
  123. sync_write32(0xFFFFFFFF, MD_TOPSM_SM_REQ_MASK(md_topsm_base));
  124. sync_write32(0, MODEM_LITE_TOPSM_RM_TMR_PWR0(modem_lite_topsm_base));
  125. sync_write32(0, MODEM_LITE_TOPSM_RM_TMR_PWR1(modem_lite_topsm_base));
  126. sync_write32(ioread32(MODEM_LITE_TOPSM_RM_PWR_CON0(modem_lite_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  127. MODEM_LITE_TOPSM_RM_PWR_CON0(modem_lite_topsm_base));
  128. /* power off HSPA */
  129. sync_write32(0xFFFFFFFF, MD_TOPSM_SM_REQ_MASK(md_topsm_base));
  130. sync_write32(0, MODEM_TOPSM_RM_TMR_PWR0(modem_topsm_base));
  131. sync_write32(0, MODEM_TOPSM_RM_TMR_PWR1(modem_topsm_base));
  132. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON1(modem_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  133. MODEM_TOPSM_RM_PWR_CON1(modem_topsm_base));
  134. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON2(modem_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  135. MODEM_TOPSM_RM_PWR_CON2(modem_topsm_base));
  136. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON3(modem_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  137. MODEM_TOPSM_RM_PWR_CON3(modem_topsm_base));
  138. sync_write32(ioread32(MODEM_TOPSM_RM_PWR_CON4(modem_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  139. MODEM_TOPSM_RM_PWR_CON4(modem_topsm_base));
  140. pr_debug("[ccci-off]3.power off TDD\n");
  141. sync_write16(0x1, TDD_HALT_CFG_ADDR(tdd_base));
  142. status = ioread16(TDD_HALT_STATUS_ADDR(tdd_base));
  143. while ((status & 0x1) == 0) {
  144. /*
  145. * status & 0x1 TDD is in *HALT* STATE
  146. * status & 0x2 TDD is in *NORMAL* STATE
  147. * status & 0x4 TDD is in *SLEEP* STATE
  148. */
  149. i = 100;
  150. while (i--)
  151. ;
  152. status = ioread16(TDD_HALT_STATUS_ADDR(tdd_base));
  153. }
  154. pr_debug("[ccci-off]4.power off LTEL1\n");
  155. sync_write32(0x01FF, PLL_DFS_CON7(md_pll_mixedsys_base));
  156. sync_write32(0x0010, PLL_PLL_CON4(md_pll_mixedsys_base));
  157. sync_write32(0x6000, PLL_ARM7PLL_CON1(md_pll_mixedsys_base));
  158. sync_write32(0x2000, PLL_ARM7PLL_CON1(md_pll_mixedsys_base));
  159. sync_write32(ioread32(PLL_ARM7PLL_CON0(md_pll_mixedsys_base)) | 0x8000, PLL_ARM7PLL_CON0(md_pll_mixedsys_base));
  160. sync_write32(ioread32(PLL_MDPLL_CON0(md_pll_mixedsys_base)) | 0x8000, PLL_MDPLL_CON0(md_pll_mixedsys_base));
  161. sync_write32(0x4500, PLL_CLKSW_CKSEL4(md_pll_mixedsys_base));
  162. sync_write32(0x0003, PLL_CLKSW_CKSEL6(md_pll_mixedsys_base));
  163. sync_write32(0x21008510, ltelt1_base_1);
  164. sync_write32(ioread32(ltelt1_base_2) | 0xC, ltelt1_base_2);
  165. sync_write32(0x01010101, ltelt1_base + 0x030c8);
  166. sync_write32(0x10041000, ltelt1_base + 0x0306c);
  167. sync_write32(0x10041000, ltelt1_base + 0x03070);
  168. sync_write32(0x10041000, ltelt1_base + 0x03074);
  169. sync_write32(0x10040000, ltelt1_base + 0x0306c);
  170. sync_write32(0x10040000, ltelt1_base + 0x03070);
  171. sync_write32(0x10040000, ltelt1_base + 0x03074);
  172. sync_write32(0x10040000, ltelt1_base + 0x03078);
  173. sync_write32(0x88888888, ltelt1_base + 0x02000);
  174. sync_write32(0x88888888, ltelt1_base + 0x02004);
  175. sync_write32(0x88888888, ltelt1_base + 0x02008);
  176. sync_write32(0x88888888, ltelt1_base + 0x0200c);
  177. sync_write32(0x88888888, ltelt1_base + 0x32000);
  178. sync_write32(0x88888888, ltelt1_base + 0x32004);
  179. sync_write32(0x88888888, ltelt1_base + 0x22000);
  180. sync_write32(0x88888888, ltelt1_base + 0x22004);
  181. sync_write32(0x88888888, ltelt1_base + 0x22008);
  182. sync_write32(0x88888888, ltelt1_base + 0x2200c);
  183. sync_write32(0x88888888, ltelt1_base + 0x22010);
  184. sync_write32(0x88888888, ltelt1_base + 0x22014);
  185. sync_write32(0x88888888, ltelt1_base + 0x22018);
  186. sync_write32(0x88888888, ltelt1_base + 0x2201c);
  187. sync_write32(0x88888888, ltelt1_base + 0x42000);
  188. sync_write32(0x88888888, ltelt1_base + 0x42004);
  189. sync_write32(0x88888888, ltelt1_base + 0x42008);
  190. sync_write32(0x88888888, ltelt1_base + 0x52000);
  191. sync_write32(0x88888888, ltelt1_base + 0x52004);
  192. sync_write32(0x88888888, ltelt1_base + 0x52008);
  193. sync_write32(0x88888888, ltelt1_base + 0x5200c);
  194. sync_write32(0x88888888, ltelt1_base + 0x12000);
  195. sync_write32(0x88888888, ltelt1_base + 0x12004);
  196. sync_write32(0x88888888, ltelt1_base + 0x12008);
  197. sync_write32(0x88888888, ltelt1_base + 0x1200c);
  198. sync_write32(0x0000000C, ltelt1_base + 0x031b4);
  199. sync_write32(0x00520C41, ltelt1_base + 0x031c4);
  200. sync_write32(0x00000004, ltelt1_base + 0x02030);
  201. sync_write32(0x00000008, ltelt1_base + 0x02034);
  202. sync_write32(0x0000000C, ltelt1_base + 0x02038);
  203. sync_write32(0x00000010, ltelt1_base + 0x0203c);
  204. sync_write32(0x00000018, ltelt1_base + 0x02040);
  205. sync_write32(0x00000004, ltelt1_base + 0x32028);
  206. sync_write32(0x00000008, ltelt1_base + 0x3202c);
  207. sync_write32(0x0000000C, ltelt1_base + 0x32030);
  208. sync_write32(0x00000010, ltelt1_base + 0x32034);
  209. sync_write32(0x00000018, ltelt1_base + 0x32038);
  210. sync_write32(0x00080004, ltelt1_base + 0x22044);
  211. sync_write32(0x00100008, ltelt1_base + 0x22048);
  212. sync_write32(0x0000000C, ltelt1_base + 0x2204c);
  213. sync_write32(0x00000010, ltelt1_base + 0x22050);
  214. sync_write32(0x00000018, ltelt1_base + 0x22054);
  215. sync_write32(0x00000004, ltelt1_base + 0x4202c);
  216. sync_write32(0x00000008, ltelt1_base + 0x42030);
  217. sync_write32(0x0000000C, ltelt1_base + 0x42034);
  218. sync_write32(0x00000010, ltelt1_base + 0x42038);
  219. sync_write32(0x00000018, ltelt1_base + 0x4203c);
  220. sync_write32(0x00000004, ltelt1_base + 0x5202c);
  221. sync_write32(0x00000008, ltelt1_base + 0x52030);
  222. sync_write32(0x0000000C, ltelt1_base + 0x52034);
  223. sync_write32(0x00000010, ltelt1_base + 0x52038);
  224. sync_write32(0x00000018, ltelt1_base + 0x5203c);
  225. sync_write32(0x00000004, ltelt1_base + 0x1202c);
  226. sync_write32(0x00000008, ltelt1_base + 0x12030);
  227. sync_write32(0x0000000C, ltelt1_base + 0x12034);
  228. sync_write32(0x00000010, ltelt1_base + 0x12038);
  229. sync_write32(0x00000018, ltelt1_base + 0x1203c);
  230. sync_write32(0x05004321, ltelt1_base + 0x030a0);
  231. sync_write32(0x00432064, ltelt1_base + 0x030a4);
  232. sync_write32(0x0000000F, ltelt1_base + 0x03118);
  233. sync_write32(0x00000000, ltelt1_base + 0x03104);
  234. sync_write32(0x00000000, ltelt1_base + 0x03100);
  235. sync_write32(0x02020006, ltelt1_base + 0x03004);
  236. sync_write32(0x00000002, ltelt1_base + 0x03110);
  237. sync_write32(0x00000001, ltelt1_base + 0x030f0);
  238. sync_write32(ioread32(ltelt1_base + 0x030d4) | 0x1, ltelt1_base + 0x030d4);
  239. sync_write32(0x01010101, ltelt1_base + 0x030b8);
  240. sync_write32(0x01010101, ltelt1_base + 0x030bc);
  241. sync_write32(0x00000000, ltelt1_base + 0x04014);
  242. sync_write32(0x00000190, ltelt1_base + 0x04018);
  243. sync_write32(0x000000C8, ltelt1_base + 0x0401c);
  244. sync_write32(0x0000001E, ltelt1_base + 0x04028);
  245. sync_write32(0x00000001, ltelt1_base + 0x030d4);
  246. udelay(1000);
  247. sync_write32(0x00000030, ltelt1_base + 0x04058);
  248. udelay(1000);
  249. sync_write32(0x00000001, ltelt1_base + 0x03120);
  250. udelay(1000);
  251. sync_write32(0x00000001, ltelt1_base + 0x04000);
  252. udelay(1000);
  253. sync_write32(ioread32(PLL_ARM7PLL_CON0(md_pll_mixedsys_base)) & ~(0x8000),
  254. PLL_ARM7PLL_CON0(md_pll_mixedsys_base));
  255. sync_write32(ioread32(PLL_MDPLL_CON0(md_pll_mixedsys_base)) & ~(0x8000), PLL_MDPLL_CON0(md_pll_mixedsys_base));
  256. sync_write32(0x6000, PLL_ARM7PLL_CON1(md_pll_mixedsys_base));
  257. sync_write32(0x4000, PLL_ARM7PLL_CON1(md_pll_mixedsys_base));
  258. pr_debug("[ccci-off]5.power off LTEL2/ARM7\n");
  259. /* power off LTEL2 */
  260. sync_write32(ioread32(MD_TOPSM_RM_PWR_CON2(md_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  261. MD_TOPSM_RM_PWR_CON2(md_topsm_base));
  262. /* power off ARM7 */
  263. sync_write32(ioread32(MD_TOPSM_RM_PWR_CON3(md_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  264. MD_TOPSM_RM_PWR_CON3(md_topsm_base));
  265. pr_debug("[ccci-off]6.power off ABB\n");
  266. sync_write32(ioread32(MD_TOPSM_RM_PWR_CON1(md_topsm_base)) & ~(0x1 << 2) & ~(0x1 << 6),
  267. MD_TOPSM_RM_PWR_CON1(md_topsm_base));
  268. sync_write32(ioread32(MD_TOPSM_RM_PWR_CON1(md_topsm_base)) | 0x00000090, MD_TOPSM_RM_PWR_CON1(md_topsm_base));
  269. sync_write32(ioread32(MD_TOPSM_RM_PLL_MASK0(md_topsm_base)) | 0xFFFF0000, MD_TOPSM_RM_PLL_MASK0(md_topsm_base));
  270. /* sync_write32(ioread32(MD_TOPSM_RM_PLL_MASK1(md_topsm_base)) | 0xFFFFFFFF,
  271. MD_TOPSM_RM_PLL_MASK1(md_topsm_base));*/
  272. sync_write32(0xFFFFFFFF, MD_TOPSM_RM_PLL_MASK1(md_topsm_base));
  273. /* sync_write32(ioread32(MODEM_TOPSM_RM_PLL_MASK0(modem_topsm_base)) | 0xFFFFFFFF,
  274. MODEM_TOPSM_RM_PLL_MASK0(modem_topsm_base));*/
  275. sync_write32(0xFFFFFFFF, MODEM_TOPSM_RM_PLL_MASK0(modem_topsm_base));
  276. sync_write32(ioread32(MODEM_TOPSM_RM_PLL_MASK1(modem_topsm_base)) | 0x0000000F,
  277. MODEM_TOPSM_RM_PLL_MASK1(modem_topsm_base));
  278. /* sync_write32(ioread32(MODEM_LITE_TOPSM_RM_PLL_MASK0(modem_lite_topsm_base)) | 0xFFFFFFFF,
  279. MODEM_LITE_TOPSM_RM_PLL_MASK0(modem_lite_topsm_base));*/
  280. sync_write32(0xFFFFFFFF, MODEM_LITE_TOPSM_RM_PLL_MASK0(modem_lite_topsm_base));
  281. sync_write32(ioread32(MODEM_LITE_TOPSM_RM_PLL_MASK1(modem_lite_topsm_base)) | 0x0000000F,
  282. MODEM_LITE_TOPSM_RM_PLL_MASK1(modem_lite_topsm_base));
  283. pr_debug("[ccci-off]7.power off CR4\n");
  284. sync_write32(0xFFFFFFFF, MD_TOPSM_SM_REQ_MASK(md_topsm_base));
  285. sync_write32(0x00000000, MD_TOPSM_RM_TMR_PWR0(md_topsm_base));
  286. sync_write32(0x0005229A, MD_TOPSM_RM_PWR_CON0(md_topsm_base));
  287. sync_write32(0xFFFFFFFF, MD_TOPSM_RM_PLL_MASK0(md_topsm_base));
  288. sync_write32(0xFFFFFFFF, MD_TOPSM_RM_PLL_MASK1(md_topsm_base));
  289. sync_write32(0xFFFFFFFF, MODEM_LITE_TOPSM_SM_REQ_MASK(modem_lite_topsm_base));
  290. sync_write32(0xFFFFFFFF, MODEM_LITE_TOPSM_RM_PLL_MASK0(modem_lite_topsm_base));
  291. sync_write32(0xFFFFFFFF, MODEM_LITE_TOPSM_RM_PLL_MASK1(modem_lite_topsm_base));
  292. sync_write32(0xFFFFFFFF, MODEM_TOPSM_SM_REQ_MASK(modem_topsm_base));
  293. sync_write32(0xFFFFFFFF, MODEM_TOPSM_RM_PLL_MASK0(modem_topsm_base));
  294. sync_write32(0xFFFFFFFF, MODEM_TOPSM_RM_PLL_MASK1(modem_topsm_base));
  295. pr_debug("[ccci-off]8.power off MD_INFRA/MODEM_TOP\n");
  296. #if defined(CONFIG_MTK_CLKMGR)
  297. ret = md_power_off(SYS_MD1, 0);
  298. #else
  299. clk_disable_unprepare(clk_scp_sys_md1_main);
  300. #endif
  301. iounmap(md_topsm_base);
  302. iounmap(modem_lite_topsm_base);
  303. iounmap(modem_topsm_base);
  304. iounmap(tdd_base);
  305. iounmap(ltelt1_base);
  306. iounmap(ltelt1_base_1);
  307. iounmap(ltelt1_base_2);
  308. iounmap(md_pll_mixedsys_base);
  309. }
  310. static int modem_power_down_worker(void *data)
  311. {
  312. unsigned int val;
  313. val = get_devinfo_with_index(4);
  314. if ((val & (0x1 << 1)) == 0)
  315. internal_md_power_down();
  316. else
  317. pr_debug("[ccci-off]md1 effused,no need power off\n");
  318. return 0;
  319. }
  320. static void modem_power_down(void)
  321. {
  322. /* start kthread to power down modem */
  323. struct task_struct *md_power_kthread;
  324. md_power_kthread = kthread_run(modem_power_down_worker, NULL, "md_power_off_kthread");
  325. if (IS_ERR(md_power_kthread)) {
  326. pr_debug("[ccci-off] create kthread for power off md fail, only direct call API\n");
  327. modem_power_down_worker(NULL);
  328. } else {
  329. pr_debug("[ccci-off] create kthread for power off md ok\n");
  330. }
  331. }
  332. #endif
  333. int ccci_md_off(void)
  334. {
  335. #ifndef CONFIG_MTK_ECCCI_DRIVER
  336. modem_power_down();
  337. #else
  338. #ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
  339. if ((get_boot_mode() == KERNEL_POWER_OFF_CHARGING_BOOT) || (get_boot_mode() == LOW_POWER_OFF_CHARGING_BOOT)) {
  340. pr_debug("[ccci-off]power off MD in charging mode %d\n", get_boot_mode());
  341. modem_power_down();
  342. }
  343. #endif
  344. #endif
  345. return 0;
  346. }
  347. #if !defined(CONFIG_MTK_CLKMGR)
  348. static int ccci_off_probe(struct platform_device *pdev)
  349. {
  350. clk_scp_sys_md1_main = devm_clk_get(&pdev->dev, "scp-sys-md1-main");
  351. if (IS_ERR(clk_scp_sys_md1_main)) {
  352. pr_debug("[ccci-off]modem %d get scp-sys-md1-main failed\n", 1);
  353. return -1;
  354. }
  355. pr_debug("[ccci-off][CCF]clk_scp_sys_md1_main=%p\n", clk_scp_sys_md1_main);
  356. ccci_md_off();
  357. return 0;
  358. }
  359. static int ccci_off_remove(struct platform_device *pdev)
  360. {
  361. return 0;
  362. }
  363. #ifdef CONFIG_OF
  364. static const struct of_device_id ccci_off_of_ids[] = {
  365. {.compatible = "mediatek,ccci_off",},
  366. {}
  367. };
  368. #endif
  369. static struct platform_driver ccci_off_dev_drv = {
  370. .probe = ccci_off_probe,
  371. .remove = ccci_off_remove,
  372. .driver = {
  373. .name = "ccci_off",
  374. .owner = THIS_MODULE,
  375. #ifdef CONFIG_OF
  376. .of_match_table = ccci_off_of_ids,
  377. #endif
  378. },
  379. };
  380. #endif /* !defined(CONFIG_MTK_CLKMGR) */
  381. static int __init ccci_off_init(void)
  382. {
  383. int ret;
  384. #if defined(CONFIG_MTK_CLKMGR)
  385. pr_debug("ccci_off_init 1\n");
  386. ret = ccci_md_off();
  387. #else
  388. ret = platform_driver_register(&ccci_off_dev_drv);
  389. if (ret)
  390. pr_debug("[ccci-off] platform driver registered failed(%d)\n", ret);
  391. else
  392. pr_debug("[ccci-off]platform driver registered OK\n");
  393. #endif
  394. return 0;
  395. }
  396. module_init(ccci_off_init);