c2k_platform.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. #include <mt-plat/upmu_common.h>
  2. #include <mt-plat/sync_write.h>
  3. #ifdef CONFIG_OF_RESERVED_MEM
  4. #include <linux/of_reserved_mem.h>
  5. #include <mt-plat/mtk_memcfg.h>
  6. #endif
  7. #ifdef CONFIG_OF
  8. #include <linux/of.h>
  9. #include <linux/of_fdt.h>
  10. #include <linux/of_irq.h>
  11. #include <linux/of_address.h>
  12. #endif
  13. #include <mt-plat/mt_gpio.h>
  14. #include <mach/gpio_const.h>
  15. #include <linux/gpio.h>
  16. #if !defined(CONFIG_MTK_CLKMGR)
  17. #include <linux/clk.h>
  18. struct clk *clk_scp_sys_md2_main;
  19. static atomic_t clock_on = ATOMIC_INIT(0);
  20. #else
  21. #include <mach/mt_clkmgr.h>
  22. #endif
  23. #if defined(CONFIG_MTK_LEGACY)
  24. #include <cust_gpio_usage.h>
  25. #endif
  26. #include "c2k_platform.h"
  27. static unsigned long infra_ao_base; /*0x1000_0000 */
  28. static unsigned long sleep_base; /*0x1000_6000 */
  29. static unsigned long toprgu_base; /*0x1000_7000 */
  30. static unsigned long c2k_chip_id_base;
  31. static unsigned long md1_pccif_base;
  32. static unsigned long md3_pccif_base;
  33. static unsigned int c2k_wdt_irq_id;
  34. /*static unsigned long c2k_iram_base;*/
  35. static unsigned long c2k_iram_base_seg2[2] = { 0 };
  36. #define ENABLE_C2K_JTAG 0
  37. #define MD3_BANK0_MAP0 (0x310)
  38. #define MD3_BANK0_MAP1 (0x314)
  39. #define MD3_BANK4_MAP0 (0x318)
  40. #define MD3_BANK4_MAP1 (0x31C)
  41. #define INFRA_AO_C2K_CONFIG (0x330)
  42. #define INFRA_AO_C2K_STATUS (0x334)
  43. #define INFRA_AO_C2K_SPM_CTRL (0x338)
  44. #define SLEEP_CLK_CON (0x400)
  45. #define TOP_RGU_WDT_MODE (0x0)
  46. #define TOP_RGU_WDT_SWRST (0x14)
  47. #define TOP_RGU_WDT_SWSYSRST (0x18)
  48. #define TOP_RGU_WDT_NONRST_REG (0x20)
  49. #define PCCIF_BUSY (0x4)
  50. #define PCCIF_TCHNUM (0xC)
  51. #define PCCIF_ACK (0x14)
  52. #define PCCIF_CHDATA (0x100)
  53. #define PCCIF_SRAM_SIZE (512)
  54. #define AP_PLATFORM_INFO "MT6735E1"
  55. #define ENABLE_C2K_EMI_PROTECTION (1)
  56. #if ENABLE_C2K_EMI_PROTECTION
  57. #include <mach/emi_mpu.h>
  58. #endif
  59. /*===================================================*/
  60. /*MPU Region defination*/
  61. /*===================================================*/
  62. #define MPU_REGION_ID_C2K_ROM 7
  63. #define MPU_REGION_ID_C2K_RW 8
  64. #define MPU_REGION_ID_C2K_SMEM 10
  65. /**
  66. *
  67. *--C2K memory layout--
  68. *
  69. *--0x00AFFFFF _ _ _ _ _ _ _ _
  70. * | share mem |
  71. *--0x00A00000 |_ _ _ _ _ _ _ _ |
  72. * | RAM top |
  73. *--0x00500000 |_ _ _ _ _ _ _ _ |
  74. * | ROM |
  75. *--0x00180000 |_ _ _ _ _ _ _ _ |
  76. * | RAM bottom |
  77. *--0x00000000 |_ _ _ _ _ _ _ _ |
  78. *
  79. **/
  80. #define MD3_ROM_SIZE (0x380000)
  81. #define MD3_RAM_SIZE_BOTTOM (0x180000)
  82. #define MD3_RAM_SIZE_TOP (0x500000)
  83. #define MD3_SHARE_MEM_SIZE (0x100000)
  84. #define AP_READY_BIT (0x1 << 1)
  85. #define AP_WAKE_C2K_BIT (0x1 << 0)
  86. #define ETS_SEL_BIT (0x1 << 13)
  87. #define c2k_write32(b, a, v) mt_reg_sync_writel(v, (b)+(a))
  88. #define c2k_write16(b, a, v) mt_reg_sync_writew(v, (b)+(a))
  89. #define c2k_write8(b, a, v) mt_reg_sync_writeb(v, (b)+(a))
  90. #define c2k_read32(b, a) ioread32((void __iomem *)((b)+(a)))
  91. #define c2k_read16(b, a) ioread16((void __iomem *)((b)+(a)))
  92. #define c2k_read8(b, a) ioread8((void __iomem *)((b)+(a)))
  93. #ifdef CONFIG_OF_RESERVED_MEM
  94. #define CCCI_MD3_MEM_RESERVED_KEY "mediatek,reserve-memory-ccci_md3"
  95. /*C2K reserved memory: total 11M */
  96. #define MD3_MEM_RESERVED_SIZE (MD3_ROM_SIZE + MD3_RAM_SIZE_BOTTOM + MD3_RAM_SIZE_TOP + MD3_SHARE_MEM_SIZE)
  97. #define MD3_MEM_RAM_ROM (MD3_ROM_SIZE + MD3_RAM_SIZE_BOTTOM + MD3_RAM_SIZE_TOP)
  98. phys_addr_t md3_mem_base;
  99. static unsigned long md3_mem_base_virt;
  100. static unsigned int md3_share_mem_size;
  101. #define C2K_IMG_DUMP_SIZE (0x1000)
  102. #define C2K_IMG_DUMP_OFFSET (0x61000)
  103. #define C2K_IRAM_DUMP_SIZE (0x200)
  104. static int first_init = 1;
  105. struct md3_log_memory_info {
  106. unsigned int magic1;
  107. unsigned int magic2;
  108. unsigned int mem_size;
  109. unsigned int mem_base; /* reserved */
  110. };
  111. void c2k_platform_restore_first_init(void)
  112. {
  113. first_init = 1;
  114. }
  115. int modem_sdio_reserve_mem_of_init(struct reserved_mem *rmem)
  116. {
  117. phys_addr_t rptr = 0;
  118. unsigned int rsize = 0;
  119. rptr = rmem->base;
  120. rsize = (unsigned int)rmem->size;
  121. MTK_MEMCFG_LOG_AND_PRINTK("%s,uname:%s,base:0x%llx,size:0x%x\n",
  122. __func__, rmem->name,
  123. (unsigned long long)rptr, rsize);
  124. if (strstr(CCCI_MD3_MEM_RESERVED_KEY, rmem->name)) {
  125. if (rsize < MD3_MEM_RAM_ROM) {
  126. MTK_MEMCFG_LOG_AND_PRINTK("%s: reserve size=0x%x != 0x%x\n",
  127. __func__, rsize,
  128. MD3_MEM_RESERVED_SIZE);
  129. return 0;
  130. }
  131. md3_share_mem_size = rsize - MD3_MEM_RAM_ROM;
  132. }
  133. md3_mem_base = rmem->base;
  134. return 0;
  135. }
  136. RESERVEDMEM_OF_DECLARE(ccci_reserve_mem_md3_init, CCCI_MD3_MEM_RESERVED_KEY,
  137. modem_sdio_reserve_mem_of_init);
  138. #endif
  139. static void c2k_set_log_mem_info(unsigned long start_addr)
  140. {
  141. struct md3_log_memory_info *plog_mem_info = (struct md3_log_memory_info *)start_addr;
  142. plog_mem_info->magic1 = 0x1A2F4D46;
  143. plog_mem_info->magic2 = 0xB33B50D5;
  144. plog_mem_info->mem_size = md3_share_mem_size;
  145. plog_mem_info->mem_base = 0x0;
  146. }
  147. static void c2k_hw_info_init(void)
  148. {
  149. #ifdef CONFIG_OF
  150. struct device_node *node;
  151. node = of_find_compatible_node(NULL, NULL, "mediatek,INFRACFG_AO");
  152. infra_ao_base = (unsigned long)of_iomap(node, 0);
  153. node = of_find_compatible_node(NULL, NULL, "mediatek,SLEEP");
  154. sleep_base = (unsigned long)of_iomap(node, 0);
  155. node = of_find_compatible_node(NULL, NULL, "mediatek,mt6735-rgu");
  156. toprgu_base = (unsigned long)of_iomap(node, 0);
  157. node = of_find_compatible_node(NULL, NULL, "mediatek,mdc2k");
  158. c2k_chip_id_base = (unsigned long)of_iomap(node, 0);
  159. md1_pccif_base = (unsigned long)of_iomap(node, 1);
  160. md3_pccif_base = (unsigned long)of_iomap(node, 2);
  161. c2k_wdt_irq_id = irq_of_parse_and_map(node, 0);
  162. #ifdef CONFIG_OF_RESERVED_MEM
  163. md3_mem_base_virt =
  164. (unsigned long)ioremap_nocache(md3_mem_base + C2K_IMG_DUMP_OFFSET,
  165. C2K_IMG_DUMP_SIZE);
  166. #endif
  167. /*set c2k log memory info at the head of 4K*/
  168. c2k_set_log_mem_info(md3_mem_base_virt);
  169. pr_info("[C2K] log mem size = 0x%x\n", *((unsigned int *)(md3_mem_base_virt+8)));
  170. pr_debug
  171. ("[C2K] infra_ao_base=0x%lx, sleep_base=0x%lx, toprgu_base=0x%lx",
  172. infra_ao_base, sleep_base, toprgu_base);
  173. pr_debug
  174. ("c2k_chip_id_base=0x%lx, md3_mem_base_virt=0x%lx, c2k_wdt_irq_id=%d\n",
  175. c2k_chip_id_base, md3_mem_base_virt, c2k_wdt_irq_id);
  176. #endif
  177. }
  178. void c2k_mem_dump(void *start_addr, int len)
  179. {
  180. unsigned int *curr_p = (unsigned int *)start_addr;
  181. unsigned char *curr_ch_p;
  182. int _16_fix_num = len / 16;
  183. int tail_num = len % 16;
  184. char buf[16];
  185. int i, j;
  186. if (NULL == curr_p) {
  187. pr_debug("[C2K-DUMP]NULL point to dump!\n");
  188. return;
  189. }
  190. if (0 == len) {
  191. pr_debug("[C2K-DUMP]Not need to dump\n");
  192. return;
  193. }
  194. pr_debug("[C2K-DUMP]Base: 0x%lx\n", (unsigned long)start_addr);
  195. /*Fix section */
  196. for (i = 0; i < _16_fix_num; i++) {
  197. pr_debug("[C2K-DUMP]%03X: %08X %08X %08X %08X\n",
  198. i * 16, *curr_p, *(curr_p + 1), *(curr_p + 2),
  199. *(curr_p + 3));
  200. curr_p += 4;
  201. }
  202. /*Tail section */
  203. if (tail_num > 0) {
  204. curr_ch_p = (unsigned char *)curr_p;
  205. for (j = 0; j < tail_num; j++) {
  206. buf[j] = *curr_ch_p;
  207. curr_ch_p++;
  208. }
  209. for (; j < 16; j++)
  210. buf[j] = 0;
  211. curr_p = (unsigned int *)buf;
  212. pr_debug("[C2K-DUMP]%03X: %08X %08X %08X %08X\n",
  213. i * 16, *curr_p, *(curr_p + 1), *(curr_p + 2),
  214. *(curr_p + 3));
  215. }
  216. }
  217. void dump_c2k_iram(void)
  218. {
  219. if (md3_mem_base_virt == 0) {
  220. pr_debug
  221. ("[C2K] md3_mem_base_virt is 0, exit without dump...\n");
  222. return;
  223. }
  224. pr_debug("[C2K] Dump C2K MEM begin, size 4K\n");
  225. c2k_mem_dump((void *)md3_mem_base_virt, C2K_IMG_DUMP_SIZE);
  226. pr_debug("[C2K] Dump C2K MEM end\n");
  227. }
  228. void dump_c2k_iram_seg2(void)
  229. {
  230. int i;
  231. for (i = 0;
  232. i < sizeof(c2k_iram_base_seg2) / sizeof(c2k_iram_base_seg2[0]);
  233. i++) {
  234. if (c2k_iram_base_seg2[i] == 0) {
  235. pr_debug("[C2K] c2k_iram_base_seg2[%d] is 0, exit...\n",
  236. i);
  237. return;
  238. }
  239. pr_debug("[C2K] Dump C2K IRAM begin, start at %lx\n",
  240. c2k_iram_base_seg2[i]);
  241. c2k_mem_dump((void *)c2k_iram_base_seg2[i], C2K_IRAM_DUMP_SIZE);
  242. }
  243. pr_debug("[C2K] Dump C2K MEM end\n");
  244. }
  245. #if ENABLE_C2K_EMI_PROTECTION
  246. void set_c2k_mpu(void)
  247. {
  248. unsigned int shr_mem_phy_start, shr_mem_phy_end, shr_mem_mpu_id,
  249. shr_mem_mpu_attr;
  250. unsigned int rom_mem_phy_start, rom_mem_phy_end, rom_mem_mpu_id,
  251. rom_mem_mpu_attr;
  252. unsigned int rw_mem_phy_start, rw_mem_phy_end, rw_mem_mpu_id,
  253. rw_mem_mpu_attr;
  254. rom_mem_mpu_id = MPU_REGION_ID_C2K_ROM;
  255. rw_mem_mpu_id = MPU_REGION_ID_C2K_RW;
  256. shr_mem_mpu_id = MPU_REGION_ID_C2K_SMEM;
  257. rom_mem_mpu_attr =
  258. SET_ACCESS_PERMISSON(FORBIDDEN, FORBIDDEN, NO_PROTECTION, FORBIDDEN,
  259. FORBIDDEN, FORBIDDEN, FORBIDDEN, SEC_R_NSEC_R);
  260. rw_mem_mpu_attr =
  261. SET_ACCESS_PERMISSON(FORBIDDEN, FORBIDDEN, NO_PROTECTION, FORBIDDEN,
  262. FORBIDDEN, FORBIDDEN, FORBIDDEN, SEC_R_NSEC_R);
  263. shr_mem_mpu_attr =
  264. SET_ACCESS_PERMISSON(FORBIDDEN, FORBIDDEN, NO_PROTECTION, FORBIDDEN,
  265. FORBIDDEN, FORBIDDEN, FORBIDDEN,
  266. NO_PROTECTION);
  267. /*
  268. *if set start=0x0, end=0x10000, the actural protected area will be 0x0-0x1FFFF,
  269. *here we use 64KB align, MPU actually request 32KB align since MT6582, but this works...
  270. *we assume emi_mpu_set_region_protection will round end address down to 64KB align.
  271. */
  272. rw_mem_phy_start = (unsigned int)md3_mem_base;
  273. rw_mem_phy_end =
  274. ((rw_mem_phy_start + MD3_RAM_SIZE_BOTTOM + MD3_ROM_SIZE +
  275. MD3_RAM_SIZE_TOP + 0xFFFF) & (~0xFFFF)) - 0x1;
  276. rom_mem_phy_start =
  277. (unsigned int)(rw_mem_phy_start + MD3_RAM_SIZE_BOTTOM);
  278. rom_mem_phy_end =
  279. ((rom_mem_phy_start + MD3_ROM_SIZE + 0xFFFF) & (~0xFFFF)) - 0x1;
  280. shr_mem_phy_start = rw_mem_phy_end + 0x1;
  281. shr_mem_phy_end = ((shr_mem_phy_start + md3_share_mem_size + 0xFFFF)&(~0xFFFF)) - 0x1;
  282. pr_debug("[C2K] MPU Start protect MD R/W region<%d:%08x:%08x> %x\n",
  283. rw_mem_mpu_id, rw_mem_phy_start, rw_mem_phy_end,
  284. rw_mem_mpu_attr);
  285. emi_mpu_set_region_protection(rw_mem_phy_start, /*START_ADDR */
  286. rw_mem_phy_end, /*END_ADDR */
  287. rw_mem_mpu_id, /*region */
  288. rw_mem_mpu_attr);
  289. pr_debug("[C2K] MPU Start protect MD ROM region<%d:%08x:%08x> %x\n",
  290. rom_mem_mpu_id, rom_mem_phy_start, rom_mem_phy_end,
  291. rom_mem_mpu_attr);
  292. emi_mpu_set_region_protection(rom_mem_phy_start, /*START_ADDR */
  293. rom_mem_phy_end, /*END_ADDR */
  294. rom_mem_mpu_id, /*region */
  295. rom_mem_mpu_attr);
  296. pr_debug("[C2K] MPU Start protect MD Share region<%d:%08x:%08x> %x\n",
  297. shr_mem_mpu_id, shr_mem_phy_start, shr_mem_phy_end,
  298. shr_mem_mpu_attr);
  299. emi_mpu_set_region_protection(shr_mem_phy_start, /*START_ADDR */
  300. shr_mem_phy_end, /*END_ADDR */
  301. shr_mem_mpu_id, /*region */
  302. shr_mem_mpu_attr);
  303. }
  304. #endif
  305. static void md_gpio_get(GPIO_PIN pin, char *tag)
  306. {
  307. pr_debug
  308. ("GPIO%d(%s): mode=%d,dir=%d,in=%d,out=%d,pull_en=%d,pull_sel=%d,smt=%d\n",
  309. pin, tag, mt_get_gpio_mode(pin), mt_get_gpio_dir(pin),
  310. mt_get_gpio_in(pin), mt_get_gpio_out(pin),
  311. mt_get_gpio_pull_enable(pin), mt_get_gpio_pull_select(pin),
  312. mt_get_gpio_smt(pin));
  313. }
  314. static void md_gpio_set(GPIO_PIN pin, GPIO_MODE mode, GPIO_DIR dir,
  315. GPIO_OUT out, GPIO_PULL_EN pull_en, GPIO_PULL pull,
  316. GPIO_SMT smt)
  317. {
  318. mt_set_gpio_mode(pin, mode);
  319. if (dir != GPIO_DIR_UNSUPPORTED)
  320. mt_set_gpio_dir(pin, dir);
  321. if (dir == GPIO_DIR_OUT)
  322. mt_set_gpio_out(pin, out);
  323. if (dir == GPIO_DIR_IN)
  324. mt_set_gpio_smt(pin, smt);
  325. if (pull_en != GPIO_PULL_EN_UNSUPPORTED) {
  326. mt_set_gpio_pull_enable(pin, pull_en);
  327. mt_set_gpio_pull_select(pin, pull);
  328. }
  329. md_gpio_get(pin, "-");
  330. }
  331. void enable_c2k_jtag(unsigned int mode)
  332. {
  333. static void __iomem *c2k_jtag_setting;
  334. if (mode == 1) {
  335. md_gpio_set(0x80000000 | GPIO82, GPIO_MODE_05, GPIO_DIR_IN,
  336. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE,
  337. GPIO_PULL_DOWN, GPIO_SMT_ENABLE);
  338. md_gpio_set(0x80000000 | GPIO81, GPIO_MODE_05, GPIO_DIR_IN,
  339. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE,
  340. GPIO_PULL_UP, GPIO_SMT_ENABLE);
  341. md_gpio_set(0x80000000 | GPIO83, GPIO_MODE_05, GPIO_DIR_IN,
  342. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE,
  343. GPIO_PULL_UP, GPIO_SMT_DISABLE);
  344. md_gpio_set(0x80000000 | GPIO85, GPIO_MODE_05, GPIO_DIR_IN,
  345. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE,
  346. GPIO_PULL_UP, GPIO_SMT_DISABLE);
  347. md_gpio_set(0x80000000 | GPIO84, GPIO_MODE_05, GPIO_DIR_OUT,
  348. GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED,
  349. GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  350. md_gpio_set(0x80000000 | GPIO86, GPIO_MODE_05, GPIO_DIR_OUT,
  351. GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED,
  352. GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  353. } else if (mode == 2) {
  354. if (first_init) {
  355. first_init = 0;
  356. c2k_jtag_setting = ioremap_nocache(0x10000700, 0x04);
  357. }
  358. c2k_write32(c2k_jtag_setting, 0,
  359. c2k_read32(c2k_jtag_setting, 0) | (0x1 << 2));
  360. }
  361. }
  362. void c2k_modem_power_on_platform(void)
  363. {
  364. int ret = 0;
  365. #if ENABLE_C2K_JTAG
  366. /*ARM legacy JTAG for C2K*/
  367. md_gpio_set(0x80000000 | GPIO82, GPIO_MODE_05, GPIO_DIR_IN,
  368. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_DOWN,
  369. GPIO_SMT_ENABLE);
  370. md_gpio_set(0x80000000 | GPIO81, GPIO_MODE_05, GPIO_DIR_IN,
  371. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP,
  372. GPIO_SMT_ENABLE);
  373. md_gpio_set(0x80000000 | GPIO83, GPIO_MODE_05, GPIO_DIR_IN,
  374. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP,
  375. GPIO_SMT_DISABLE);
  376. md_gpio_set(0x80000000 | GPIO85, GPIO_MODE_05, GPIO_DIR_IN,
  377. GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP,
  378. GPIO_SMT_DISABLE);
  379. md_gpio_set(0x80000000 | GPIO84, GPIO_MODE_05, GPIO_DIR_OUT,
  380. GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED,
  381. GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  382. md_gpio_set(0x80000000 | GPIO86, GPIO_MODE_05, GPIO_DIR_OUT,
  383. GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED,
  384. GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  385. #endif
  386. pr_debug("[C2K] c2k_modem_power_on enter\n");
  387. if (infra_ao_base == 0)
  388. c2k_hw_info_init();
  389. pr_debug("[C2K] prepare to power on c2k\n");
  390. /*step 0: power on MTCMOS */
  391. #if defined(CONFIG_MTK_CLKMGR)
  392. ret = md_power_on(SYS_MD2);
  393. #else
  394. if (atomic_inc_return(&clock_on) == 1)
  395. ret = clk_prepare_enable(clk_scp_sys_md2_main);
  396. else
  397. atomic_dec(&clock_on);
  398. #endif
  399. pr_debug("[C2K] md_power_on %d\n", ret);
  400. /*step 1: set C2K boot mode */
  401. c2k_write32(infra_ao_base, INFRA_AO_C2K_CONFIG,
  402. (c2k_read32(infra_ao_base, INFRA_AO_C2K_CONFIG) &
  403. (~(0x7 << 8))));
  404. pr_debug("[C2K] C2K_CONFIG = 0x%x\n",
  405. c2k_read32(infra_ao_base, INFRA_AO_C2K_CONFIG));
  406. /*step 2: config srcclkena selection mask */
  407. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL,
  408. c2k_read32(infra_ao_base,
  409. INFRA_AO_C2K_SPM_CTRL) & (~(0xF << 2)));
  410. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL,
  411. c2k_read32(infra_ao_base,
  412. INFRA_AO_C2K_SPM_CTRL) | (0x9 << 2));
  413. pr_debug("[C2K] C2K_SPM_CTRL = 0x%x\n",
  414. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL));
  415. c2k_write32(sleep_base, SLEEP_CLK_CON,
  416. c2k_read32(sleep_base, SLEEP_CLK_CON) | 0xc);
  417. c2k_write32(sleep_base, SLEEP_CLK_CON,
  418. c2k_read32(sleep_base, SLEEP_CLK_CON) & (~(0x1 << 14)));
  419. c2k_write32(sleep_base, SLEEP_CLK_CON,
  420. c2k_read32(sleep_base, SLEEP_CLK_CON) | (0x1 << 12));
  421. c2k_write32(sleep_base, SLEEP_CLK_CON,
  422. c2k_read32(sleep_base, SLEEP_CLK_CON) | (0x1 << 27));
  423. pr_debug("[C2K] SLEEP_CLK_CON = 0x%x\n",
  424. c2k_read32(sleep_base, SLEEP_CLK_CON));
  425. /*step 3: PMIC VTCXO_1 enable */
  426. pmic_config_interface(0x0A02, 0xA12E, 0xFFFF, 0x0);
  427. /*step 4: reset C2K */
  428. #if 0
  429. c2k_write32(toprgu_base, TOP_RGU_WDT_SWSYSRST,
  430. (c2k_read32(toprgu_base, TOP_RGU_WDT_SWSYSRST) | 0x88000000)
  431. & (~(0x1 << 15)));
  432. #else
  433. mtk_wdt_set_c2k_sysrst(1);
  434. #endif
  435. pr_debug("[C2K] TOP_RGU_WDT_SWSYSRST = 0x%x\n",
  436. c2k_read32(toprgu_base, TOP_RGU_WDT_SWSYSRST));
  437. /*step 5: set memory remap */
  438. if (first_init) {
  439. first_init = 0;
  440. c2k_write32(infra_ao_base, MD3_BANK0_MAP0,
  441. ((((unsigned int)md3_mem_base -
  442. 0x40000000) >> 24) | 0x1) & 0xFF);
  443. #if ENABLE_C2K_EMI_PROTECTION
  444. set_c2k_mpu();
  445. #endif
  446. pr_debug("[C2K] MD3_BANK0_MAP0 = 0x%x\n",
  447. c2k_read32(infra_ao_base, MD3_BANK0_MAP0));
  448. }
  449. /*step 6: wake up C2K */
  450. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL,
  451. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL) | 0x1);
  452. while (!((c2k_read32(infra_ao_base, INFRA_AO_C2K_STATUS) >> 1) & 0x1))
  453. ;
  454. pr_debug("[C2K] C2K_STATUS = 0x%x\n",
  455. c2k_read32(infra_ao_base, INFRA_AO_C2K_STATUS));
  456. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL,
  457. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL) & (~0x1));
  458. pr_debug("[C2K] C2K_SPM_CTRL = 0x%x, C2K_STATUS = 0x%x\n",
  459. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL),
  460. c2k_read32(infra_ao_base, INFRA_AO_C2K_STATUS));
  461. #if 0
  462. while (c2k_read32(c2k_chip_id_base, 0) != 0x020AC000) {
  463. pr_debug("[C2K] C2K_CHIP_ID = 0x%x\n",
  464. c2k_read32(c2k_chip_id_base, 0));
  465. }
  466. pr_debug("[C2K] C2K_CHIP_ID = 0x%x!!\n",
  467. c2k_read32(c2k_chip_id_base, 0));
  468. #endif
  469. }
  470. #define AP_CCIF_BASE (0x10218000)
  471. #define APCCIF_CON (0x00)
  472. #define APCCIF_BUSY (0x04)
  473. #define APCCIF_START (0x08)
  474. #define APCCIF_TCHNUM (0x0C)
  475. #define APCCIF_RCHNUM (0x10)
  476. #define APCCIF_ACK (0x14)
  477. #define APCCIF_CHDATA (0x100)
  478. static void __iomem *ap_ccif_base;
  479. int ccif_notify_c2k(int ch_id)
  480. {
  481. int busy = 0;
  482. if (first_init) {
  483. first_init = 0;
  484. ap_ccif_base = ioremap_nocache(AP_CCIF_BASE, 0x100);
  485. }
  486. busy = c2k_read32(ap_ccif_base, APCCIF_BUSY);
  487. if (busy & (1 << ch_id)) {
  488. pr_debug("[C2K] ccif busy now, ch%d\n", ch_id);
  489. return -1;
  490. }
  491. pr_debug("[C2K] ccif_notify_c2k, ch%d\n", ch_id);
  492. c2k_write32(ap_ccif_base, APCCIF_BUSY, 1 << ch_id);
  493. c2k_write32(ap_ccif_base, APCCIF_TCHNUM, ch_id);
  494. return 0;
  495. }
  496. int dump_ccif(void)
  497. {
  498. pr_debug("[C2K] ccif APCCIF_BUSY(%d), APCCIF_START(%d)\n",
  499. c2k_read32(ap_ccif_base, APCCIF_BUSY), c2k_read32(ap_ccif_base,
  500. APCCIF_START));
  501. return 0;
  502. }
  503. void c2k_modem_power_off_platform(void)
  504. {
  505. int ret = -123;
  506. pr_debug("[C2K] md_power_off begain\n");
  507. #if defined(CONFIG_MTK_CLKMGR)
  508. ret = md_power_off(SYS_MD2, 1000);
  509. #else
  510. atomic_set(&clock_on, 0);
  511. clk_disable_unprepare(clk_scp_sys_md2_main);
  512. #endif
  513. pr_debug("[C2K] md_power_off %d\n", ret);
  514. }
  515. void c2k_modem_reset_platform(void)
  516. {
  517. int ret = 0;
  518. if (infra_ao_base == 0)
  519. c2k_hw_info_init();
  520. c2k_write32(toprgu_base, TOP_RGU_WDT_SWSYSRST,
  521. (c2k_read32(toprgu_base, TOP_RGU_WDT_SWSYSRST) | 0x88000000)
  522. | (0x1 << 15));
  523. #if defined(CONFIG_MTK_CLKMGR)
  524. ret = md_power_on(SYS_MD2);
  525. #else
  526. if (atomic_inc_return(&clock_on) == 1)
  527. ret = clk_prepare_enable(clk_scp_sys_md2_main);
  528. else
  529. atomic_dec(&clock_on);
  530. #endif
  531. pr_debug("[C2K] md_power_on %d\n", ret);
  532. /*step 1: reset C2K */
  533. #if 0
  534. pr_debug("[C2K] set toprgu wdt");
  535. c2k_write32(toprgu_base, TOP_RGU_WDT_SWSYSRST,
  536. (c2k_read32(toprgu_base, TOP_RGU_WDT_SWSYSRST) | 0x88000000)
  537. & (~(0x1 << 15)));
  538. #else
  539. mtk_wdt_set_c2k_sysrst(1);
  540. #endif
  541. pr_debug("[C2K] TOP_RGU_WDT_SWSYSRST = 0x%x\n",
  542. c2k_read32(toprgu_base, TOP_RGU_WDT_SWSYSRST));
  543. /*step 2: wake up C2K */
  544. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL,
  545. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL) | 0x1);
  546. while (!((c2k_read32(infra_ao_base, INFRA_AO_C2K_STATUS) >> 1) & 0x1))
  547. ;
  548. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL,
  549. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL) & (~0x1));
  550. pr_debug("[C2K] C2K_SPM_CTRL = 0x%x\n",
  551. c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL));
  552. #if 0
  553. while (c2k_read32(c2k_chip_id_base, 0) != 0x020AC000) {
  554. pr_debug("[C2K] C2K_CHIP_ID = 0x%x\n",
  555. c2k_read32(c2k_chip_id_base, 0));
  556. }
  557. pr_debug("[C2K] C2K_CHIP_ID = 0x%x\n", c2k_read32(c2k_chip_id_base, 0));
  558. #endif
  559. }
  560. void c2k_modem_reset_pccif(void)
  561. {
  562. unsigned int tx_channel = 0;
  563. int i;
  564. /*clear occupied channel */
  565. while (tx_channel < 16) {
  566. if (c2k_read32(md1_pccif_base, PCCIF_BUSY) & (1 << tx_channel))
  567. c2k_write32(md1_pccif_base, PCCIF_TCHNUM, tx_channel);
  568. if (c2k_read32(md3_pccif_base, PCCIF_BUSY) & (1 << tx_channel))
  569. c2k_write32(md3_pccif_base, PCCIF_TCHNUM, tx_channel);
  570. tx_channel++;
  571. }
  572. /*clear un-ached channel */
  573. c2k_write32(md1_pccif_base, PCCIF_ACK,
  574. c2k_read32(md3_pccif_base, PCCIF_BUSY));
  575. c2k_write32(md3_pccif_base, PCCIF_ACK,
  576. c2k_read32(md1_pccif_base, PCCIF_BUSY));
  577. /*clear SRAM */
  578. for (i = 0; i < PCCIF_SRAM_SIZE / sizeof(unsigned int); i++) {
  579. c2k_write32(md1_pccif_base,
  580. PCCIF_CHDATA + i * sizeof(unsigned int), 0);
  581. c2k_write32(md3_pccif_base,
  582. PCCIF_CHDATA + i * sizeof(unsigned int), 0);
  583. }
  584. /*dump */
  585. /*
  586. pr_debug("[C2K] Dump MD1 PCCIF\n");
  587. ccci_mem_dump(-1, (void *)md1_pccif_base, 0x300);
  588. pr_debug("[C2K] Dump MD3 PCCIF\n");
  589. ccci_mem_dump(-1, (void *)md3_pccif_base, 0x300);
  590. */
  591. }
  592. void set_ap_ready(int value)
  593. {
  594. unsigned int reg_value;
  595. if (infra_ao_base == 0)
  596. c2k_hw_info_init();
  597. reg_value = c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL);
  598. if (value)
  599. reg_value |= AP_READY_BIT;
  600. else
  601. reg_value &= ~AP_READY_BIT; /*set 0 to indicate ap ready */
  602. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL, reg_value);
  603. /* pr_debug("[C2K]%s: set ap ready %d\n", __func__, value); */
  604. }
  605. void set_ap_wake_cp(int value)
  606. {
  607. unsigned int reg_value;
  608. if (infra_ao_base == 0)
  609. c2k_hw_info_init();
  610. reg_value = c2k_read32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL);
  611. if (value)
  612. reg_value |= AP_WAKE_C2K_BIT;
  613. else
  614. reg_value &= ~AP_WAKE_C2K_BIT; /*set 0 to wake up cp */
  615. c2k_write32(infra_ao_base, INFRA_AO_C2K_SPM_CTRL, reg_value);
  616. /* pr_debug("[C2K] ap_wake_cp(%d)\n", value); */
  617. }
  618. void set_ets_sel(int value)
  619. {
  620. unsigned int reg_value;
  621. if (infra_ao_base == 0)
  622. c2k_hw_info_init();
  623. reg_value = c2k_read32(infra_ao_base, INFRA_AO_C2K_CONFIG);
  624. if (value)
  625. reg_value |= ETS_SEL_BIT;
  626. else
  627. reg_value &= ~ETS_SEL_BIT; /*set 0 to wake up cp */
  628. c2k_write32(infra_ao_base, INFRA_AO_C2K_CONFIG, reg_value);
  629. pr_debug("[C2K] set ETS SEL to %d (reg %d)\n", value,
  630. c2k_read32(infra_ao_base, INFRA_AO_C2K_CONFIG));
  631. }
  632. unsigned int get_c2k_wdt_irq_id(void)
  633. {
  634. if (c2k_wdt_irq_id == 0)
  635. c2k_hw_info_init();
  636. return c2k_wdt_irq_id;
  637. }
  638. unsigned int get_c2k_reserve_mem_size(void)
  639. {
  640. return MD3_MEM_RAM_ROM + md3_share_mem_size;
  641. }
  642. char *get_ap_platform(void)
  643. {
  644. return AP_PLATFORM_INFO;
  645. }