dummy_ap.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  1. // Dummy AP
  2. #include <platform/boot_mode.h>
  3. #include <debug.h>
  4. #include <dev/uart.h>
  5. #include <platform/mtk_key.h>
  6. #include <target/cust_key.h>
  7. #include <platform/mt_gpio.h>
  8. #include <sys/types.h>
  9. #include <debug.h>
  10. #include <err.h>
  11. #include <reg.h>
  12. #include <string.h>
  13. #include <platform/mt_typedefs.h>
  14. #include <platform/mt_reg_base.h>
  15. #include <platform/mt_irq.h>
  16. #include <platform/mt_pmic.h>
  17. #include <platform/timer.h>
  18. #include <sys/types.h>
  19. #include <arch/ops.h>
  20. #define THIS_IS_EVB
  21. #define BOTH_MD_ON
  22. //#define CCIF_DVT
  23. //#define DEFAULT_META
  24. //#define ENABLE_MD_RESET_SPM
  25. //#define ENABLE_MD_RESET_RGU
  26. //#define IGNORE_MD_WDT
  27. #ifdef ENABLE_MD_RESET_SPM
  28. #include <platform/spm.h>
  29. #endif
  30. //#define TEMP_COTSX // request by Sw Huang
  31. #define MAX_MD_NUM (2)
  32. #define MAX_IMG_NUM (8)
  33. #define PART_HEADER_MAGIC (0x58881688)
  34. #define BOOT_ARGS_ADDR (0x87F00000)
  35. #define IMG_HEADER_ADDR (0x87F00000+1024)
  36. #define GIC_PRIVATE_SIGNALS (32)
  37. #define MT_MD_WDT1_IRQ_ID (253)
  38. #define MT_MD_WDT2_IRQ_ID (261)
  39. #define MD1_BANK0_MAP0 (0x10000300)
  40. #define MD2_BANK0_MAP0 (0x10000310)
  41. #define C2K_CONFIG (0x10000330)
  42. #define C2K_STATUS (0x10000334)
  43. #define C2K_SPM_CTRL (0x10000338)
  44. #define SLEEP_CLK_CON (0x10006400)
  45. //#define TOPRGU_BASE (0x10212000)
  46. #define TOP_RGU_WDT_MODE (TOPRGU_BASE+0x0)
  47. #define TOP_RGU_WDT_SWRST (TOPRGU_BASE+0x14)
  48. #define TOP_RGU_WDT_SWSYSRST (TOPRGU_BASE+0x18)
  49. #define TOP_RGU_WDT_NONRST_REG (TOPRGU_BASE+0x20)
  50. #define C2K_CHIP_ID (0x3a00b01c)
  51. typedef enum{
  52. DUMMY_AP_IMG = 0,
  53. MD1_IMG,
  54. MD1_RAM_DISK,
  55. MD2_IMG,
  56. MD2_RAM_DISK,
  57. MD_DSP
  58. }img_idx_t;
  59. typedef struct _map
  60. {
  61. char name[32];
  62. img_idx_t idx;
  63. }map_t;
  64. #if 0
  65. typedef union
  66. {
  67. struct
  68. {
  69. unsigned int magic; /* partition magic */
  70. unsigned int dsize; /* partition data size */
  71. char name[32]; /* partition name */
  72. unsigned int maddr; /* partition memory address */
  73. } info;
  74. unsigned char data[512];
  75. } part_hdr_t;
  76. // Notice for MT6582
  77. // Update LK BOOT_ARGUMENT structure
  78. typedef struct {
  79. unsigned int magic_number;
  80. BOOTMODE boot_mode;
  81. unsigned int e_flag;
  82. unsigned int log_port;
  83. unsigned int log_baudrate;
  84. unsigned char log_enable;
  85. unsigned char part_num;
  86. unsigned char reserved[2];
  87. unsigned int dram_rank_num;
  88. unsigned int dram_rank_size[4];
  89. unsigned int boot_reason;
  90. unsigned int meta_com_type;
  91. unsigned int meta_com_id;
  92. unsigned int boot_time;
  93. da_info_t da_info;
  94. SEC_LIMIT sec_limit;
  95. part_hdr_t *part_info;
  96. } BOOT_ARGUMENT;
  97. #endif
  98. extern BOOT_ARGUMENT *g_boot_arg;
  99. //static BOOT_ARGUMENT *boot_args=BOOT_ARGS_ADDR;
  100. //static unsigned int *img_header_array = (unsigned int*)IMG_HEADER_ADDR;
  101. static unsigned int img_load_flag = 0;
  102. static part_hdr_t *img_info_start = NULL;
  103. static unsigned int img_addr_tbl[MAX_IMG_NUM];
  104. static unsigned int img_size_tbl[MAX_IMG_NUM];
  105. static map_t map_tbl[] =
  106. {
  107. {"DUMMY_AP", DUMMY_AP_IMG},
  108. {"MD_IMG", MD1_IMG},
  109. {"MD_RAM_DISK", MD1_RAM_DISK},
  110. {"MD_DSP", MD_DSP},
  111. {"MD2_IMG", MD2_IMG},
  112. {"MD2_RAM_DISK", MD2_RAM_DISK},
  113. };
  114. extern int mt_set_gpio_mode_chip(unsigned int pin, unsigned int mode);
  115. void pmic_init_sequence(void);
  116. void md_uart_config(int md_id);
  117. int parse_img_header(unsigned int *start_addr, unsigned int img_num)
  118. {
  119. unsigned int i, j;
  120. int idx;
  121. if(start_addr == NULL) {
  122. printf("parse_img_header get invalid parameters!\n");
  123. return -1;
  124. }
  125. img_info_start = (part_hdr_t*)start_addr;
  126. for(i=0; i<img_num; i++) {
  127. if(img_info_start[i].info.magic != PART_HEADER_MAGIC)
  128. continue;
  129. for(j=0; j<(sizeof(map_tbl)/sizeof(map_t)); j++) {
  130. if(strcmp(img_info_start[i].info.name, map_tbl[j].name) == 0) {
  131. idx = map_tbl[j].idx;
  132. img_addr_tbl[idx] = img_info_start[i].info.maddr;
  133. img_size_tbl[idx] = img_info_start[i].info.dsize;
  134. img_load_flag |= (1<<idx);
  135. printf("[%s] idx:%d, addr:0x%x, size:0x%x\n", map_tbl[j].name, idx, img_addr_tbl[idx], img_size_tbl[idx]);
  136. }
  137. }
  138. }
  139. return 0;
  140. }
  141. static int meta_detection(void)
  142. {
  143. int boot_mode = 0;
  144. if(g_boot_arg->boot_mode != NORMAL_BOOT)
  145. boot_mode = 1;
  146. printf("Meta mode: %d, boot_mode: %d\n", boot_mode, g_boot_arg->boot_mode);
  147. return boot_mode;
  148. }
  149. static void md_gpio_get(GPIO_PIN pin, char *tag)
  150. {
  151. printf("GPIO(%X)(%s): mode=%d,dir=%d,in=%d,out=%d,pull_en=%d,pull_sel=%d,smt=%d\n",
  152. pin, tag,
  153. mt_get_gpio_mode(pin),
  154. mt_get_gpio_dir(pin),
  155. mt_get_gpio_in(pin),
  156. mt_get_gpio_out(pin),
  157. mt_get_gpio_pull_enable(pin),
  158. mt_get_gpio_pull_select(pin),
  159. mt_get_gpio_smt(pin));
  160. }
  161. static void md_gpio_set(GPIO_PIN pin, GPIO_MODE mode, GPIO_DIR dir, GPIO_OUT out, GPIO_PULL_EN pull_en, GPIO_PULL pull, GPIO_SMT smt)
  162. {
  163. mt_set_gpio_mode(pin, mode);
  164. if(dir != GPIO_DIR_UNSUPPORTED)
  165. mt_set_gpio_dir(pin, dir);
  166. if(dir == GPIO_DIR_OUT) {
  167. mt_set_gpio_out(pin, out);
  168. }
  169. if(dir == GPIO_DIR_IN) {
  170. mt_set_gpio_smt(pin, smt);
  171. }
  172. if(pull_en != GPIO_PULL_EN_UNSUPPORTED) {
  173. mt_set_gpio_pull_enable(pin, pull_en);
  174. mt_set_gpio_pull_select(pin, pull);
  175. }
  176. md_gpio_get(pin, "-");
  177. }
  178. static void md_gpio_config(unsigned int boot_md_id)
  179. {
  180. // init sim1
  181. mt_set_gpio_dir(GPIO_SIM1_SCLK, GPIO_DIR_OUT);
  182. mt_set_gpio_dir(GPIO_SIM1_SRST, GPIO_DIR_OUT);
  183. mt_set_gpio_pull_enable(GPIO_SIM1_SIO, GPIO_PULL_ENABLE);
  184. mt_set_gpio_pull_select(GPIO_SIM1_SIO, GPIO_PULL_UP);
  185. mt_set_gpio_dir(GPIO_SIM1_SIO, GPIO_DIR_IN);
  186. mt_set_gpio_pull_enable(GPIO_SIM1_HOT_PLUG, GPIO_PULL_ENABLE);
  187. mt_set_gpio_pull_select(GPIO_SIM1_HOT_PLUG, GPIO_PULL_UP);
  188. mt_set_gpio_dir(GPIO_SIM1_HOT_PLUG, GPIO_DIR_IN);
  189. // init sim2
  190. mt_set_gpio_dir(GPIO_SIM2_SCLK, GPIO_DIR_OUT);
  191. mt_set_gpio_dir(GPIO_SIM2_SRST, GPIO_DIR_OUT);
  192. mt_set_gpio_pull_enable(GPIO_SIM2_SIO, GPIO_PULL_ENABLE);
  193. mt_set_gpio_pull_select(GPIO_SIM2_SIO, GPIO_PULL_UP);
  194. mt_set_gpio_dir(GPIO_SIM2_SIO, GPIO_DIR_IN);
  195. mt_set_gpio_pull_enable(GPIO_SIM2_HOT_PLUG, GPIO_PULL_ENABLE);
  196. mt_set_gpio_pull_select(GPIO_SIM2_HOT_PLUG, GPIO_PULL_UP);
  197. mt_set_gpio_dir(GPIO_SIM2_HOT_PLUG, GPIO_DIR_IN);
  198. switch(boot_md_id) {
  199. case 0:
  200. //SIM1=> MD1 SIM1IF
  201. mt_set_gpio_mode(GPIO_SIM1_SCLK, GPIO_SIM1_SCLK_M_CLK);
  202. mt_set_gpio_mode(GPIO_SIM1_SRST, GPIO_SIM1_SRST_M_MD_SIM1_SRST);
  203. mt_set_gpio_mode(GPIO_SIM1_SIO, GPIO_SIM1_SIO_M_MD_SIM1_SDAT);
  204. mt_set_gpio_mode(GPIO_SIM1_HOT_PLUG, GPIO_SIM1_HOT_PLUG_M_MDEINT);
  205. //SIM2=> MD1 SIM2IF
  206. mt_set_gpio_mode(GPIO_SIM2_SCLK, GPIO_SIM2_SCLK_M_CLK);
  207. mt_set_gpio_mode(GPIO_SIM2_SRST, GPIO_SIM2_SRST_M_MD_SIM2_SRST);
  208. mt_set_gpio_mode(GPIO_SIM2_SIO, GPIO_SIM2_SIO_M_MD_SIM2_SDAT);
  209. mt_set_gpio_mode(GPIO_SIM2_HOT_PLUG, GPIO_SIM2_HOT_PLUG_M_MDEINT);
  210. break;
  211. case 1:
  212. //SIM1=> MD2 UIM0IF
  213. mt_set_gpio_mode(GPIO_SIM1_SCLK, GPIO_SIM1_SCLK_M_UIM0_CLK);
  214. mt_set_gpio_mode(GPIO_SIM1_SRST, GPIO_SIM1_SRST_M_UIM0_RST);
  215. mt_set_gpio_mode(GPIO_SIM1_SIO, GPIO_SIM1_SIO_M_UIM0_IO);
  216. mt_set_gpio_mode(GPIO_SIM1_HOT_PLUG, GPIO_SIM1_HOT_PLUG_M_C2K_UIM0_HOT_PLUG_IN);
  217. //SIM2=> MD2 UIM1IF
  218. mt_set_gpio_mode(GPIO_SIM2_SCLK, GPIO_SIM2_SIO_M_UIM1_IO);
  219. mt_set_gpio_mode(GPIO_SIM2_SRST, GPIO_SIM2_SRST_M_UIM1_RST);
  220. mt_set_gpio_mode(GPIO_SIM2_SIO, GPIO_SIM2_SIO_M_UIM1_IO);
  221. mt_set_gpio_mode(GPIO_SIM2_HOT_PLUG, GPIO_SIM2_HOT_PLUG_M_C2K_UIM1_HOT_PLUG_IN);
  222. break;
  223. case 2:
  224. //SIM1=> MD1 SIM1IF
  225. mt_set_gpio_mode(GPIO_SIM1_SCLK, GPIO_SIM1_SCLK_M_CLK);
  226. mt_set_gpio_mode(GPIO_SIM1_SRST, GPIO_SIM1_SRST_M_MD_SIM1_SRST);
  227. mt_set_gpio_mode(GPIO_SIM1_SIO, GPIO_SIM1_SIO_M_MD_SIM1_SDAT);
  228. mt_set_gpio_mode(GPIO_SIM1_HOT_PLUG, GPIO_SIM1_HOT_PLUG_M_MDEINT);
  229. //SIM2=> MD2 UIM0IF
  230. mt_set_gpio_mode(GPIO_SIM2_SCLK, GPIO_SIM2_SCLK_M_UIM0_CLK);
  231. mt_set_gpio_mode(GPIO_SIM2_SRST, GPIO_SIM2_SRST_M_UIM0_RST);
  232. mt_set_gpio_mode(GPIO_SIM2_SIO, GPIO_SIM2_SIO_M_UIM0_IO);
  233. mt_set_gpio_mode(GPIO_SIM2_HOT_PLUG, GPIO_SIM2_HOT_PLUG_M_C2K_UIM1_HOT_PLUG_IN);
  234. break;
  235. default:
  236. break;
  237. }
  238. md_gpio_get(GPIO_SIM1_SCLK, "sclk");
  239. md_gpio_get(GPIO_SIM1_SRST, "srst");
  240. md_gpio_get(GPIO_SIM1_SIO, "sio");
  241. md_gpio_get(GPIO_SIM1_HOT_PLUG, "hp");
  242. md_gpio_get(GPIO_SIM2_SCLK, "sclk2");
  243. md_gpio_get(GPIO_SIM2_SRST, "srst2");
  244. md_gpio_get(GPIO_SIM2_SIO, "sio2");
  245. md_gpio_get(GPIO_SIM2_HOT_PLUG, "hp2");
  246. #ifndef MACH_TYPE_MT6735M // only for D-1&3
  247. if(boot_md_id == 1) {
  248. // BPI
  249. #ifndef BOTH_MD_ON
  250. md_gpio_set(GPIO87, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  251. md_gpio_set(GPIO88, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  252. md_gpio_set(GPIO89, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  253. md_gpio_set(GPIO90, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  254. md_gpio_set(GPIO91, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  255. md_gpio_set(GPIO92, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  256. md_gpio_set(GPIO93, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  257. md_gpio_set(GPIO94, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  258. md_gpio_set(GPIO95, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  259. md_gpio_set(GPIO96, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  260. #endif
  261. // ARM GPIO/GPINT
  262. md_gpio_set(GPIO3, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  263. md_gpio_set(GPIO2, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  264. md_gpio_set(GPIO1, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  265. md_gpio_set(GPIO0, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  266. // DSPM GPIO
  267. md_gpio_set(GPIO4, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  268. // ARM legacy JATG
  269. md_gpio_set(GPIO82, GPIO_MODE_05, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_DOWN, GPIO_SMT_ENABLE);
  270. md_gpio_set(GPIO81, GPIO_MODE_05, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_ENABLE);
  271. md_gpio_set(GPIO83, GPIO_MODE_05, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  272. md_gpio_set(GPIO85, GPIO_MODE_05, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  273. md_gpio_set(GPIO84, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  274. md_gpio_set(GPIO86, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  275. // DSP JTAG
  276. #ifdef THIS_IS_EVB
  277. md_gpio_set(GPIO199, GPIO_MODE_07, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_ENABLE);
  278. md_gpio_set(GPIO198, GPIO_MODE_07, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  279. md_gpio_set(GPIO200, GPIO_MODE_07, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  280. md_gpio_set(GPIO201, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  281. md_gpio_set(GPIO202, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  282. #else
  283. md_gpio_set(GPIO71, GPIO_MODE_06, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_ENABLE);
  284. md_gpio_set(GPIO70, GPIO_MODE_06, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  285. md_gpio_set(GPIO72, GPIO_MODE_06, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  286. md_gpio_set(GPIO73, GPIO_MODE_06, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  287. md_gpio_set(GPIO46, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  288. #endif
  289. // C2K UART0
  290. #ifdef THIS_IS_EVB
  291. // covered in uart config
  292. //md_gpio_set(GPIO75, GPIO_MODE_05, GPIO_DIR_OUT, GPIO_OUT_ONE, GPIO_PULL_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  293. //md_gpio_set(GPIO74, GPIO_MODE_05, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  294. #else
  295. md_uart_config(-1);
  296. md_gpio_set(GPIO199, GPIO_MODE_03, GPIO_DIR_OUT, GPIO_OUT_ONE, GPIO_PULL_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  297. md_gpio_set(GPIO198, GPIO_MODE_03, GPIO_DIR_IN, GPIO_OUT_UNSUPPORTED, GPIO_PULL_ENABLE, GPIO_PULL_UP, GPIO_SMT_DISABLE);
  298. #endif
  299. // C2K DropZone assert
  300. md_gpio_set(GPIO63, GPIO_MODE_00, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  301. // debug port
  302. #ifdef THIS_IS_EVB
  303. md_gpio_set(GPIO13, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  304. md_gpio_set(GPIO14, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  305. md_gpio_set(GPIO15, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  306. md_gpio_set(GPIO16, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  307. md_gpio_set(GPIO17, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  308. md_gpio_set(GPIO18, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  309. md_gpio_set(GPIO19, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  310. md_gpio_set(GPIO20, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  311. md_gpio_set(GPIO21, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  312. md_gpio_set(GPIO42, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  313. md_gpio_set(GPIO43, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  314. md_gpio_set(GPIO44, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  315. md_gpio_set(GPIO45, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  316. md_gpio_set(GPIO57, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  317. md_gpio_set(GPIO58, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  318. md_gpio_set(GPIO59, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  319. md_gpio_set(GPIO60, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  320. md_gpio_set(GPIO61, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  321. md_gpio_set(GPIO62, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  322. md_gpio_set(GPIO63, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  323. md_gpio_set(GPIO64, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  324. md_gpio_set(GPIO65, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  325. md_gpio_set(GPIO66, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  326. md_gpio_set(GPIO67, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  327. md_gpio_set(GPIO68, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  328. md_gpio_set(GPIO78, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  329. md_gpio_set(GPIO79, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  330. md_gpio_set(GPIO80, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  331. md_gpio_set(GPIO120, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  332. md_gpio_set(GPIO10, GPIO_MODE_07, GPIO_DIR_OUT, GPIO_OUT_ZERO, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  333. #endif
  334. }
  335. #endif
  336. }
  337. static void md_emi_remapping(unsigned int boot_md_id)
  338. {
  339. unsigned int md_img_start_addr = 0;
  340. unsigned int md_emi_remapping_addr = 0;
  341. switch(boot_md_id) {
  342. case 0: // MD1
  343. md_img_start_addr = img_addr_tbl[MD1_IMG] - 0x40000000;
  344. md_emi_remapping_addr = MD1_BANK0_MAP0;
  345. break;
  346. case 1: // MD2
  347. md_img_start_addr = img_addr_tbl[MD2_IMG] - 0x40000000;
  348. md_emi_remapping_addr = MD2_BANK0_MAP0;
  349. break;
  350. default:
  351. break;
  352. }
  353. printf("---> Map 0x00000000 to 0x%x for MD%d\n", md_img_start_addr+0x40000000, boot_md_id+1);
  354. // For MDx_BANK0_MAP0
  355. *((volatile unsigned int*)md_emi_remapping_addr) = (((md_img_start_addr >> 24) | 1) & 0xFF) \
  356. + ((((md_img_start_addr + 0x02000000) >> 16) | 1<<8) & 0xFF00) \
  357. + ((((md_img_start_addr + 0x04000000) >> 8) | 1<<16) & 0xFF0000) \
  358. + ((((md_img_start_addr + 0x06000000) >> 0) | 1<<24) & 0xFF000000);
  359. // For MDx_BANK0_MAP1
  360. *((volatile unsigned int*)(md_emi_remapping_addr + 0x4)) = ((((md_img_start_addr + 0x08000000) >> 24) | 1) & 0xFF) \
  361. + ((((md_img_start_addr + 0x0A000000) >> 16) | 1<<8) & 0xFF00) \
  362. + ((((md_img_start_addr + 0x0C000000) >> 8) | 1<<16) & 0xFF0000) \
  363. + ((((md_img_start_addr + 0x0E000000) >> 0) | 1<<24) & 0xFF000000);
  364. printf("---> MD_BANK0_MAP0=0x%x, MD_BANK0_MAP1=0x%x\n",
  365. *((volatile unsigned int*)md_emi_remapping_addr),
  366. *((volatile unsigned int*)(md_emi_remapping_addr + 0x4)));
  367. }
  368. static void md_power_up_mtcmos(unsigned int boot_md_id)
  369. {
  370. volatile unsigned int loop = 10000;
  371. loop =10000;
  372. while(loop-->0);
  373. switch(boot_md_id) {
  374. case 0://MD 1
  375. #ifdef ENABLE_MD_RESET_SPM
  376. spm_mtcmos_ctrl_mdsys1(STA_POWER_ON);
  377. #else
  378. // default on
  379. #endif
  380. break;
  381. case 1:// MD2
  382. #ifdef ENABLE_MD_RESET_SPM
  383. spm_mtcmos_ctrl_mdsys2(STA_POWER_ON);
  384. #else
  385. // YP Lin will power it on in preloader
  386. #endif
  387. break;
  388. default:
  389. break;
  390. }
  391. }
  392. static void md_common_setting(int boot_md_id)
  393. {
  394. // Put special setting here if needed, ex. Disable WDT
  395. volatile unsigned int *md_wdt;
  396. switch(boot_md_id) {
  397. case 0:
  398. md_wdt = (volatile unsigned int*)0x20050000;
  399. printf("Disable MD1 WDT\n");
  400. *md_wdt = 0x220E;
  401. mdelay(5);
  402. break;
  403. case 1:
  404. // C2K MD's WDT is dsiabled by default
  405. break;
  406. default:
  407. break;
  408. }
  409. }
  410. static void md_boot_up(unsigned int boot_md_id, unsigned int is_meta_mode)
  411. {
  412. unsigned int reg_value;
  413. switch(boot_md_id) {
  414. case 0:// For MD1
  415. #ifdef TEMP_COTSX
  416. pmic_config_interface(0x0F08, 0x8040, 0xFFFF, 0x0);
  417. pmic_config_interface(0x0F0E, 0x8040, 0xFFFF, 0x0);
  418. pmic_config_interface(0x0F12, 0x0004, 0xFFFF, 0x0);
  419. #endif
  420. // step 1: enable VSRAM
  421. md_gpio_set(GPIO_LTE_VSRAM_EXT_POWER_EN_PIN, GPIO_MODE_00, GPIO_DIR_OUT, GPIO_OUT_ONE, GPIO_PULL_EN_UNSUPPORTED, GPIO_PULL_UNSUPPORTED, GPIO_SMT_UNSUPPORTED);
  422. // step 2: md1_srcclkena and md2_srcclkena in C2K_SPM_CTRL
  423. *((volatile unsigned int*)C2K_SPM_CTRL) &= ~(0xF<<2);
  424. *((volatile unsigned int*)C2K_SPM_CTRL) |= (0x9<<2);
  425. printf("C2K_SPM_CTRL = 0x%x\n", *((volatile unsigned int*)C2K_SPM_CTRL));
  426. // MD1 will init and configure PMIC by itself
  427. // step 3: set META Register
  428. if(is_meta_mode) {
  429. *((volatile unsigned int*)0x20000010) |= 0x1; // Bit0, Meta mode flag, this need sync with MD init owner
  430. }
  431. // step 4: set boot slave
  432. *((volatile unsigned int*)0x2019379C) = 0x3567C766; // Key Register
  433. *((volatile unsigned int*)0x20190000) = 0x0; // Vector Register
  434. *((volatile unsigned int*)0x20195488) = 0xA3B66175; // Slave En Register
  435. break;
  436. case 1:// For MD2
  437. // C2K MD does not need META mode
  438. // step 1: set C2K boot mode
  439. reg_value = *((volatile unsigned int*)C2K_CONFIG);
  440. *((volatile unsigned int*)C2K_CONFIG) = (reg_value&(~(0x7<<8)))|(0x5<<8);
  441. printf("C2K_CONFIG = 0x%x\n", *((volatile unsigned int*)C2K_CONFIG));
  442. // step 2: config srcclkena selection mask
  443. *((volatile unsigned int*)C2K_SPM_CTRL) &= ~(0xF<<2);
  444. *((volatile unsigned int*)C2K_SPM_CTRL) |= (0x9<<2);
  445. printf("C2K_SPM_CTRL = 0x%x\n", *((volatile unsigned int*)C2K_SPM_CTRL));
  446. *((volatile unsigned int*)SLEEP_CLK_CON) |= 0xc;
  447. *((volatile unsigned int*)SLEEP_CLK_CON) &= ~(0x1<<14);
  448. *((volatile unsigned int*)SLEEP_CLK_CON) |= (0x1<<12);
  449. *((volatile unsigned int*)SLEEP_CLK_CON) |= (0x1<<27);
  450. printf("SLEEP_CLK_CON = 0x%x\n", *((volatile unsigned int*)SLEEP_CLK_CON));
  451. // step 3: PMIC VTCXO_1 VRF18_1 VIO18 enable
  452. pmic_init_sequence();
  453. pmic_config_interface(0x0A02, 0xA12E, 0xFFFF, 0x0);
  454. pmic_config_interface(0x0A16, 0x8102, 0xFFFF, 0x0);
  455. pmic_config_interface(0x0A36, 0x8102, 0xFFFF, 0x0);
  456. // step 4: reset C2K
  457. reg_value = *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST);
  458. *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST) = (reg_value|0x88000000)&(~(0x1<<15));
  459. printf("TOP_RGU_WDT_SWSYSRST = 0x%x, TOPRGU_BASE(0x%x)\n", *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST), TOPRGU_BASE);
  460. // step 5: wake up C2K
  461. *((volatile unsigned int*)C2K_SPM_CTRL) |= 0x1;
  462. while(!((*((volatile unsigned int*)C2K_STATUS)>>1)&0x1)){
  463. printf("C2K_STATUS = 0x%x\n", *((volatile unsigned int*)C2K_STATUS));
  464. }
  465. *((volatile unsigned int*)C2K_SPM_CTRL) &= ~0x1;
  466. printf("C2K_SPM_CTRL = 0x%x, C2K_STATUS = 0x%x\n", *((volatile unsigned int*)C2K_SPM_CTRL), *((volatile unsigned int*)C2K_STATUS));
  467. while(*((volatile unsigned int*)C2K_CHIP_ID) != 0x020AC000) {
  468. printf("C2K_CHIP_ID = 0x%x\n", *((volatile unsigned int*)C2K_CHIP_ID));
  469. }
  470. printf("C2K_CHIP_ID = 0x%x!!\n", *((volatile unsigned int*)C2K_CHIP_ID));
  471. break;
  472. default:
  473. break;
  474. }
  475. }
  476. int md_jtag_config(int boot_md_id)
  477. {
  478. return 0;
  479. }
  480. int get_input(void)
  481. {
  482. return uart_getc();
  483. }
  484. void apply_env_setting(int case_id)
  485. {
  486. printf("Apply case:%d setting for dummy AP!\n", case_id);
  487. }
  488. void md_uart_config(int type_id)
  489. {
  490. switch(type_id) {
  491. case -1: // for AP only
  492. case 0: // for AP & MD1
  493. case 1: // for AP & MD2
  494. case 2: // for both MD1 and MD2
  495. printf("md_uart_config:%d, UART1->MD3, UART2->MD1, UART3->AP, UART4->disabled\n", type_id);
  496. mt_set_gpio_mode(GPIO_UART_URXD0_PIN, GPIO_UART_URXD0_PIN_M_C2K_UART0_RXD);
  497. mt_set_gpio_mode(GPIO_UART_UTXD0_PIN, GPIO_UART_UTXD0_PIN_M_C2K_UART0_TXD);
  498. mt_set_gpio_mode(GPIO_UART_URXD1_PIN, GPIO_UART_URXD1_PIN_M_MD_URXD);
  499. mt_set_gpio_mode(GPIO_UART_UTXD1_PIN, GPIO_UART_UTXD1_PIN_M_MD_UTXD);
  500. mt_set_gpio_mode(GPIO_UART_URXD2_PIN, GPIO_UART_URXD2_PIN_M_URXD);
  501. mt_set_gpio_mode(GPIO_UART_UTXD2_PIN, GPIO_UART_UTXD2_PIN_M_UTXD);
  502. mt_set_gpio_mode(GPIO_UART_URXD3_PIN, GPIO_UART_URXD3_PIN_M_GPIO);
  503. mt_set_gpio_mode(GPIO_UART_UTXD3_PIN, GPIO_UART_UTXD3_PIN_M_GPIO);
  504. break;
  505. default:
  506. break;
  507. }
  508. }
  509. static void let_md_go(int md_id)
  510. {
  511. unsigned int is_meta_mode = 0;
  512. // 1, Configure EMI remapping setting
  513. printf("Step 1: Configure EMI remapping...\n");
  514. md_emi_remapping(md_id);
  515. // 2, Power up MD MTCMOS
  516. //printf("Step 3: Power up MD!\n");
  517. md_power_up_mtcmos(md_id);
  518. // 3, Configure DAP for ICE to connect to MD
  519. printf("Step 2: Configure DAP for ICE to connect to MD!\n");
  520. md_jtag_config(md_id);
  521. // 4, Check boot Mode
  522. #ifdef DEFAULT_META
  523. is_meta_mode = 1;
  524. #else
  525. is_meta_mode = meta_detection();
  526. #endif
  527. printf("Step 3: Notify MD enter %s mode!\n", is_meta_mode ? "META" : "NORMAL");
  528. // 5, MD register setting
  529. printf("Step 4: MD Common setting!\n");
  530. md_common_setting(md_id);
  531. // 6, Boot up MD
  532. printf("Step 5: MD%d boot up with meta(%d)!\n", md_id+1, is_meta_mode);
  533. md_boot_up(md_id, is_meta_mode);
  534. printf("\nmd%d boot up done!\n", md_id + 1);
  535. }
  536. void md_wdt_init(void)
  537. {
  538. if(img_load_flag &(1<<MD1_IMG)) {
  539. mt_irq_set_sens(MT_MD_WDT1_IRQ_ID, MT65xx_EDGE_SENSITIVE);
  540. mt_irq_set_polarity(MT_MD_WDT1_IRQ_ID, MT65xx_POLARITY_LOW);
  541. mt_irq_unmask(MT_MD_WDT1_IRQ_ID);
  542. }
  543. if(img_load_flag &(1<<MD2_IMG)) {
  544. mt_irq_set_sens(MT_MD_WDT2_IRQ_ID, MT65xx_EDGE_SENSITIVE);
  545. mt_irq_set_polarity(MT_MD_WDT2_IRQ_ID, MT65xx_POLARITY_LOW);
  546. mt_irq_unmask(MT_MD_WDT2_IRQ_ID);
  547. }
  548. }
  549. #ifdef CCIF_DVT
  550. /******************************************************************************/
  551. #define ccif_debug(fmt, args...) printf("ts_ccif: "fmt, ##args)
  552. #define ccif_error(fmt, args...) printf("[CCIF][Error] "fmt, ##args)
  553. #define __IO_WRITE32(a, v) *((volatile unsigned int*)a)=(v)
  554. #define __IO_READ32(a) (*((volatile unsigned int*)a))
  555. #define CCIF_IRQ_ID 171
  556. #define CCIF_REG_BASE 0x10218000
  557. #define CCIF_MAX_PHY 16
  558. #define CCIF_DATA_REG_LENGTH (512)
  559. #define CCIF_CON (CCIF_REG_BASE + 0x0000)
  560. #define CCIF_BUSY (CCIF_REG_BASE + 0x0004)
  561. #define CCIF_START (CCIF_REG_BASE + 0x0008)
  562. #define CCIF_TCHNUM (CCIF_REG_BASE + 0x000c)
  563. #define CCIF_RCHNUM (CCIF_REG_BASE + 0x0010)
  564. #define CCIF_ACK (CCIF_REG_BASE + 0x0014)
  565. #define CCIF_DATA (CCIF_REG_BASE + 0x0100)
  566. #define CCIF_TXCHDATA_OFFSET (0)
  567. #define CCIF_RXCHDATA_OFFSET (CCIF_DATA_REG_LENGTH/2)
  568. #define CCIF_TXCHDATA (CCIF_DATA+CCIF_TXCHDATA_OFFSET)
  569. #define CCIF_RXCHDATA (CCIF_DATA + CCIF_RXCHDATA_OFFSET)
  570. typedef struct
  571. {
  572. unsigned int data[2];
  573. unsigned int channel;
  574. unsigned int reserved;
  575. } CCCI_BUFF_T;
  576. typedef struct
  577. {
  578. unsigned int ap_state;
  579. unsigned int md_state;
  580. unsigned int test_case;
  581. }sync_flag;
  582. enum { AP_NOT_READY=0x9abcdef, AP_READY, AP_SYNC_ID_DONE, AP_WAIT_BEGIN, AP_BEGIN,
  583. AP_REQUST, AP_REQUST_ONGOING, AP_REQUST_DONE
  584. };
  585. enum { MD_NOT_READY=0xfedcba9, MD_READY, MD_SYNC_ID_DONE, MD_WAIT_BEGIN, MD_GEGIN,
  586. MD_WAIT_REQUST, MD_ACK_DONE
  587. };
  588. enum { TC_00=0,
  589. TC_01=1, TC_02, TC_03, TC_04, TC_05, TC_06, TC_07, TC_08, TC_09, TC_10,
  590. TC_11, TC_12, TC_13, TC_14, TC_15, TC_16, TC_17, TC_18, TC_19, TC_20,
  591. TC_21, TC_22, TC_23, TC_24, TC_25, TC_26, TC_27, TC_28, TC_29, TC_30,
  592. };
  593. static CCCI_BUFF_T ccif_msg[CCIF_MAX_PHY];
  594. static volatile unsigned int *test_heap_ptr;
  595. static volatile unsigned int *test_nc_heap_ptr;
  596. static void (*CCIF_isr_process_func)(void);
  597. static void(*CCIF_call_back_func)(unsigned int);
  598. static unsigned int using_user_isr=0;
  599. static unsigned int rx_ch_flag = 1;
  600. static unsigned int rx_ch_index = 0;
  601. static volatile unsigned int *ap_md_share_heap_ptr;
  602. static volatile sync_flag *sync_data_region;
  603. static unsigned int *AP_MD_Result_Share_Region;
  604. static const unsigned int phy_ch_seq_mode_seq[CCIF_MAX_PHY] = { 13, 5, 7, 11, 4,12, 0, 6, 3, 14, 9,2, 15,8,10,1 };
  605. static const unsigned int data_pattern[] = {
  606. 0x500af0f0, 0x501af0f0, 0x502af0f0, 0x503af0f0, 0x504af0f0,0x505af0f0,0x506af0f0,0x507af0f0,
  607. 0x508af0f0, 0x509af0f0, 0x50aaf0f0, 0x50baf0f0, 0x50caf0f0,0x50daf0f0,0x50eaf0f0,0x50faf0f0,
  608. 0x510af0f0, 0x511af0f0, 0x512af0f0, 0x513af0f0, 0x514af0f0,0x515af0f0,0x516af0f0,0x517af0f0,
  609. 0x518af0f0, 0x519af0f0, 0x51aaf0f0, 0x51baf0f0, 0x51caf0f0,0x51daf0f0,0x51eaf0f0,0x51faf0f0,
  610. };
  611. static const unsigned int channel_bits_map[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000};
  612. static volatile unsigned int isr_work_done[30];
  613. static const unsigned int result_unknow = 0;
  614. static const unsigned int result_pass = 1<<16;
  615. static const unsigned int result_fail = 2<<16;
  616. static unsigned int rx_seq_for_isr = 0;
  617. static unsigned int rx_last_time_val = 0;
  618. static unsigned int irq_is_masked = 0;
  619. static const int ccif_phy_arb_mode_seq[CCIF_MAX_PHY] = { 12, 3, 15, 1, 11, 8, 14, 2, 13, 4, 10, 7, 9, 5, 0, 6};
  620. static void CCIF_arb_isr_func(void)
  621. {
  622. // 1. Get channel
  623. unsigned int ch_flag = __IO_READ32(CCIF_RCHNUM);
  624. ccif_debug("CCIF_arb_isr_func() ch:%d\n", ch_flag);
  625. while(ch_flag){
  626. if(ch_flag & rx_ch_flag){
  627. // 2. Call callback function
  628. if(CCIF_call_back_func)
  629. (*CCIF_call_back_func)(rx_ch_index);
  630. // 3. Ack channel
  631. __IO_WRITE32(CCIF_ACK, rx_ch_flag);
  632. // 4. Clear rx channel flag
  633. ch_flag &= (~rx_ch_flag);
  634. }
  635. // 5. Updata index and ch flag
  636. rx_ch_index++;
  637. rx_ch_index &= 0xf;
  638. rx_ch_flag =1<<rx_ch_index;
  639. }
  640. }
  641. static void CCIF_default_seq_cb_func()
  642. {
  643. // 1. Get channel
  644. unsigned int ch = __IO_READ32(CCIF_RCHNUM);
  645. ccif_debug("CCIF_default_seq_cb_func() ch:%d\n", ch);
  646. // 2. Call callback function
  647. if(CCIF_call_back_func)
  648. (*CCIF_call_back_func)(ch);
  649. // 3. Ack channel
  650. __IO_WRITE32(CCIF_ACK, channel_bits_map[ch]);
  651. }
  652. void CCIF_Set_Con(unsigned int setting)
  653. {
  654. __IO_WRITE32(CCIF_CON, setting);
  655. if(using_user_isr)
  656. return;
  657. if(setting&0x1){ // arb mode
  658. CCIF_isr_process_func = CCIF_arb_isr_func;
  659. }else{ // seq mode
  660. CCIF_isr_process_func = CCIF_default_seq_cb_func;
  661. }
  662. }
  663. void CCIF_Register_User_Isr(void(*pfunc)(void))
  664. {
  665. static void (*pfunc_bak)(void);
  666. if(pfunc){
  667. using_user_isr = 1;
  668. pfunc_bak = CCIF_isr_process_func;
  669. CCIF_isr_process_func = pfunc;
  670. }else{
  671. using_user_isr = 0;
  672. CCIF_isr_process_func = pfunc_bak;
  673. }
  674. }
  675. int CCIF_Register(void(*pfunc)(unsigned int))
  676. {
  677. CCIF_call_back_func = pfunc;
  678. return 0;
  679. }
  680. unsigned int CCIF_Get_Busy(void)
  681. {
  682. return __IO_READ32(CCIF_BUSY);
  683. }
  684. unsigned int CCIF_Get_Start(void)
  685. {
  686. return __IO_READ32(CCIF_START);
  687. }
  688. void CCIF_Set_Busy(unsigned int setting)
  689. {
  690. __IO_WRITE32(CCIF_BUSY, setting);
  691. }
  692. void CCIF_Set_TxData(unsigned int ch, char buff[])
  693. {
  694. unsigned int *src_ptr;
  695. unsigned int *des_ptr;
  696. int i;
  697. src_ptr = (unsigned int *)&buff[0];
  698. des_ptr = (unsigned int *)(CCIF_TXCHDATA + (16*ch));
  699. for(i=0; i<4; i++)
  700. des_ptr[i] = src_ptr[i];
  701. }
  702. void CCIF_Set_Tch_Num(unsigned int ch)
  703. {
  704. __IO_WRITE32(CCIF_TCHNUM, ch);
  705. }
  706. int CCIF_Init()
  707. {
  708. // 1. Mask CCIF Irq
  709. CCIF_Mask_Irq(CCIF_IRQ_ID);
  710. // 2. Set to arb mode
  711. CCIF_Set_Con(1);
  712. // 3. Ack all channel
  713. //CCIF_Set_Ack(0xff);
  714. // 4. Register interrupt to system
  715. //IRQ_Register_LISR(CCIF_IRQ_ID, CCIF_Isr, "CCIF"); // FIXME
  716. mt_irq_set_sens(CCIF_IRQ_ID, MT65xx_LEVEL_SENSITIVE);
  717. mt_irq_set_polarity(CCIF_IRQ_ID, MT65xx_POLARITY_LOW);
  718. //IRQClearInt(CCIF_IRQ_ID);
  719. // 5. Un-mask Irq
  720. CCIF_UnMask_Irq(CCIF_IRQ_ID);
  721. }
  722. void CCIF_Set_ShareData(unsigned int offset, unsigned int setting)
  723. {
  724. __IO_WRITE32((CCIF_DATA+(offset&(~0x003))), setting);
  725. }
  726. unsigned int CCIF_Get_ShareData(unsigned int offset)
  727. {
  728. return __IO_READ32( (CCIF_DATA+(offset&(~0x003))) );
  729. }
  730. void CCIF_Get_RxData(unsigned int ch, char buff[])
  731. {
  732. unsigned int *src_ptr;
  733. unsigned int *des_ptr;
  734. int i;
  735. des_ptr = (unsigned int *)&buff[0];
  736. src_ptr = (unsigned int *)(CCIF_RXCHDATA + (16*ch));
  737. for(i=0; i<4; i++)
  738. des_ptr[i] = src_ptr[i];
  739. }
  740. void CCIF_Isr(unsigned int irq)
  741. {
  742. if(irq == CCIF_IRQ_ID) {
  743. printf("CCIF ISR enter!\n");
  744. (*CCIF_isr_process_func)();
  745. mt_irq_ack(CCIF_IRQ_ID);
  746. mt_irq_unmask(CCIF_IRQ_ID);
  747. printf("CCIF ISR exit!\n");
  748. }
  749. }
  750. void CCIF_Mask_Irq()
  751. {
  752. mt_irq_mask(CCIF_IRQ_ID);
  753. irq_is_masked = 1;
  754. }
  755. void CCIF_UnMask_Irq()
  756. {
  757. mt_irq_unmask(CCIF_IRQ_ID);
  758. irq_is_masked = 0;
  759. }
  760. void CCIF_Set_Ack(unsigned int ch)
  761. {
  762. __IO_WRITE32(CCIF_ACK, ch);
  763. }
  764. unsigned int CCIF_Get_Tch_Num()
  765. {
  766. return __IO_READ32(CCIF_TCHNUM);
  767. }
  768. unsigned int CCIF_Get_Rch_Num(void)
  769. {
  770. return __IO_READ32(CCIF_RCHNUM);
  771. }
  772. void AP_MD_Test_Sync_Init(unsigned int addr)
  773. {
  774. ccif_debug("AP_MD_Test_Sync_Init 10 \n");
  775. sync_data_region = (sync_flag *)addr;
  776. sync_data_region->ap_state = AP_NOT_READY;
  777. sync_data_region->md_state = MD_NOT_READY;
  778. sync_data_region->test_case = 0;
  779. ccif_debug("AP_MD_Test_Sync_Init 99 \n");
  780. }
  781. void Set_AP_MD_Sync_Share_Memory(unsigned int ptr)
  782. {
  783. enum {AP_IN_INIT_DONE=0x12345678, AP_WRITE_DATA_DONE};
  784. enum {MD_IN_INIT_DONE=0x87654321, MD_GET_DATA_DONE};
  785. ccif_debug("Check if MD init done 0x%x\n", CCIF_Get_ShareData(CCIF_RXCHDATA_OFFSET));
  786. // 1. Notify MD that AP init done
  787. ccif_debug("Notify MD that AP init done, addr:0x%x, value:0x%x\n", CCIF_DATA,AP_IN_INIT_DONE);
  788. CCIF_Set_ShareData(CCIF_TXCHDATA_OFFSET, AP_IN_INIT_DONE);
  789. // 2. Check MD is init done
  790. ccif_debug("Check if MD init done, addr:0x%x, value:0x%x\n", (CCIF_DATA + (CCIF_RXCHDATA_OFFSET & (~0x003))), MD_IN_INIT_DONE);
  791. while(CCIF_Get_ShareData(CCIF_RXCHDATA_OFFSET)!=MD_IN_INIT_DONE);
  792. ccif_debug("Check if MD init done 0x%x\n", CCIF_Get_ShareData(CCIF_RXCHDATA_OFFSET));
  793. // 3. MD ready, notify share memory start addr
  794. ccif_debug("AP MD share memroy start addr:%x\n", (unsigned int)ptr);
  795. ptr -= img_addr_tbl[MD2_IMG]; // FIXME, hardcode;
  796. CCIF_Set_ShareData(CCIF_TXCHDATA_OFFSET+4, (unsigned int)(ptr));
  797. ccif_debug("Notify MD get share memroy start addr:0x%x\n",(unsigned int) ptr);
  798. CCIF_Set_ShareData(0, AP_WRITE_DATA_DONE);
  799. // 4. Wait MD get data done
  800. ccif_debug("Check if MD get data done\n");
  801. while(CCIF_Get_ShareData(CCIF_RXCHDATA_OFFSET)!=MD_GET_DATA_DONE);
  802. // 5. Set share memory done, clear ccif shareram
  803. ccif_debug("Set_AP_MD_Sync_Share_Memory done\n");
  804. CCIF_Set_ShareData(CCIF_TXCHDATA_OFFSET, 0);
  805. CCIF_Set_ShareData(CCIF_TXCHDATA_OFFSET+4, 0);
  806. CCIF_Set_ShareData(CCIF_RXCHDATA_OFFSET, 0);
  807. }
  808. void CCIF_Test_Env_Init(unsigned int ptr)
  809. {
  810. ccif_debug("CCIF_Test_Env_Init 1\n");
  811. AP_MD_Test_Sync_Init(ptr);
  812. ccif_debug("CCIF_Test_Env_Init 2\n");
  813. Set_AP_MD_Sync_Share_Memory(ptr);
  814. ccif_debug("CCIF_Test_Env_Init 3\n");
  815. //INFRA_disable_clock(MT65XX_PDN_INFRA_CCIF0);
  816. ccif_debug("CCIF_Test_Env_Init 4\n");
  817. AP_MD_Result_Share_Region = (unsigned int*)(ptr+sizeof(sync_flag)*2);
  818. }
  819. int ts_init_handler()
  820. {
  821. int ret_val = 0;
  822. unsigned int *ptr, *nc_ptr;
  823. memset(ccif_msg,0,sizeof(ccif_msg));
  824. ccif_debug("TC init\n");
  825. test_heap_ptr=(unsigned int *)malloc(1024*2);
  826. test_nc_heap_ptr=(unsigned int *)malloc(1024*2);
  827. ccif_debug("\tTC init step 3\n");
  828. CCIF_Init();
  829. ccif_debug("\tTC init step 4\n");
  830. ap_md_share_heap_ptr = (void *)(img_addr_tbl[MD2_IMG]+0x100000); // FIXME, hardcode
  831. ccif_debug("\tTC init step 5\n");
  832. //Let_MD_to_Run();
  833. ccif_debug("\tTC init step 6\n");
  834. CCIF_Test_Env_Init((unsigned int)ap_md_share_heap_ptr);
  835. ccif_debug("TC init done.\n");
  836. return ret_val;
  837. }
  838. void AP_MD_test_case_sync_AP_Side(unsigned int tc)
  839. {
  840. int i =0;
  841. ccif_debug("Enter set_ccif_test_case_sync \n");
  842. // 1. Notify MD that AP ready
  843. ccif_debug("Notify MD that AP ready, addr:0x%x, val:0x%x, disr:0x%x\n",(unsigned int)(&(sync_data_region->ap_state)), sync_data_region->ap_state, AP_READY);
  844. sync_data_region->ap_state = AP_READY;
  845. //arch_sync_cache_range(&sync_data_region, sizeof(sync_data_region));
  846. // 2. Check MD is ready
  847. ccif_debug("Check if MD is ready, addr:0x%x, val:0x%x, disr:0x%x\n", (unsigned int)(&(sync_data_region->md_state)),sync_data_region->md_state, AP_READY);
  848. while(sync_data_region->md_state!=MD_READY) {
  849. ccif_debug("Check AP addr:0x%x, State:%x\n", &(sync_data_region->ap_state),
  850. sync_data_region->ap_state);
  851. ccif_debug("Check MD addr:0x%x, State:%x, expeted:0x%x\n", &(sync_data_region->md_state),
  852. sync_data_region->md_state, MD_READY);
  853. };
  854. // 3. MD ready, notify MD test case ID
  855. sync_data_region->test_case = tc;
  856. ccif_debug("Notify MD test id :%x\n", tc);
  857. sync_data_region->ap_state = AP_SYNC_ID_DONE;
  858. // 4. Wait MD get tc id done
  859. ccif_debug("Check if MD ready to test\n");
  860. while(sync_data_region->md_state!=MD_SYNC_ID_DONE){
  861. ccif_debug("Check AP 2 addr:0x%x, State:%x\n", &(sync_data_region->ap_state),
  862. sync_data_region->ap_state);
  863. ccif_debug("Wait MD get TC id Done: addr:0x%x, State:%x, expeted:0x%x\n", &(sync_data_region->md_state),
  864. sync_data_region->md_state, MD_SYNC_ID_DONE);
  865. };
  866. // 5. Finish sysn
  867. ccif_debug("AP_MD_test_case_sync_AP_Side done\n");
  868. }
  869. void AP_MD_Ready_to_Test_Sync_AP_Side()
  870. {
  871. ccif_debug("Enter AP_MD_Ready_to_Test_Sync_AP_Side \n");
  872. // 1. Notify MD that AP ready
  873. ccif_debug("Notify MD that AP ready\n");
  874. sync_data_region->ap_state = AP_WAIT_BEGIN;
  875. // 2. Check MD is ready
  876. ccif_debug("Check if MD is ready\n");
  877. while(sync_data_region->md_state!=MD_WAIT_BEGIN);
  878. sync_data_region->ap_state=AP_NOT_READY;
  879. sync_data_region->md_state=MD_NOT_READY;
  880. // 3. MD also ready
  881. ccif_debug("Begin to test\n");
  882. }
  883. int AP_Get_MD_Test_Result(unsigned int buf[], unsigned int length)
  884. {
  885. int act_get = 0;
  886. unsigned int j;
  887. ccif_debug("Enter AP_Get_MD_Test_Result \n");
  888. // 1. Notify MD that AP request test result
  889. ccif_debug("Notify MD that AP request test result\n");
  890. sync_data_region->ap_state = AP_REQUST;
  891. // 2. Check MD is wait request
  892. ccif_debug("Check if MD is wait send result\n");
  893. while(sync_data_region->md_state!=MD_WAIT_REQUST);
  894. sync_data_region->ap_state = AP_REQUST_ONGOING;
  895. // 3. Wait MD write result done
  896. ccif_debug("Wait MD write result done\n");
  897. while(sync_data_region->md_state!=MD_ACK_DONE);
  898. // 4. Get Test result
  899. for(j=0; (j<AP_MD_Result_Share_Region[0])&&(j<length); j++)
  900. buf[j] = AP_MD_Result_Share_Region[j+1];
  901. // 5. Notify MD AP get result done
  902. ccif_debug("Notify MD AP get result done buf[0](%d)\n", buf[0]);
  903. sync_data_region->ap_state = AP_REQUST_DONE;
  904. return j;
  905. }
  906. void Set_Isr_Work_Done(unsigned int tc)
  907. {
  908. printf("CCIF ISR done for TC%d\n", tc);
  909. isr_work_done[tc] = 1;
  910. }
  911. void Reset_Isr_Work_State(unsigned int tc)
  912. {
  913. isr_work_done[tc] = 0;
  914. }
  915. int Is_Isr_Work_Done(unsigned int tc)
  916. {
  917. return isr_work_done[tc];
  918. }
  919. static void ccif_seq_isr_cb_for_tc02(unsigned int ch)
  920. {
  921. unsigned int data[4];
  922. unsigned int seq = test_heap_ptr[0];
  923. unsigned int mis_match = 0;
  924. // 1. Read Data Send from MD
  925. CCIF_Get_RxData(ch, (unsigned char*)data);
  926. // 2. Check sequence
  927. if(ch != phy_ch_seq_mode_seq[seq])
  928. {
  929. mis_match = (1<<0);
  930. ccif_error("AP <== MD seq mode channel seq mis-match(%d!=%d), seq:%d\n",ch,phy_ch_seq_mode_seq[seq], seq);
  931. }
  932. // 3. Check rx data
  933. if( (data[0]==data[1])&&(data[1]==data[2])&&(data[2]==data[3])&&
  934. (data[3]==(data_pattern[TC_02]+ch))&&(result_unknow==test_heap_ptr[ch+1]) )
  935. test_heap_ptr[ch+1] = result_pass;
  936. else
  937. {
  938. test_heap_ptr[ch+1] = result_fail;
  939. ccif_error("%x != %x \r\n",data[0],data_pattern[TC_02]+ch);
  940. }
  941. // 4 Update mis-match info
  942. if(mis_match){
  943. test_heap_ptr[ch+1] += 1;
  944. mis_match = 0;
  945. }
  946. // 5. Check whether test done
  947. seq++;
  948. test_heap_ptr[0] = seq;
  949. if(test_heap_ptr[0] == CCIF_MAX_PHY)
  950. Set_Isr_Work_Done(TC_02);
  951. }
  952. static void ccif_arb_isr_for_tc04()
  953. {
  954. unsigned int ch;
  955. // 1. Get Channel
  956. ch = CCIF_Get_Rch_Num();
  957. if (ch < 1) {
  958. ccif_debug("ch = 0, exit abr isr\r\n");
  959. return ;
  960. }
  961. // 2. Check Rx seq
  962. if(ch!=rx_last_time_val){
  963. // Has new data
  964. // if( (ch^rx_last_time_val)==(unsigned int)(1<<ccif_phy_arb_mode_seq[rx_seq_for_isr]) )
  965. // rx_seq_for_isr++;
  966. if( (ch)==(unsigned int)(1<<ccif_phy_arb_mode_seq[rx_seq_for_isr]) )
  967. rx_seq_for_isr++;
  968. rx_last_time_val = ch;
  969. CCIF_Set_Ack(ch);
  970. CCIF_Get_Rch_Num();
  971. CCIF_Get_Rch_Num();
  972. }
  973. // 3. Check if RX all channel have data
  974. if((ch==0xFFFF) ||(rx_seq_for_isr == CCIF_MAX_PHY)){
  975. Set_Isr_Work_Done(TC_04);
  976. CCIF_Mask_Irq();
  977. // CCIF_Set_Ack(0xFFFFFFFF);
  978. ccif_debug("Output: seq_for_isr:0x%x\r\n", rx_seq_for_isr);
  979. }
  980. }
  981. int ccif_ap_test_case_01(void)
  982. {
  983. unsigned int irq, data[4], phy;
  984. int i;
  985. unsigned int md_result;
  986. unsigned int reg_busy=0, reg_start=0;
  987. unsigned int tmp_busy, tmp_start;
  988. unsigned int ret=0;
  989. unsigned int last_busy_val=0;
  990. ccif_debug("[TC01]AP ==> MD sequence test\n");
  991. AP_MD_test_case_sync_AP_Side(TC_01);
  992. CCIF_Set_Con(0);
  993. CCIF_Register(0);
  994. AP_MD_Ready_to_Test_Sync_AP_Side();
  995. for (i = 0; i < CCIF_MAX_PHY; i++) {
  996. phy = phy_ch_seq_mode_seq[i];
  997. data[0] = data[1] = data[2] = data[3] = data_pattern[TC_01]+phy;
  998. // 1. Busy bit should be zero
  999. tmp_busy = CCIF_Get_Busy();
  1000. tmp_start = CCIF_Get_Start();
  1001. if(tmp_busy&(1<<phy)){
  1002. ccif_error("\tphysical ch %d busy now, abnormal\n", phy);
  1003. ret=(1<<0);
  1004. }
  1005. if(tmp_start&(1<<phy)){
  1006. ccif_error("\tphysical ch %d start bit is 1 now, abnormal\n", phy);
  1007. ret=(1<<1);
  1008. }
  1009. // 2. Busy bits for this channel will change to 1
  1010. CCIF_Set_Busy(1 << phy);
  1011. reg_busy |= 1<<phy;
  1012. if( (reg_busy&CCIF_Get_Busy())!= CCIF_Get_Busy() ){
  1013. ccif_error("\tphysical ch %d busy bit change to 1 fail\n", phy);
  1014. ret=(1<<3);
  1015. }
  1016. CCIF_Set_TxData(phy, (unsigned char*)data);
  1017. CCIF_Set_Tch_Num(phy);
  1018. //CTP_Wait_msec(1000);
  1019. ccif_debug("send data to physical ch %d, data:0x%x, 0x%x, 0x%x, 0x%x\n", phy, data[0], data[1], data[2], data[3]);
  1020. // 3. Start bit for this ch should change to 1
  1021. reg_start|= 1<<phy;
  1022. if( (reg_start&CCIF_Get_Start())!= CCIF_Get_Start() ){
  1023. ccif_error("physical ch %d start bit change to 1 fail\n", phy);
  1024. ret=(1<<4);
  1025. }
  1026. }
  1027. last_busy_val = reg_busy;
  1028. i=20;
  1029. // while(i-- && (last_busy_val=CCIF_Get_Busy())) {delay_a_while(500000) ;}
  1030. while(i-- && (last_busy_val=CCIF_Get_Busy())) {mdelay(200) ; ccif_debug("[TC01]Test,2 CCIF_Get_Busy():0x%x \n", CCIF_Get_Busy());}
  1031. if (last_busy_val)
  1032. {
  1033. ccif_error("last_busy_val=%x Failed to clear \n",last_busy_val);
  1034. ret=(1<<5);
  1035. }
  1036. AP_Get_MD_Test_Result(&md_result, 1);
  1037. if( (0==md_result)&&(0==ret) ){
  1038. ccif_debug("[TC01]Test pass\n");
  1039. return 0;
  1040. }else{
  1041. ccif_error("[TC01]Test fail,md_result=%d,ap_result=%d\n",md_result,ret);
  1042. return -1;
  1043. }
  1044. }
  1045. int ccif_ap_test_case_02(void)
  1046. {
  1047. int i;
  1048. unsigned int md_result=0;
  1049. int error_val=0;
  1050. ccif_debug("[TC02]AP <== MD sequence test\n");
  1051. AP_MD_test_case_sync_AP_Side(TC_02);
  1052. CCIF_Set_Con(0);
  1053. CCIF_Register(0);
  1054. for(i=1; i<=CCIF_MAX_PHY; i++)
  1055. test_heap_ptr[i] = result_unknow;
  1056. test_heap_ptr[0] = 0;
  1057. Reset_Isr_Work_State(TC_02);
  1058. CCIF_Register(ccif_seq_isr_cb_for_tc02);
  1059. CCIF_Mask_Irq(CCIF_IRQ_ID);
  1060. AP_MD_Ready_to_Test_Sync_AP_Side();
  1061. // Sleep 500ms to let MD side send all 8 channel data done
  1062. //CTP_Wait_msec(500);
  1063. CCIF_UnMask_Irq(CCIF_IRQ_ID);
  1064. // Waiting test done
  1065. ccif_debug("\tWaiting md test done\n");
  1066. while(!Is_Isr_Work_Done(TC_02));
  1067. // Check result
  1068. ccif_debug("\tCheck AP <== MD result\n");
  1069. for(i=1; i<=CCIF_MAX_PHY; i++){
  1070. if(result_fail == (test_heap_ptr[i]&0xffff0000)){
  1071. ccif_error("\tAP <== MD seq mode data check fail\n");
  1072. error_val = -1;
  1073. goto _Result;
  1074. }
  1075. if(0 != (test_heap_ptr[i]&0x0000ffff)){
  1076. ccif_error("\tAP <== MD seq mode check seq fail\n");
  1077. error_val = -2;
  1078. goto _Result;
  1079. }
  1080. }
  1081. if(i!=CCIF_MAX_PHY+1){
  1082. ccif_error("\tAP <== MD seq mode channel num fail\n");
  1083. error_val = -3;
  1084. }
  1085. _Result:
  1086. ccif_debug("\tCheck AP ==> MD result\n");
  1087. AP_Get_MD_Test_Result(&md_result, 1);
  1088. if( (0==md_result)&&(0==error_val) ){
  1089. ccif_debug("[TC02]Test pass\n");
  1090. return 0;
  1091. }else{
  1092. ccif_error("[TC02]Test fail,md_result=%d,ret=\n",md_result,error_val);
  1093. return -1;
  1094. }
  1095. }
  1096. int ccif_ap_test_case_03(void)
  1097. {
  1098. unsigned int irq, data[4], phy;
  1099. unsigned int i;
  1100. unsigned int reg_busy=0, reg_start=0;
  1101. unsigned int tmp_busy, tmp_start;
  1102. unsigned int ret=0,md_result = 0;
  1103. unsigned int last_busy_val=0;
  1104. ccif_debug("[TC03]AP ==> MD arbitration test\n");
  1105. CCIF_Set_Con(1);
  1106. AP_MD_test_case_sync_AP_Side(TC_03);
  1107. CCIF_Register(0);
  1108. AP_MD_Ready_to_Test_Sync_AP_Side();
  1109. for (i = 0; i < CCIF_MAX_PHY; i++) {
  1110. data[0] = data[1] = data[2] = data[3] = data_pattern[TC_03]+i;
  1111. phy = ccif_phy_arb_mode_seq[i];
  1112. // 1. Busy bit should be zero
  1113. tmp_busy = CCIF_Get_Busy();
  1114. tmp_start = CCIF_Get_Start();
  1115. if(tmp_busy&(1<<phy)){
  1116. ccif_error("\tphysical ch %d busy now, abnormal\n", phy);
  1117. ret=(1<<0);
  1118. }
  1119. if(tmp_start&(1<<phy)){
  1120. ccif_error("\tphysical ch %d start bit is 1 now, abnormal\n", phy);
  1121. ret=(1<<1);
  1122. }
  1123. // 2. Busy bits for this channel will change to 1
  1124. CCIF_Set_Busy(1<<phy);
  1125. reg_busy |= 1<<phy;
  1126. if( (reg_busy&CCIF_Get_Busy())!= CCIF_Get_Busy() ){
  1127. ccif_error("\tphysical ch %d busy bit change to 1 fail\n", phy);
  1128. ret=(1<<2);
  1129. }
  1130. CCIF_Set_TxData(phy, (unsigned char*)data);
  1131. CCIF_Set_Tch_Num(phy);
  1132. ccif_debug("send data to physical ch %d\n", phy);
  1133. // 3. Start bit for this ch should change to 1
  1134. reg_start|= 1<<phy;
  1135. if( (reg_start&CCIF_Get_Start())!= CCIF_Get_Start() ){
  1136. ccif_error("\tphysical ch %d start bit change to 1 fail\n", phy);
  1137. ret=(1<<3);
  1138. }
  1139. }
  1140. last_busy_val = reg_busy;
  1141. i=20;
  1142. while(i-- && (last_busy_val=CCIF_Get_Busy())) {mdelay(20);}
  1143. if (last_busy_val)
  1144. {
  1145. ccif_debug("last_busy_val=%x Failed to clear \n",last_busy_val);
  1146. ret=(1<<4);
  1147. }
  1148. AP_Get_MD_Test_Result(&md_result, 1);
  1149. if(ret||md_result){
  1150. ccif_error("[TC03]Test fail, md_result=%d,ret=%d\n",md_result,ret);
  1151. return -1;
  1152. }else{
  1153. ccif_debug("[TC03]Test pass\n");
  1154. return 0;
  1155. }
  1156. }
  1157. int ccif_ap_test_case_04(void)
  1158. {
  1159. unsigned int irq, data[4], phy;
  1160. int i;
  1161. unsigned int ret=0, md_result=0;
  1162. ccif_debug("[TC04]AP <== MD arbitration test\n");
  1163. rx_seq_for_isr = 0;
  1164. rx_last_time_val = 0;
  1165. //CCIF_CHECK_POINT_IN_BEGIN();
  1166. AP_MD_test_case_sync_AP_Side(TC_04);
  1167. CCIF_Set_Con(1);
  1168. CCIF_UnMask_Irq();
  1169. mdelay(1000);
  1170. ccif_debug("delay for some time \n");
  1171. CCIF_Register(0);
  1172. for(i=1; i<=CCIF_MAX_PHY; i++)
  1173. test_heap_ptr[i] = result_unknow;
  1174. test_heap_ptr[0] = 0;
  1175. Reset_Isr_Work_State(TC_04);
  1176. ccif_debug("\tCCIF_Register_User_Isr \n");
  1177. CCIF_Register_User_Isr(ccif_arb_isr_for_tc04);
  1178. ccif_debug("\tAP_MD_Ready_to_Test_Sync_AP_Side \n");
  1179. AP_MD_Ready_to_Test_Sync_AP_Side();
  1180. // Waiting test done
  1181. while(!Is_Isr_Work_Done(TC_04));
  1182. ccif_debug("\tIsr work done \n");
  1183. // Check Data
  1184. for(i=0; i<CCIF_MAX_PHY; i++){
  1185. CCIF_Get_RxData(ccif_phy_arb_mode_seq[i], (unsigned char*)data);
  1186. if( (data[0]==data[1])&&(data[1]==data[2])&&(data[2]==data[3])&&
  1187. (data[3]==(data_pattern[TC_04]+i)) );
  1188. else{
  1189. ret=1;
  1190. }
  1191. // Ack AP
  1192. CCIF_Set_Ack(1<<ccif_phy_arb_mode_seq[i]);
  1193. mdelay(1);
  1194. }
  1195. CCIF_Register_User_Isr(0);
  1196. rx_seq_for_isr = 0;
  1197. rx_last_time_val = 0;
  1198. AP_Get_MD_Test_Result(&md_result, 1);
  1199. //CCIF_CHECK_POINT_IN_END();
  1200. if(ret||md_result){
  1201. ccif_error("[TC04]Test fail,md_result=%d,ret=%d\n",md_result,ret);
  1202. return -1;
  1203. }else{
  1204. ccif_debug("[TC04]Test pass\n");
  1205. return 0;
  1206. }
  1207. }
  1208. /******************************************************************************/
  1209. #endif
  1210. void dummy_ap_entry(void)
  1211. {
  1212. int md_check_tbl[] = {1<<MD1_IMG, 1<<MD2_IMG};
  1213. int i=0;
  1214. int get_val=0;
  1215. #if 0
  1216. volatile unsigned int count;
  1217. volatile unsigned int count1;
  1218. #endif
  1219. // reinit UART, overwrite DWS setting
  1220. md_uart_config(-1);
  1221. // Disable AP WDT
  1222. *(volatile unsigned int *)(TOPRGU_BASE) = 0x22000000;
  1223. printf("Welcome to use dummy AP!\n");
  1224. //get_val = get_input();
  1225. apply_env_setting(get_val);
  1226. // 0, Parse header info
  1227. printf("Parsing image info!\n");
  1228. parse_img_header((unsigned int*)g_boot_arg->part_info, (unsigned int)g_boot_arg->part_num);
  1229. printf("Begin to configure MD run env!\n");
  1230. // 1, Setup special GPIO request (RF/SIM/UART ... etc)
  1231. printf("Configure GPIO!\n");
  1232. if((img_load_flag&((1<<MD1_IMG)|(1<<MD2_IMG))) == ((1<<MD1_IMG)|(1<<MD2_IMG))) {
  1233. md_gpio_config(2);
  1234. } else if (img_load_flag & (1<<MD1_IMG)) {
  1235. md_gpio_config(0);
  1236. } else if (img_load_flag & (1<<MD2_IMG)) {
  1237. md_gpio_config(1);
  1238. }
  1239. // 2, Setup per-MD env and boot up MD
  1240. for(i=0; i<MAX_MD_NUM; i++) {
  1241. if(img_load_flag & md_check_tbl[i]) {
  1242. printf("MD%d Enabled\n", i+1);
  1243. let_md_go(i);
  1244. }
  1245. }
  1246. // 3, Config UART
  1247. printf("Config UART!\n");
  1248. if((img_load_flag&((1<<MD1_IMG)|(1<<MD2_IMG))) == ((1<<MD1_IMG)|(1<<MD2_IMG))) {
  1249. md_uart_config(2);
  1250. } else if (img_load_flag & (1<<MD1_IMG)) {
  1251. md_uart_config(0);
  1252. } else if (img_load_flag & (1<<MD2_IMG)) {
  1253. md_uart_config(1);
  1254. }
  1255. printf("All dummy AP config done\n");
  1256. md_wdt_init();
  1257. #if 0
  1258. count = 1;
  1259. while(count--) {
  1260. count1 = 0x80000000;
  1261. while(count1--);
  1262. }
  1263. printf("Write MD WDT SWRST\n");
  1264. *((volatile unsigned int *)0x2005001C) = 0x1209;
  1265. count = 1;
  1266. while(count--) {
  1267. count1 = 0x08000000;
  1268. while(count1--);
  1269. }
  1270. printf("Read back STA:%x!!\n", *((volatile unsigned int*)0x2005000C));
  1271. #endif
  1272. #if CCIF_DVT
  1273. arch_disable_cache(UCACHE);
  1274. ts_init_handler();
  1275. while(1) {
  1276. printf("select test case:\n");
  1277. get_val = get_input();
  1278. uart_putc(get_val);
  1279. switch(get_val) {
  1280. case '1':
  1281. ccif_ap_test_case_01();
  1282. break;
  1283. case '2':
  1284. ccif_ap_test_case_02();
  1285. break;
  1286. case '3':
  1287. ccif_ap_test_case_03();
  1288. break;
  1289. case '4':
  1290. ccif_ap_test_case_04();
  1291. break;
  1292. case 'q':
  1293. goto nothing;
  1294. default:
  1295. break;
  1296. };
  1297. };
  1298. #endif
  1299. nothing:
  1300. printf("enter while(1), Yeah!!\n");
  1301. while(1);
  1302. }
  1303. void md_wdt_irq_handler(unsigned int irq)
  1304. {
  1305. unsigned int reg_value;
  1306. #if defined(ENABLE_MD_RESET_SPM) || defined(ENABLE_MD_RESET_RGU)
  1307. // update counter
  1308. unsigned int cnt = *(volatile unsigned int *)(TOP_RGU_WDT_NONRST_REG);
  1309. *(volatile unsigned int *)(TOP_RGU_WDT_NONRST_REG) = cnt+1;
  1310. // reset UART config
  1311. md_uart_config(-1);
  1312. if(irq == MT_MD_WDT1_IRQ_ID) {
  1313. #ifdef ENABLE_MD_RESET_SPM
  1314. printf("MD1 power off\n");
  1315. spm_mtcmos_ctrl_mdsys1(STA_POWER_DOWN);
  1316. mdelay(5);
  1317. #endif
  1318. #ifdef ENABLE_MD_RESET_RGU
  1319. printf("MD1 reset\n");
  1320. reg_value = *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST);
  1321. *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST) = reg_value|0x88000000|(0x1<<7);
  1322. mdelay(5);
  1323. reg_value = *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST);
  1324. *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST) = (reg_value|0x88000000)&(~(0x1<<7));
  1325. #endif
  1326. let_md_go(0);
  1327. }
  1328. if(irq == MT_MD_WDT2_IRQ_ID) {
  1329. #ifdef ENABLE_MD_RESET_SPM
  1330. printf("MD2 power off\n");
  1331. spm_mtcmos_ctrl_mdsys2(STA_POWER_DOWN);
  1332. mdelay(5);
  1333. #endif
  1334. #ifdef ENABLE_MD_RESET_RGU
  1335. printf("MD2 reset\n");
  1336. reg_value = *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST);
  1337. *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST) = reg_value|0x88000000|(0x1<<15);
  1338. mdelay(5);
  1339. reg_value = *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST);
  1340. *((volatile unsigned int*)TOP_RGU_WDT_SWSYSRST) = (reg_value|0x88000000)&(~(0x1<<15));
  1341. #endif
  1342. let_md_go(1);
  1343. }
  1344. printf("Config UART after MD WDT!\n");
  1345. if((img_load_flag&((1<<MD1_IMG)|(1<<MD2_IMG))) == ((1<<MD1_IMG)|(1<<MD2_IMG))) {
  1346. md_uart_config(2);
  1347. } else if (img_load_flag & (1<<MD1_IMG)) {
  1348. md_uart_config(0);
  1349. } else if (img_load_flag & (1<<MD2_IMG)) {
  1350. md_uart_config(1);
  1351. }
  1352. #else
  1353. md_uart_config(-1);
  1354. printf("Get MD WDT irq, STA:%x!!\n", *((volatile unsigned int*)0x2005000C));
  1355. #ifdef IGNORE_MD_WDT
  1356. printf("ignore MD WDT\n");
  1357. #else
  1358. printf("whole system reboot\n");
  1359. *(volatile unsigned int *)(TOP_RGU_WDT_MODE) = 0x22000000;
  1360. *(volatile unsigned int *)(TOP_RGU_WDT_SWRST) = 0x1209;
  1361. while(1);
  1362. #endif
  1363. #endif
  1364. }
  1365. void dummy_ap_irq_handler(unsigned int irq)
  1366. {
  1367. #ifdef CCIF_DVT
  1368. CCIF_Isr(irq);
  1369. #endif
  1370. switch(irq) {
  1371. case MT_MD_WDT1_IRQ_ID:
  1372. if(img_load_flag &(1<<MD1_IMG)) {
  1373. md_wdt_irq_handler(MT_MD_WDT1_IRQ_ID);
  1374. mt_irq_ack(MT_MD_WDT1_IRQ_ID);
  1375. mt_irq_unmask(MT_MD_WDT1_IRQ_ID);
  1376. }
  1377. break;
  1378. case MT_MD_WDT2_IRQ_ID:
  1379. if(img_load_flag &(1<<MD2_IMG)) {
  1380. md_wdt_irq_handler(MT_MD_WDT2_IRQ_ID);
  1381. mt_irq_ack(MT_MD_WDT2_IRQ_ID);
  1382. mt_irq_unmask(MT_MD_WDT2_IRQ_ID);
  1383. }
  1384. break;
  1385. default:
  1386. break;
  1387. }
  1388. }
  1389. void pmic_init_sequence(void)
  1390. {
  1391. // PMIC wrapper is inited in preloader
  1392. // provided by Wy Chuang, updated 12/03
  1393. pmic_config_interface(0x4,0x1,0x1,4); // [4:4]: RG_EN_DRVSEL; Ricky
  1394. pmic_config_interface(0xA,0x1,0x1,0); // [0:0]: DDUVLO_DEB_EN; Ricky
  1395. pmic_config_interface(0xC,0x1,0x1,0); // [0:0]: VPROC_PG_H2L_EN; Ricky
  1396. pmic_config_interface(0xC,0x1,0x1,1); // [1:1]: VAUX18_PG_H2L_EN; Ricky
  1397. pmic_config_interface(0xC,0x1,0x1,4); // [4:4]: VCORE1_PG_H2L_EN; Ricky
  1398. pmic_config_interface(0xC,0x1,0x1,5); // [5:5]: VSYS22_PG_H2L_EN; Ricky
  1399. pmic_config_interface(0xC,0x1,0x1,6); // [6:6]: VLTE_PG_H2L_EN; Ricky
  1400. pmic_config_interface(0xC,0x1,0x1,7); // [7:7]: VIO18_PG_H2L_EN; Ricky
  1401. pmic_config_interface(0xC,0x1,0x1,8); // [8:8]: VAUD28_PG_H2L_EN; Ricky
  1402. pmic_config_interface(0xC,0x1,0x1,9); // [9:9]: VTCXO_PG_H2L_EN; Ricky
  1403. pmic_config_interface(0xC,0x1,0x1,10); // [10:10]: VUSB_PG_H2L_EN; Ricky
  1404. pmic_config_interface(0xC,0x1,0x1,11); // [11:11]: VSRAM_PG_H2L_EN; Ricky
  1405. pmic_config_interface(0xC,0x1,0x1,12); // [12:12]: VIO28_PG_H2L_EN; Ricky
  1406. pmic_config_interface(0xC,0x1,0x1,13); // [13:13]: VM_PG_H2L_EN; Ricky
  1407. pmic_config_interface(0xE,0x1,0x1,10); // [10:10]: VUSB_PG_ENB; Ricky E1 workaround
  1408. pmic_config_interface(0x10,0x1,0x1,5); // [5:5]: UVLO_L2H_DEB_EN; Ricky
  1409. pmic_config_interface(0x16,0x1,0x1,0); // [0:0]: STRUP_PWROFF_SEQ_EN; Ricky
  1410. pmic_config_interface(0x16,0x1,0x1,1); // [1:1]: STRUP_PWROFF_PREOFF_EN; Ricky
  1411. pmic_config_interface(0x1E,0x0,0x1,11); // [11:11]: RG_TESTMODE_SWEN; CC: Test mode, first command
  1412. pmic_config_interface(0x40,0x1,0x1,12); // [12:12]: RG_RST_DRVSEL; Ricky
  1413. pmic_config_interface(0x204,0x1,0x1,4); // [4:4]: RG_SRCLKEN_IN0_HW_MODE; Juinn-Ting
  1414. pmic_config_interface(0x204,0x1,0x1,5); // [5:5]: RG_SRCLKEN_IN1_HW_MODE; Juinn-Ting
  1415. pmic_config_interface(0x204,0x1,0x1,6); // [6:6]: RG_OSC_SEL_HW_MODE; Juinn-Ting: E1 only
  1416. pmic_config_interface(0x226,0x1,0x1,0); // [0:0]: RG_SMT_WDTRSTB_IN; Ricky
  1417. pmic_config_interface(0x226,0x1,0x1,2); // [2:2]: RG_SMT_SRCLKEN_IN0; Ricky
  1418. pmic_config_interface(0x226,0x1,0x1,3); // [3:3]: RG_SMT_SRCLKEN_IN1; Ricky
  1419. pmic_config_interface(0x242,0x1,0x1,2); // [2:2]: RG_RTC_75K_CK_PDN; Juinn-Ting
  1420. pmic_config_interface(0x242,0x1,0x1,3); // [3:3]: RG_RTCDET_CK_PDN; Juinn-Ting
  1421. pmic_config_interface(0x248,0x1,0x1,13); // [13:13]: RG_RTC_EOSC32_CK_PDN; Juinn-Ting
  1422. pmic_config_interface(0x248,0x1,0x1,14); // [14:14]: RG_TRIM_75K_CK_PDN; Juinn-Ting
  1423. pmic_config_interface(0x25A,0x1,0x1,9); // [9:9]: RG_75K_32K_SEL; Angela
  1424. pmic_config_interface(0x278,0x1,0x1,10); // [10:10]: RG_AUXADC_26M_CK_PDN_HWEN; ZF
  1425. pmic_config_interface(0x278,0x1,0x1,11); // [11:11]: RG_AUXADC_CK_CKSEL_HWEN; ZF
  1426. pmic_config_interface(0x422,0x1,0x1,0); // [0:0]: VSRAM_TRACK_SLEEP_CTRL; SRAM Tracking,Fandy
  1427. pmic_config_interface(0x422,0x1,0x1,1); // [1:1]: VSRAM_TRACK_ON_CTRL; SRAM Tracking,Fandy
  1428. pmic_config_interface(0x422,0x1,0x1,2); // [2:2]: VPROC_TRACK_ON_CTRL; SRAM Tracking,Fandy
  1429. pmic_config_interface(0x424,0x0,0x7F,0); // [6:0]: VSRAM_VOSEL_DELTA; SRAM Tracking,Fandy
  1430. pmic_config_interface(0x424,0x10,0x7F,8); // [14:8]: VSRAM_VOSEL_OFFSET; SRAM Tracking,Fandy
  1431. pmic_config_interface(0x426,0x48,0x7F,0); // [6:0]: VSRAM_VOSEL_ON_LB; SRAM Tracking,Fandy
  1432. pmic_config_interface(0x426,0x78,0x7F,8); // [14:8]: VSRAM_VOSEL_ON_HB; SRAM Tracking,Fandy
  1433. pmic_config_interface(0x428,0x28,0x7F,0); // [6:0]: VSRAM_VOSEL_SLEEP_LB; SRAM Tracking,Fandy
  1434. pmic_config_interface(0x42E,0x1,0x1FF,0); // [8:0]: RG_SMPS_TESTMODE_B;
  1435. pmic_config_interface(0x462,0x3,0x3,10); // [11:10]: RG_VPA_SLP; Seven,Stability
  1436. pmic_config_interface(0x482,0x1,0x1,1); // [1:1]: VPROC_VOSEL_CTRL; ShangYing
  1437. pmic_config_interface(0x488,0x11,0x7F,0); // [6:0]: VPROC_SFCHG_FRATE; 11/20 DVFS raising slewrate,SY
  1438. pmic_config_interface(0x488,0x1,0x1,7); // [7:7]: VPROC_SFCHG_FEN; VSRAM tracking,Fandy
  1439. pmic_config_interface(0x488,0x4,0x7F,8); // [14:8]: VPROC_SFCHG_RRATE; 11/20 DVFS raising slewrate,SY
  1440. pmic_config_interface(0x488,0x1,0x1,15); // [15:15]: VPROC_SFCHG_REN; VSRAM tracking,Fandy
  1441. pmic_config_interface(0x48E,0x28,0x7F,0); // [6:0]: VPROC_VOSEL_SLEEP; 11/20 Sleep mode 0.85V
  1442. pmic_config_interface(0x498,0x3,0x3,0); // [1:0]: VPROC_TRANS_TD; ShangYing
  1443. pmic_config_interface(0x498,0x1,0x3,4); // [5:4]: VPROC_TRANS_CTRL; ShangYing
  1444. pmic_config_interface(0x498,0x1,0x1,8); // [8:8]: VPROC_VSLEEP_EN; 11/20 sleep mode by SRCLKEN
  1445. pmic_config_interface(0x49A,0x0,0x3,4); // [5:4]: VPROC_OSC_SEL_SRCLKEN_SEL; ShangYing
  1446. pmic_config_interface(0x49A,0x0,0x3,8); // [9:8]: VPROC_R2R_PDN_SRCLKEN_SEL; ShangYing
  1447. pmic_config_interface(0x49A,0x0,0x3,14); // [15:14]: VPROC_VSLEEP_SRCLKEN_SEL; ShangYing
  1448. pmic_config_interface(0x4AA,0x1,0x1,1); // [1:1]: VSRAM_VOSEL_CTRL; SRAM tracking,Fandy
  1449. pmic_config_interface(0x4B0,0x8,0x7F,0); // [6:0]: VSRAM_SFCHG_FRATE; SRAM tracking,Fandy
  1450. pmic_config_interface(0x4B0,0x1,0x1,7); // [7:7]: VSRAM_SFCHG_FEN; SRAM tracking,Fandy
  1451. pmic_config_interface(0x4B0,0x8,0x7F,8); // [14:8]: VSRAM_SFCHG_RRATE; SRAM tracking,Fandy
  1452. pmic_config_interface(0x4B0,0x1,0x1,15); // [15:15]: VSRAM_SFCHG_REN; SRAM tracking,Fandy
  1453. pmic_config_interface(0x4B4,0x40,0x7F,0); // [6:0]: VSRAM_VOSEL_ON; SRAM tracking,Fandy
  1454. pmic_config_interface(0x4D2,0x1,0x1,1); // [1:1]: VLTE_VOSEL_CTRL; ShangYing
  1455. pmic_config_interface(0x4D8,0x11,0x7F,0); // [6:0]: VLTE_SFCHG_FRATE; 11/20 DVFS falling slewrate
  1456. pmic_config_interface(0x4D8,0x4,0x7F,8); // [14:8]: VLTE_SFCHG_RRATE; 11/20 DVFS raising slewrate
  1457. pmic_config_interface(0x4DE,0x28,0x7F,0); // [6:0]: VLTE_VOSEL_SLEEP; 11/20 Sleep mode 0.85V
  1458. pmic_config_interface(0x4E8,0x3,0x3,0); // [1:0]: VLTE_TRANS_TD; ShangYing
  1459. pmic_config_interface(0x4E8,0x1,0x1,8); // [8:8]: VLTE_VSLEEP_EN; 11/20 sleep mode by SRCLKEN
  1460. pmic_config_interface(0x4EA,0x0,0x3,4); // [5:4]: VLTE_OSC_SEL_SRCLKEN_SEL;
  1461. pmic_config_interface(0x4EA,0x0,0x3,8); // [9:8]: VLTE_R2R_PDN_SRCLKEN_SEL;
  1462. pmic_config_interface(0x4EA,0x0,0x3,14); // [15:14]: VLTE_VSLEEP_SRCLKEN_SEL;
  1463. pmic_config_interface(0x60E,0x1,0x1,1); // [1:1]: VCORE1_VOSEL_CTRL; ShangYing
  1464. pmic_config_interface(0x614,0x11,0x7F,0); // [6:0]: VCORE1_SFCHG_FRATE; 11/20 DVS falling slewrate
  1465. pmic_config_interface(0x614,0x4,0x7F,8); // [14:8]: VCORE1_SFCHG_RRATE; 11/20 DVS rising slewrate
  1466. pmic_config_interface(0x61A,0x28,0x7F,0); // [6:0]: VCORE1_VOSEL_SLEEP; 11/20 sleep mode 0.85V
  1467. pmic_config_interface(0x624,0x3,0x3,0); // [1:0]: VCORE1_TRANS_TD; ShangYing
  1468. pmic_config_interface(0x624,0x1,0x1,8); // [8:8]: VCORE1_VSLEEP_EN; 11/20 sleep mode control by SRCLKEN
  1469. pmic_config_interface(0x626,0x0,0x3,4); // [5:4]: VCORE1_OSC_SEL_SRCLKEN_SEL; ShangYing
  1470. pmic_config_interface(0x626,0x0,0x3,8); // [9:8]: VCORE1_R2R_PDN_SRCLKEN_SEL; ShangYing
  1471. pmic_config_interface(0x626,0x0,0x3,14); // [15:14]: VCORE1_VSLEEP_SRCLKEN_SEL; ShangYing
  1472. pmic_config_interface(0x646,0x5,0x7,0); // [2:0]: VSYS22_BURST; Seven
  1473. pmic_config_interface(0x664,0x2,0x7F,0); // [6:0]: VPA_SFCHG_FRATE; Seven
  1474. pmic_config_interface(0x664,0x0,0x1,7); // [7:7]: VPA_SFCHG_FEN; Seven
  1475. pmic_config_interface(0x664,0x2,0x7F,8); // [14:8]: VPA_SFCHG_RRATE; Seven
  1476. pmic_config_interface(0x664,0x0,0x1,15); // [15:15]: VPA_SFCHG_REN; Seven
  1477. pmic_config_interface(0x67E,0x3,0x3,4); // [5:4]: VPA_DVS_TRANS_CTRL; Seven
  1478. pmic_config_interface(0xA02,0x1,0x1,3); // [3:3]: RG_VTCXO_1_ON_CTRL; by RF request 11/02,Luke
  1479. pmic_config_interface(0xA06,0x1,0x1,6); // [6:6]: RG_VAUX18_AUXADC_PWDB_EN; Chuan-Hung
  1480. pmic_config_interface(0xA30,0x0,0x1,0); // [0:0]: RG_VEFUSE_MODE_SET; Fandy:Disable VEFUSE
  1481. pmic_config_interface(0xA44,0x1,0x1,1); // [1:1]: RG_TREF_EN; Tim
  1482. pmic_config_interface(0xA46,0x0,0x1,14); // [14:14]: QI_VM_STB; Fandy, disable
  1483. pmic_config_interface(0xC14,0x1,0x1,0); // [0:0]: RG_SKIP_OTP_OUT; Fandy: for CORE power(VDVFS1x, VCOREx, VSRAM_DVFS) max voltage limitation.
  1484. pmic_config_interface(0xCBC,0x1,0x1,8); // [8:8]: FG_SLP_EN; Ricky
  1485. pmic_config_interface(0xCBC,0x1,0x1,9); // [9:9]: FG_ZCV_DET_EN; Ricky
  1486. pmic_config_interface(0xCC0,0x24,0xFFFF,0); // [15:0]: FG_SLP_CUR_TH; Ricky
  1487. pmic_config_interface(0xCC2,0x14,0xFF,0); // [7:0]: FG_SLP_TIME; Ricky
  1488. pmic_config_interface(0xCC4,0xFF,0xFF,8); // [15:8]: FG_DET_TIME; Ricky
  1489. pmic_config_interface(0xE94,0x0,0x1,13); // [13:13]: AUXADC_CK_AON_GPS; YP Niou, sync with golden setting
  1490. pmic_config_interface(0xE94,0x0,0x1,14); // [14:14]: AUXADC_CK_AON_MD; YP Niou, sync with golden setting
  1491. pmic_config_interface(0xE94,0x0,0x1,15); // [15:15]: AUXADC_CK_AON; YP Niou, sync with golden setting
  1492. pmic_config_interface(0xEA4,0x1,0x3,4); // [5:4]: AUXADC_TRIM_CH2_SEL; Ricky
  1493. pmic_config_interface(0xEA4,0x1,0x3,6); // [7:6]: AUXADC_TRIM_CH3_SEL; Ricky
  1494. pmic_config_interface(0xEA4,0x1,0x3,8); // [9:8]: AUXADC_TRIM_CH4_SEL; Ricky
  1495. pmic_config_interface(0xEA4,0x1,0x3,10); // [11:10]: AUXADC_TRIM_CH5_SEL; Ricky
  1496. pmic_config_interface(0xEA4,0x1,0x3,12); // [13:12]: AUXADC_TRIM_CH6_SEL; Ricky
  1497. pmic_config_interface(0xEA4,0x2,0x3,14); // [15:14]: AUXADC_TRIM_CH7_SEL; Ricky
  1498. pmic_config_interface(0xEA6,0x1,0x3,0); // [1:0]: AUXADC_TRIM_CH8_SEL; Ricky
  1499. pmic_config_interface(0xEA6,0x1,0x3,2); // [3:2]: AUXADC_TRIM_CH9_SEL; Ricky
  1500. pmic_config_interface(0xEA6,0x1,0x3,4); // [5:4]: AUXADC_TRIM_CH10_SEL; Ricky
  1501. pmic_config_interface(0xEA6,0x1,0x3,6); // [7:6]: AUXADC_TRIM_CH11_SEL; Ricky
  1502. pmic_config_interface(0xEB8,0x1,0x1,14); // [14:14]: AUXADC_START_SHADE_EN; Chuan-Hung
  1503. pmic_config_interface(0xF4A,0xB,0xF,4); // [7:4]: RG_VCDT_HV_VTH; Tim:VCDT_HV_th=7V
  1504. pmic_config_interface(0xF54,0x0,0x7,1); // [3:1]: RG_VBAT_OV_VTH; Tim:for 4.35 battery
  1505. pmic_config_interface(0xF62,0x3,0xF,0); // [3:0]: RG_CHRWDT_TD; Tim:WDT=32s
  1506. pmic_config_interface(0xF6C,0x2,0x1F,0); // [4:0]: RG_LBAT_INT_VTH; Ricky: E1 only
  1507. pmic_config_interface(0xF70,0x1,0x1,1); // [1:1]: RG_BC11_RST; Tim:Disable BC1.1 timer
  1508. pmic_config_interface(0xF74,0x0,0x7,4); // [6:4]: RG_CSDAC_STP_DEC; Tim:Reduce ICHG current ripple (align 6323)
  1509. pmic_config_interface(0xF7A,0x1,0x1,2); // [2:2]: RG_CSDAC_MODE; Tim:Align 6323
  1510. pmic_config_interface(0xF7A,0x1,0x1,6); // [6:6]: RG_HWCV_EN; Tim:Align 6323
  1511. pmic_config_interface(0xF7A,0x1,0x1,7); // [7:7]: RG_ULC_DET_EN; Tim:Align 6323
  1512. }