mt_pmic_wrap_init.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2010. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver's
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. /******************************************************************************
  36. * mt_pmic_wrap_init.c - MTK PMIC Wrapper Driver
  37. *
  38. * Copyright 2008-2009 MediaTek Co.,Ltd.
  39. *
  40. * DESCRIPTION:
  41. * This file provides API for other drivers to access PMIC registers
  42. *
  43. ******************************************************************************/
  44. #include <platform/mt_pmic_wrap_init.h>
  45. //---start ---internal API--------------------------------------------------
  46. static S32 _pwrap_wacs2_nochk( U32 write, U32 adr, U32 wdata, U32 *rdata );
  47. static S32 _pwrap_reset_spislv(void);
  48. static S32 _pwrap_init_dio( U32 dio_en );
  49. static S32 _pwrap_init_cipher( void );
  50. static S32 _pwrap_init_reg_clock( U32 regck_sel );
  51. static BOOL _pwrap_timeout_ns (U64 start_time_ns, U64 timeout_time_ns);
  52. static U64 _pwrap_get_current_time(void);
  53. static U64 _pwrap_time2ns (U64 time_us);
  54. static S32 pwrap_read_nochk( U32 adr, U32 *rdata );
  55. static S32 pwrap_write_nochk( U32 adr, U32 wdata );
  56. static S32 _pwrap_wacs2_nochk( U32 write, U32 adr, U32 wdata, U32 *rdata );
  57. void pwrap_dump_ap_register(void);
  58. //---end--internal API--------------------------------------------------
  59. #ifdef PMIC_WRAP_NO_PMIC
  60. S32 pwrap_wacs2( U32 write, U32 adr, U32 wdata, U32 *rdata )
  61. {
  62. PWRAPERR("there is no PMIC real chip,PMIC_WRAP do Nothing\n");
  63. return 0;
  64. }
  65. //******************************************************************************
  66. //--external API for pmic_wrap user-------------------------------------------------
  67. //******************************************************************************
  68. S32 pwrap_read( U32 adr, U32 *rdata )
  69. {
  70. return pwrap_wacs2( 0, adr,0,rdata );
  71. }
  72. S32 pwrap_write( U32 adr, U32 wdata )
  73. {
  74. return pwrap_wacs2( 1, adr,wdata,0 );
  75. }
  76. /*
  77. *pmic_wrap init,init wrap interface
  78. *
  79. */
  80. S32 pwrap_init ( void )
  81. {
  82. dprintf(CRITICAL,"[PMIC_WRAP]There is no PMIC real chip, PMIC_WRAP do Nothing.\n");
  83. return 0;
  84. }
  85. #ifdef MACH_FPGA
  86. S32 pwrap_init_lk ( void )
  87. {
  88. return 0;
  89. }
  90. //--------------------------------------------------------
  91. // Function : _pwrap_status_update_test()
  92. // Description :only for early porting
  93. // Parameter :
  94. // Return :
  95. //--------------------------------------------------------
  96. static S32 _pwrap_status_update_test_porting( void )
  97. {
  98. return 0;
  99. }
  100. void pwrap_init_for_early_porting(void)
  101. {
  102. }
  103. #endif // #endif MACH_FPGA
  104. #else
  105. /******************************************************************************
  106. wrapper timeout
  107. ******************************************************************************/
  108. #define PWRAP_TIMEOUT
  109. //use the same API name with kernel driver
  110. //however,the timeout API in lk use tick instead of ns
  111. #ifdef PWRAP_TIMEOUT
  112. static U64 _pwrap_get_current_time(void)
  113. {
  114. return gpt4_get_current_tick();
  115. }
  116. //_pwrap_timeout_tick,use the same API name with kernel driver
  117. static BOOL _pwrap_timeout_ns (U64 start_time, U64 elapse_time)
  118. {
  119. return gpt4_timeout_tick(start_time, elapse_time);
  120. }
  121. //_pwrap_time2tick_us
  122. static U64 _pwrap_time2ns (U64 time_us)
  123. {
  124. return gpt4_time2tick_us(time_us);
  125. }
  126. #else
  127. static U64 _pwrap_get_current_time(void)
  128. {
  129. return 0;
  130. }
  131. static BOOL _pwrap_timeout_ns (U64 start_time, U64 elapse_time)//,U64 timeout_ns)
  132. {
  133. return FALSE;
  134. }
  135. static U64 _pwrap_time2ns (U64 time_us)
  136. {
  137. return 0;
  138. }
  139. #endif
  140. //#####################################################################
  141. //define macro and inline function (for do while loop)
  142. //#####################################################################
  143. typedef U32 (*loop_condition_fp)(U32);//define a function pointer
  144. static inline U32 wait_for_fsm_idle(U32 x)
  145. {
  146. return (GET_WACS0_FSM( x ) != WACS_FSM_IDLE );
  147. }
  148. static inline U32 wait_for_fsm_vldclr(U32 x)
  149. {
  150. return (GET_WACS0_FSM( x ) != WACS_FSM_WFVLDCLR);
  151. }
  152. static inline U32 wait_for_sync(U32 x)
  153. {
  154. return (GET_SYNC_IDLE0(x) != WACS_SYNC_IDLE);
  155. }
  156. static inline U32 wait_for_idle_and_sync(U32 x)
  157. {
  158. return ((GET_WACS2_FSM(x) != WACS_FSM_IDLE) || (GET_SYNC_IDLE2(x) != WACS_SYNC_IDLE)) ;
  159. }
  160. static inline U32 wait_for_wrap_idle(U32 x)
  161. {
  162. return ((GET_WRAP_FSM(x) != 0x0) || (GET_WRAP_CH_DLE_RESTCNT(x) != 0x0));
  163. }
  164. static inline U32 wait_for_wrap_state_idle(U32 x)
  165. {
  166. return ( GET_WRAP_AG_DLE_RESTCNT( x ) != 0 ) ;
  167. }
  168. static inline U32 wait_for_man_idle_and_noreq(U32 x)
  169. {
  170. return ( (GET_MAN_REQ(x) != MAN_FSM_NO_REQ ) || (GET_MAN_FSM(x) != MAN_FSM_IDLE) );
  171. }
  172. static inline U32 wait_for_man_vldclr(U32 x)
  173. {
  174. return (GET_MAN_FSM( x ) != MAN_FSM_WFVLDCLR) ;
  175. }
  176. static inline U32 wait_for_cipher_ready(U32 x)
  177. {
  178. return (x!=1) ;
  179. }
  180. static inline U32 wait_for_stdupd_idle(U32 x)
  181. {
  182. return ( GET_STAUPD_FSM(x) != 0x0) ;
  183. }
  184. static inline U32 wait_for_state_ready_init(loop_condition_fp fp,U32 timeout_us,U32 wacs_register,U32 *read_reg)
  185. {
  186. U64 start_time_ns=0, timeout_ns=0;
  187. U32 reg_rdata=0x0;
  188. start_time_ns = _pwrap_get_current_time();
  189. timeout_ns = _pwrap_time2ns(timeout_us);
  190. do
  191. {
  192. if (_pwrap_timeout_ns(start_time_ns, timeout_ns))
  193. {
  194. PWRAPERR("wait_for_state_ready_init timeout when waiting for idle\n");
  195. return E_PWR_WAIT_IDLE_TIMEOUT;
  196. }
  197. reg_rdata = WRAP_RD32(wacs_register);
  198. } while( fp(reg_rdata)); //IDLE State
  199. if(read_reg)
  200. *read_reg=reg_rdata;
  201. return 0;
  202. }
  203. static inline U32 wait_for_state_idle_init(loop_condition_fp fp,U32 timeout_us,U32 wacs_register,U32 wacs_vldclr_register,U32 *read_reg)
  204. {
  205. U64 start_time_ns=0, timeout_ns=0;
  206. U32 reg_rdata;
  207. start_time_ns = _pwrap_get_current_time();
  208. timeout_ns = _pwrap_time2ns(timeout_us);
  209. do
  210. {
  211. if (_pwrap_timeout_ns(start_time_ns, timeout_ns))
  212. {
  213. PWRAPERR("wait_for_state_idle_init timeout when waiting for idle\n");
  214. pwrap_dump_ap_register();
  215. //pwrap_trace_wacs2();
  216. //BUG_ON(1);
  217. return E_PWR_WAIT_IDLE_TIMEOUT;
  218. }
  219. reg_rdata = WRAP_RD32(wacs_register);
  220. //if last read command timeout,clear vldclr bit
  221. //read command state machine:FSM_REQ-->wfdle-->WFVLDCLR;write:FSM_REQ-->idle
  222. switch ( GET_WACS0_FSM( reg_rdata ) )
  223. {
  224. case WACS_FSM_WFVLDCLR:
  225. WRAP_WR32(wacs_vldclr_register , 1);
  226. PWRAPERR("WACS_FSM = PMIC_WRAP_WACS_VLDCLR\n");
  227. break;
  228. case WACS_FSM_WFDLE:
  229. PWRAPERR("WACS_FSM = WACS_FSM_WFDLE\n");
  230. break;
  231. case WACS_FSM_REQ:
  232. PWRAPERR("WACS_FSM = WACS_FSM_REQ\n");
  233. break;
  234. default:
  235. break;
  236. }
  237. }while( fp(reg_rdata)); //IDLE State
  238. if(read_reg)
  239. *read_reg=reg_rdata;
  240. return 0;
  241. }
  242. static inline U32 wait_for_state_idle(loop_condition_fp fp,U32 timeout_us,U32 wacs_register,U32 wacs_vldclr_register,U32 *read_reg)
  243. {
  244. U64 start_time_ns=0, timeout_ns=0;
  245. U32 reg_rdata;
  246. start_time_ns = _pwrap_get_current_time();
  247. timeout_ns = _pwrap_time2ns(timeout_us);
  248. do
  249. {
  250. if (_pwrap_timeout_ns(start_time_ns, timeout_ns))
  251. {
  252. PWRAPERR("wait_for_state_idle timeout when waiting for idle\n");
  253. pwrap_dump_ap_register();
  254. // pwrap_trace_wacs2();
  255. // BUG_ON(1);
  256. return E_PWR_WAIT_IDLE_TIMEOUT;
  257. }
  258. reg_rdata = WRAP_RD32(wacs_register);
  259. if( GET_INIT_DONE0( reg_rdata ) != WACS_INIT_DONE)
  260. {
  261. PWRAPERR("initialization isn't finished \n");
  262. return E_PWR_NOT_INIT_DONE;
  263. }
  264. //if last read command timeout,clear vldclr bit
  265. //read command state machine:FSM_REQ-->wfdle-->WFVLDCLR;write:FSM_REQ-->idle
  266. switch ( GET_WACS0_FSM( reg_rdata ) )
  267. {
  268. case WACS_FSM_WFVLDCLR:
  269. WRAP_WR32(wacs_vldclr_register , 1);
  270. PWRAPERR("WACS_FSM = PMIC_WRAP_WACS_VLDCLR\n");
  271. break;
  272. case WACS_FSM_WFDLE:
  273. PWRAPERR("WACS_FSM = WACS_FSM_WFDLE\n");
  274. break;
  275. case WACS_FSM_REQ:
  276. PWRAPERR("WACS_FSM = WACS_FSM_REQ\n");
  277. break;
  278. default:
  279. break;
  280. }
  281. }while( fp(reg_rdata)); //IDLE State
  282. if(read_reg)
  283. *read_reg=reg_rdata;
  284. return 0;
  285. }
  286. static inline U32 wait_for_state_ready(loop_condition_fp fp,U32 timeout_us,U32 wacs_register,U32 *read_reg)
  287. {
  288. U64 start_time_ns=0, timeout_ns=0;
  289. U32 reg_rdata;
  290. start_time_ns = _pwrap_get_current_time();
  291. timeout_ns = _pwrap_time2ns(timeout_us);
  292. do
  293. {
  294. if (_pwrap_timeout_ns(start_time_ns, timeout_ns))
  295. {
  296. PWRAPERR("timeout when waiting for idle\n");
  297. pwrap_dump_ap_register();
  298. return E_PWR_WAIT_IDLE_TIMEOUT;
  299. }
  300. reg_rdata = WRAP_RD32(wacs_register);
  301. if( GET_INIT_DONE0( reg_rdata ) != WACS_INIT_DONE)
  302. {
  303. PWRAPERR("initialization isn't finished \n");
  304. return E_PWR_NOT_INIT_DONE;
  305. }
  306. } while( fp(reg_rdata)); //IDLE State
  307. if(read_reg)
  308. *read_reg=reg_rdata;
  309. return 0;
  310. }
  311. //******************************************************************************
  312. //--external API for pmic_wrap user-------------------------------------------------
  313. //******************************************************************************
  314. S32 pwrap_read( U32 adr, U32 *rdata )
  315. {
  316. return pwrap_wacs2( 0, adr,0,rdata );
  317. }
  318. S32 pwrap_write( U32 adr, U32 wdata )
  319. {
  320. return pwrap_wacs2( 1, adr,wdata,0 );
  321. }
  322. //--------------------------------------------------------
  323. // Function : pwrap_wacs2()
  324. // Description :
  325. // Parameter :
  326. // Return :
  327. //--------------------------------------------------------
  328. S32 pwrap_wacs2( U32 write, U32 adr, U32 wdata, U32 *rdata )
  329. {
  330. //U64 wrap_access_time=0x0;
  331. U32 reg_rdata=0;
  332. U32 wacs_write=0;
  333. U32 wacs_adr=0;
  334. U32 wacs_cmd=0;
  335. U32 return_value=0;
  336. // Check argument validation
  337. if( (write & ~(0x1)) != 0) return E_PWR_INVALID_RW;
  338. if( (adr & ~(0xffff)) != 0) return E_PWR_INVALID_ADDR;
  339. if( (wdata & ~(0xffff)) != 0) return E_PWR_INVALID_WDAT;
  340. // Check IDLE & INIT_DONE in advance
  341. return_value=wait_for_state_idle(wait_for_fsm_idle,TIMEOUT_WAIT_IDLE,PMIC_WRAP_WACS2_RDATA,PMIC_WRAP_WACS2_VLDCLR,0);
  342. if(return_value!=0)
  343. {
  344. PWRAPERR("wait_for_fsm_idle fail,return_value=%d\n",return_value);
  345. goto FAIL;
  346. }
  347. wacs_write = write << 31;
  348. wacs_adr = (adr >> 1) << 16;
  349. wacs_cmd = wacs_write | wacs_adr | wdata;
  350. WRAP_WR32(PMIC_WRAP_WACS2_CMD,wacs_cmd);
  351. if( write == 0 )
  352. {
  353. if (NULL == rdata)
  354. {
  355. PWRAPERR("rdata is a NULL pointer\n");
  356. return_value= E_PWR_INVALID_ARG;
  357. WRAP_WR32(PMIC_WRAP_WACS2_VLDCLR, 1);
  358. goto FAIL;
  359. }
  360. return_value=wait_for_state_ready(wait_for_fsm_vldclr,TIMEOUT_READ,PMIC_WRAP_WACS2_RDATA,&reg_rdata);
  361. if(return_value!=0)
  362. {
  363. PWRAPERR("wait_for_fsm_vldclr fail,return_value=%d\n",return_value);
  364. return_value+=1;//E_PWR_NOT_INIT_DONE_READ or E_PWR_WAIT_IDLE_TIMEOUT_READ
  365. goto FAIL;
  366. }
  367. *rdata = GET_WACS0_RDATA( reg_rdata );
  368. WRAP_WR32(PMIC_WRAP_WACS2_VLDCLR , 1);
  369. }
  370. FAIL:
  371. if(return_value!=0)
  372. {
  373. PWRAPERR("pwrap_wacs2 fail,return_value=%d\n",return_value);
  374. PWRAPERR("timeout:BUG_ON here\n");
  375. //BUG_ON(1);
  376. }
  377. //wrap_access_time=_pwrap_get_current_time();
  378. //pwrap_trace(wrap_access_time,return_value,write, adr, wdata,rdata);
  379. return return_value;
  380. }
  381. //******************************************************************************
  382. //--internal API for pwrap_init-------------------------------------------------
  383. //******************************************************************************
  384. //--------------------------------------------------------
  385. // Function : _pwrap_wacs2_nochk()
  386. // Description :
  387. // Parameter :
  388. // Return :
  389. //--------------------------------------------------------
  390. static S32 pwrap_read_nochk( U32 adr, U32 *rdata )
  391. {
  392. return _pwrap_wacs2_nochk( 0, adr, 0, rdata );
  393. }
  394. static S32 pwrap_write_nochk( U32 adr, U32 wdata )
  395. {
  396. return _pwrap_wacs2_nochk( 1, adr,wdata,0 );
  397. }
  398. static S32 _pwrap_wacs2_nochk( U32 write, U32 adr, U32 wdata, U32 *rdata )
  399. {
  400. U32 reg_rdata=0x0;
  401. U32 wacs_write=0x0;
  402. U32 wacs_adr=0x0;
  403. U32 wacs_cmd=0x0;
  404. U32 return_value=0x0;
  405. //PWRAPFUC();
  406. // Check argument validation
  407. if( (write & ~(0x1)) != 0) return E_PWR_INVALID_RW;
  408. if( (adr & ~(0xffff)) != 0) return E_PWR_INVALID_ADDR;
  409. if( (wdata & ~(0xffff)) != 0) return E_PWR_INVALID_WDAT;
  410. // Check IDLE
  411. return_value=wait_for_state_ready_init(wait_for_fsm_idle,TIMEOUT_WAIT_IDLE,PMIC_WRAP_WACS2_RDATA,0);
  412. if(return_value!=0)
  413. {
  414. PWRAPERR("_pwrap_wacs2_nochk write command fail,return_value=%x\n", return_value);
  415. return return_value;
  416. }
  417. wacs_write = write << 31;
  418. wacs_adr = (adr >> 1) << 16;
  419. wacs_cmd = wacs_write | wacs_adr | wdata;
  420. WRAP_WR32(PMIC_WRAP_WACS2_CMD,wacs_cmd);
  421. if( write == 0 )
  422. {
  423. if (NULL == rdata)
  424. {
  425. PWRAPERR("rdata is a NULL pointer\n");
  426. WRAP_WR32(PMIC_WRAP_WACS2_VLDCLR, 1);
  427. return E_PWR_INVALID_ARG;
  428. }
  429. return_value=wait_for_state_ready_init(wait_for_fsm_vldclr,TIMEOUT_READ,PMIC_WRAP_WACS2_RDATA,&reg_rdata);
  430. if(return_value!=0)
  431. {
  432. PWRAPERR("wait_for_fsm_vldclr fail,return_value=%d\n",return_value);
  433. return_value+=1;//E_PWR_NOT_INIT_DONE_READ or E_PWR_WAIT_IDLE_TIMEOUT_READ
  434. return return_value;
  435. }
  436. *rdata = GET_WACS0_RDATA( reg_rdata );
  437. WRAP_WR32(PMIC_WRAP_WACS2_VLDCLR , 1);
  438. }
  439. return 0;
  440. }
  441. //--------------------------------------------------------
  442. // Function : _pwrap_init_dio()
  443. // Description :call it in pwrap_init,mustn't check init done
  444. // Parameter :
  445. // Return :
  446. //--------------------------------------------------------
  447. static S32 _pwrap_init_dio( U32 dio_en )
  448. {
  449. U32 arb_en_backup=0x0;
  450. U32 rdata=0x0;
  451. U32 return_value=0;
  452. //PWRAPFUC();
  453. arb_en_backup = WRAP_RD32(PMIC_WRAP_HIPRIO_ARB_EN);
  454. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN, WACS2); // only WACS2
  455. #ifdef SLV_6350
  456. pwrap_write_nochk(MT6350_DEW_DIO_EN, dio_en);
  457. #endif
  458. // Check IDLE & INIT_DONE in advance
  459. return_value=wait_for_state_ready_init(wait_for_idle_and_sync,TIMEOUT_WAIT_IDLE,PMIC_WRAP_WACS2_RDATA,0);
  460. if(return_value!=0)
  461. {
  462. PWRAPERR("_pwrap_init_dio fail,return_value=%x\n", return_value);
  463. return return_value;
  464. }
  465. //enable AP DIO mode
  466. WRAP_WR32(PMIC_WRAP_DIO_EN , dio_en);
  467. // Read Test
  468. #ifdef SLV_6350
  469. pwrap_read_nochk(MT6350_DEW_READ_TEST, &rdata);
  470. if( rdata != MT6350_DEFAULT_VALUE_READ_TEST )
  471. {
  472. PWRAPERR("[Dio_mode][Read Test] fail,dio_en = %x, READ_TEST rdata=%x, exp=0x5aa5\n", dio_en, rdata);
  473. return E_PWR_READ_TEST_FAIL;
  474. }
  475. #endif
  476. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN , arb_en_backup);
  477. return 0;
  478. }
  479. //--------------------------------------------------------
  480. // Function : _pwrap_init_cipher()
  481. // Description :
  482. // Parameter :
  483. // Return :
  484. //--------------------------------------------------------
  485. static S32 _pwrap_init_cipher( void )
  486. {
  487. U32 arb_en_backup=0;
  488. U32 rdata=0;
  489. U32 return_value=0;
  490. U32 start_time_ns=0, timeout_ns=0;
  491. //PWRAPFUC();
  492. arb_en_backup = WRAP_RD32(PMIC_WRAP_HIPRIO_ARB_EN);
  493. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN , WACS2); // only WACS0
  494. WRAP_WR32(PMIC_WRAP_CIPHER_SWRST , 1);
  495. WRAP_WR32(PMIC_WRAP_CIPHER_SWRST , 0);
  496. WRAP_WR32(PMIC_WRAP_CIPHER_KEY_SEL , 1);
  497. WRAP_WR32(PMIC_WRAP_CIPHER_IV_SEL , 2);
  498. WRAP_WR32(PMIC_WRAP_CIPHER_EN , 1);
  499. //Config CIPHER @ PMIC
  500. #ifdef SLV_6350
  501. pwrap_write_nochk(MT6350_DEW_CIPHER_SWRST, 0x1);
  502. pwrap_write_nochk(MT6350_DEW_CIPHER_SWRST, 0x0);
  503. pwrap_write_nochk(MT6350_DEW_CIPHER_KEY_SEL, 0x1);
  504. pwrap_write_nochk(MT6350_DEW_CIPHER_IV_SEL, 0x2);
  505. pwrap_write_nochk(MT6350_DEW_CIPHER_EN, 0x1);
  506. #endif
  507. //wait for cipher data ready@AP
  508. return_value=wait_for_state_ready_init(wait_for_cipher_ready,TIMEOUT_WAIT_IDLE,PMIC_WRAP_CIPHER_RDY,0);
  509. if(return_value!=0)
  510. {
  511. PWRAPERR("wait for cipher data ready@AP fail,return_value=%x\n", return_value);
  512. return return_value;
  513. }
  514. //wait for cipher data ready@PMIC
  515. #ifdef SLV_6350
  516. start_time_ns = _pwrap_get_current_time();
  517. timeout_ns = _pwrap_time2ns(0xFFFFFF);
  518. do
  519. {
  520. if (_pwrap_timeout_ns(start_time_ns, timeout_ns))
  521. {
  522. PWRAPERR("wait for cipher data ready@PMIC\n");
  523. }
  524. pwrap_read_nochk(MT6350_DEW_CIPHER_RDY,&rdata);
  525. } while( rdata != 0x1 ); //cipher_ready
  526. pwrap_write_nochk(MT6350_DEW_CIPHER_MODE, 0x1);
  527. #endif
  528. //wait for cipher mode idle
  529. return_value=wait_for_state_ready_init(wait_for_idle_and_sync,TIMEOUT_WAIT_IDLE,PMIC_WRAP_WACS2_RDATA,0);
  530. if(return_value!=0)
  531. {
  532. PWRAPERR("wait for cipher mode idle fail,return_value=%x\n", return_value);
  533. return return_value;
  534. }
  535. WRAP_WR32(PMIC_WRAP_CIPHER_MODE , 1);
  536. // Read Test
  537. #ifdef SLV_6350
  538. pwrap_read_nochk(MT6350_DEW_READ_TEST, &rdata);
  539. if( rdata != MT6350_DEFAULT_VALUE_READ_TEST )
  540. {
  541. PWRAPERR("_pwrap_init_cipher,read test error,error code=%x, rdata=%x\n", 1, rdata);
  542. return E_PWR_READ_TEST_FAIL;
  543. }
  544. #endif
  545. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN , arb_en_backup);
  546. return 0;
  547. }
  548. //--------------------------------------------------------
  549. // Function : _pwrap_init_sistrobe()
  550. // Description : Initialize SI_CK_CON and SIDLY
  551. // Parameter :
  552. // Return :
  553. //--------------------------------------------------------
  554. static S32 _pwrap_init_sistrobe( void )
  555. {
  556. U32 arb_en_backup=0;
  557. U32 rdata=0;
  558. U32 i=0;
  559. S32 ind=0;
  560. U32 tmp1=0;
  561. U32 tmp2=0;
  562. U32 result_faulty=0;
  563. U32 result[2]={0,0};
  564. S32 leading_one[2]={-1,-1};
  565. S32 tailing_one[2]={-1,-1};
  566. arb_en_backup = WRAP_RD32(PMIC_WRAP_HIPRIO_ARB_EN);
  567. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN ,WACS2); // only WACS2
  568. //---------------------------------------------------------------------
  569. // Scan all possible input strobe by READ_TEST
  570. //---------------------------------------------------------------------
  571. for( ind=0; ind<24; ind++) // 24 sampling clock edge
  572. {
  573. WRAP_WR32(PMIC_WRAP_SI_CK_CON , (ind >> 2) & 0x7);
  574. WRAP_WR32(PMIC_WRAP_SIDLY ,0x3 - (ind & 0x3));
  575. #ifdef SLV_6350
  576. _pwrap_wacs2_nochk(0, MT6350_DEW_READ_TEST, 0, &rdata);
  577. if( rdata == MT6350_DEFAULT_VALUE_READ_TEST ) {
  578. PWRAPLOG("_pwrap_init_sistrobe [Read Test of MT6350] pass,index=%d rdata=%x\n", ind,rdata);
  579. result[0] |= (0x1 << ind);
  580. }else {
  581. PWRAPLOG("_pwrap_init_sistrobe [Read Test of MT6350] tuning,index=%d rdata=%x\n", ind,rdata);
  582. }
  583. #endif
  584. }
  585. #ifndef SLV_6350
  586. result[0] = result[1];
  587. #endif
  588. #ifndef SLV_6332
  589. result[1] = result[0];
  590. #endif
  591. //---------------------------------------------------------------------
  592. // Locate the leading one and trailing one of PMIC 1/2
  593. //---------------------------------------------------------------------
  594. for( ind=23 ; ind>=0 ; ind-- )
  595. {
  596. if( (result[0] & (0x1 << ind)) && leading_one[0] == -1){
  597. leading_one[0] = ind;
  598. }
  599. if(leading_one[0] > 0) { break;}
  600. }
  601. for( ind=23 ; ind>=0 ; ind-- )
  602. {
  603. if( (result[1] & (0x1 << ind)) && leading_one[1] == -1){
  604. leading_one[1] = ind;
  605. }
  606. if(leading_one[1] > 0) { break;}
  607. }
  608. for( ind=0 ; ind<24 ; ind++ )
  609. {
  610. if( (result[0] & (0x1 << ind)) && tailing_one[0] == -1){
  611. tailing_one[0] = ind;
  612. }
  613. if(tailing_one[0] > 0) { break;}
  614. }
  615. for( ind=0 ; ind<24 ; ind++ )
  616. {
  617. if( (result[1] & (0x1 << ind)) && tailing_one[1] == -1){
  618. tailing_one[1] = ind;
  619. }
  620. if(tailing_one[1] > 0) { break;}
  621. }
  622. //---------------------------------------------------------------------
  623. // Check the continuity of pass range
  624. //---------------------------------------------------------------------
  625. for( i=0; i<2; i++)
  626. {
  627. tmp1 = (0x1 << (leading_one[i]+1)) - 1;
  628. tmp2 = (0x1 << tailing_one[i]) - 1;
  629. if( (tmp1 - tmp2) != result[i] )
  630. {
  631. /*TERR = "[DrvPWRAP_InitSiStrobe] Fail at PMIC %d, result = %x, leading_one:%d, tailing_one:%d"
  632. , i+1, result[i], leading_one[i], tailing_one[i]*/
  633. PWRAPERR("_pwrap_init_sistrobe Fail at PMIC %d, result = %x, leading_one:%d, tailing_one:%d\n", i+1, result[i], leading_one[i], tailing_one[i]);
  634. result_faulty = 0x1;
  635. }
  636. }
  637. //---------------------------------------------------------------------
  638. // Config SICK and SIDLY to the middle point of pass range
  639. //---------------------------------------------------------------------
  640. if( result_faulty == 0 )
  641. {
  642. // choose the best point in the interaction of PMIC1's pass range and PMIC2's pass range
  643. ind = ( (leading_one[0] + tailing_one[0])/2 + (leading_one[1] + tailing_one[1])/2 )/2;
  644. /*TINFO = "The best point in the interaction area is %d, ind"*/
  645. WRAP_WR32(PMIC_WRAP_SI_CK_CON , (ind >> 2) & 0x7);
  646. WRAP_WR32(PMIC_WRAP_SIDLY , 0x3 - (ind & 0x3));
  647. //---------------------------------------------------------------------
  648. // Restore
  649. //---------------------------------------------------------------------
  650. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN , arb_en_backup);
  651. return 0;
  652. }
  653. else
  654. {
  655. PWRAPERR("_pwrap_init_sistrobe Fail,result_faulty=%x\n", result_faulty);
  656. return result_faulty;
  657. }
  658. }
  659. //--------------------------------------------------------
  660. // Function : _pwrap_reset_spislv()
  661. // Description :
  662. // Parameter :
  663. // Return :
  664. //--------------------------------------------------------
  665. static S32 _pwrap_reset_spislv( void )
  666. {
  667. U32 ret=0;
  668. U32 return_value=0;
  669. //PWRAPFUC();
  670. // This driver does not using _pwrap_switch_mux
  671. // because the remaining requests are expected to fail anyway
  672. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN , DISABLE_ALL);
  673. WRAP_WR32(PMIC_WRAP_WRAP_EN , DISABLE);
  674. WRAP_WR32(PMIC_WRAP_MUX_SEL , MANUAL_MODE);
  675. WRAP_WR32(PMIC_WRAP_MAN_EN ,ENABLE);
  676. WRAP_WR32(PMIC_WRAP_DIO_EN ,DISABLE);
  677. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_CSL << 8));//0x2100
  678. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_OUTS << 8)); //0x2800//to reset counter
  679. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_CSH << 8));//0x2000
  680. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_OUTS << 8));
  681. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_OUTS << 8));
  682. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_OUTS << 8));
  683. WRAP_WR32(PMIC_WRAP_MAN_CMD , (OP_WR << 13) | (OP_OUTS << 8));
  684. return_value=wait_for_state_ready_init(wait_for_sync,TIMEOUT_WAIT_IDLE,PMIC_WRAP_WACS2_RDATA,0);
  685. if(return_value!=0)
  686. {
  687. PWRAPERR("_pwrap_reset_spislv fail,return_value=%x\n", return_value);
  688. ret=E_PWR_TIMEOUT;
  689. goto timeout;
  690. }
  691. WRAP_WR32(PMIC_WRAP_MAN_EN ,DISABLE);
  692. WRAP_WR32(PMIC_WRAP_MUX_SEL ,WRAPPER_MODE);
  693. timeout:
  694. WRAP_WR32(PMIC_WRAP_MAN_EN, DISABLE);
  695. WRAP_WR32(PMIC_WRAP_MUX_SEL, WRAPPER_MODE);
  696. return ret;
  697. }
  698. static void __pwrap_soft_reset(void)
  699. {
  700. PWRAPLOG("start reset wrapper\n");
  701. PWRAP_SOFT_RESET;
  702. PWRAPLOG("the reset register =%x\n",WRAP_RD32(INFRA_GLOBALCON_RST0));
  703. PWRAPLOG("PMIC_WRAP_STAUPD_GRPEN =0x%x,it should be equal to 0xc\n",WRAP_RD32(PMIC_WRAP_STAUPD_GRPEN));
  704. //clear reset bit
  705. PWRAP_CLEAR_SOFT_RESET_BIT;
  706. return;
  707. }
  708. static S32 _pwrap_init_reg_clock( U32 regck_sel )
  709. {
  710. U32 wdata=0;
  711. U32 rdata=0;
  712. PWRAPFUC();
  713. if(regck_sel == 1) // not supported in 6323!!
  714. return E_PWR_INIT_REG_CLOCK;
  715. else
  716. wdata = 0x3;
  717. pwrap_write_nochk(MT6350_TOP_CKCON1_CLR, wdata);
  718. pwrap_read_nochk(MT6350_TOP_CKCON1, &rdata);
  719. #if defined SLV_6350
  720. if( (rdata & 0x3) != 0)
  721. {
  722. PWRAPERR("_pwrap_init_reg_clock,MT6350_TOP_CKCON1 Write [15]=1 Fail, rdata=%x\n",rdata);
  723. return E_PWR_WRITE_TEST_FAIL;
  724. }
  725. pwrap_write_nochk(MT6350_DEW_RDDMY_NO, 0x8);
  726. WRAP_WR32(PMIC_WRAP_RDDMY ,0x8);
  727. #endif
  728. // Config SPI Waveform according to reg clk
  729. if( regck_sel == 1 ) { // 6MHz in 6323 => no support ; 18MHz in 6320
  730. WRAP_WR32(PMIC_WRAP_CSHEXT_WRITE , 0x4);
  731. WRAP_WR32(PMIC_WRAP_CSHEXT_READ , 0x5); // wait data written into register => 3T_PMIC: consists of CSLEXT_END(1T) + CSHEXT(6T)
  732. WRAP_WR32(PMIC_WRAP_CSLEXT_START , 0x0);
  733. WRAP_WR32(PMIC_WRAP_CSLEXT_END , 0x0);
  734. }else if(regck_sel == 2 )
  735. { // 12MHz in 6323; 36MHz in 6320
  736. #if defined SLV_6350
  737. WRAP_WR32(PMIC_WRAP_CSHEXT_READ, 0x0);
  738. WRAP_WR32(PMIC_WRAP_CSHEXT_WRITE, 0x7); // wait data written into register => 3T_PMIC: consists of CSLEXT_END(1T) + CSHEXT(6T)
  739. #endif
  740. WRAP_WR32(PMIC_WRAP_CSLEXT_START , 0x0);
  741. WRAP_WR32(PMIC_WRAP_CSLEXT_END , 0x0);
  742. }
  743. else { //Safe mode
  744. WRAP_WR32(PMIC_WRAP_CSHEXT_WRITE , 0xf);
  745. WRAP_WR32(PMIC_WRAP_CSHEXT_READ , 0xf);
  746. WRAP_WR32(PMIC_WRAP_CSLEXT_START , 0xf);
  747. WRAP_WR32(PMIC_WRAP_CSLEXT_END , 0xf);
  748. }
  749. return 0;
  750. }
  751. /*
  752. * pmic_wrap init,init wrap interface
  753. */
  754. S32 pwrap_init(void)
  755. {
  756. S32 sub_return=0;
  757. S32 sub_return1=0;
  758. U32 clk_sel = 0;
  759. //S32 ret=0;
  760. U32 rdata=0x0;
  761. //U32 timeout=0;
  762. u32 cg_mask = 0;
  763. u32 backup = 0;
  764. PWRAPFUC();
  765. //###############################
  766. //toggle PMIC_WRAP and pwrap_spictl reset
  767. //###############################
  768. // WRAP_SET_BIT(0x80,INFRA_GLOBALCON_RST0);
  769. // WRAP_CLR_BIT(0x80,INFRA_GLOBALCON_RST0);
  770. //__pwrap_soft_reset();
  771. /* Turn off module clock */
  772. cg_mask = ((1 << 20) | (1 << 27) | (1 << 28) | (1 << 29));
  773. backup = (~WRAP_RD32(CLK_SWCG_1)) & cg_mask;
  774. WRAP_WR32(CLK_SETCG_1, cg_mask);
  775. /* dummy read to add latency (to wait clock turning off) */
  776. rdata = WRAP_RD32(PMIC_WRAP_SWRST);
  777. /* Toggle module reset */
  778. WRAP_WR32(PMIC_WRAP_SWRST, ENABLE);
  779. rdata = WRAP_RD32(WDT_FAST_SWSYSRST);
  780. WRAP_WR32(WDT_FAST_SWSYSRST, (rdata | (0x1 << 11)) | (0x88 << 24));
  781. WRAP_WR32(WDT_FAST_SWSYSRST, (rdata & (~(0x1 << 11))) | (0x88 << 24));
  782. WRAP_WR32(PMIC_WRAP_SWRST, DISABLE);
  783. /* Turn on module clock */
  784. WRAP_WR32(CLK_CLRCG_1, backup | (1 << 20)); // ensure cg for AP is off;
  785. /* Turn on module clock dcm (in global_con) */
  786. // WHQA_00014186: set PMIC bclk DCM default off due to HW issue
  787. WRAP_WR32(CLK_SETCG_3, (1 << 2) | (1 << 1));
  788. // WRAP_WR32(CLK_SETCG_3, (1 << 2));
  789. //###############################
  790. // Set SPI_CK_freq = 26MHz
  791. //###############################
  792. #ifndef CONFIG_MTK_FPGA
  793. clk_sel = WRAP_RD32(CLK_SEL_0);
  794. WRAP_WR32(CLK_SEL_0, clk_sel | (0x3 << 24));
  795. #endif
  796. //###############################
  797. //Enable DCM
  798. //###############################
  799. WRAP_WR32(PMIC_WRAP_DCM_EN, 1);//enable CRC DCM and PMIC_WRAP DCM
  800. WRAP_WR32(PMIC_WRAP_DCM_DBC_PRD, DISABLE); //no debounce
  801. //###############################
  802. //Reset SPISLV
  803. //###############################
  804. sub_return=_pwrap_reset_spislv();
  805. if( sub_return != 0 )
  806. {
  807. PWRAPERR("error,_pwrap_reset_spislv fail,sub_return=%x\n",sub_return);
  808. return E_PWR_INIT_RESET_SPI;
  809. }
  810. //###############################
  811. // Enable WACS2
  812. //###############################
  813. WRAP_WR32(PMIC_WRAP_WRAP_EN, ENABLE);//enable wrap
  814. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN, WACS2); //Only WACS2
  815. WRAP_WR32(PMIC_WRAP_WACS2_EN, ENABLE);
  816. //###############################
  817. // Set Dummy cycle to make the cycle is the same at both AP and PMIC sides
  818. //###############################
  819. // (default value of 6320 dummy cycle is already 0x8)
  820. #ifdef SLV_6350
  821. WRAP_WR32(PMIC_WRAP_RDDMY , 0xF);
  822. #endif
  823. //###############################
  824. // Input data calibration flow;
  825. //###############################
  826. sub_return = _pwrap_init_sistrobe();
  827. if( sub_return != 0 )
  828. {
  829. PWRAPERR("error,DrvPWRAP_InitSiStrobe fail,sub_return=%x\n",sub_return);
  830. return E_PWR_INIT_SIDLY;
  831. }
  832. //###############################
  833. // SPI Waveform Configuration
  834. //###############################
  835. //0:safe mode, 1:18MHz
  836. sub_return = _pwrap_init_reg_clock(2);
  837. if( sub_return != 0)
  838. {
  839. PWRAPERR("error,_pwrap_init_reg_clock fail,sub_return=%x\n",sub_return);
  840. return E_PWR_INIT_REG_CLOCK;
  841. }
  842. //###############################
  843. // Enable DIO mode
  844. //###############################
  845. //PMIC2 dual io not ready
  846. sub_return = _pwrap_init_dio(1);
  847. if( sub_return != 0 )
  848. {
  849. PWRAPERR("_pwrap_init_dio test error,error code=%x, sub_return=%x\n", 0x11, sub_return);
  850. return E_PWR_INIT_DIO;
  851. }
  852. //###############################
  853. // Enable Encryption
  854. //###############################
  855. sub_return = _pwrap_init_cipher();
  856. if( sub_return != 0 )
  857. {
  858. PWRAPERR("Enable Encryption fail, return=%x\n", sub_return);
  859. return E_PWR_INIT_CIPHER;
  860. }
  861. //###############################
  862. // Write test using WACS2
  863. //###############################
  864. //check Wtiet test default value
  865. #ifdef SLV_6350
  866. sub_return = pwrap_write_nochk(MT6350_DEW_WRITE_TEST, MT6350_WRITE_TEST_VALUE);
  867. sub_return1 = pwrap_read_nochk(MT6350_DEW_WRITE_TEST, &rdata);
  868. if( rdata != MT6350_WRITE_TEST_VALUE ) {
  869. PWRAPERR("write test error,rdata=0x%x,exp=0xa55a,sub_return=0x%x,sub_return1=0x%x\n", rdata,sub_return,sub_return1);
  870. return E_PWR_INIT_WRITE_TEST;
  871. }
  872. #endif
  873. //###############################
  874. // Signature Checking - Using CRC
  875. // should be the last to modify WRITE_TEST
  876. //###############################
  877. sub_return = pwrap_write_nochk(MT6350_DEW_CRC_EN, ENABLE);
  878. if( sub_return != 0 )
  879. {
  880. PWRAPERR("Enable CRC fail, return=%x\n", sub_return);
  881. return E_PWR_INIT_ENABLE_CRC;
  882. }
  883. WRAP_WR32(PMIC_WRAP_CRC_EN, ENABLE);
  884. WRAP_WR32(PMIC_WRAP_SIG_MODE, CHECK_CRC);
  885. WRAP_WR32(PMIC_WRAP_SIG_ADR, MT6350_DEW_CRC_VAL);
  886. //###############################
  887. // PMIC_WRAP enables
  888. //###############################
  889. WRAP_WR32(PMIC_WRAP_HIPRIO_ARB_EN, 0x1ff);
  890. WRAP_WR32(PMIC_WRAP_WACS0_EN,ENABLE);
  891. WRAP_WR32(PMIC_WRAP_WACS1_EN,ENABLE);
  892. WRAP_WR32(PMIC_WRAP_STAUPD_PRD, 0x5); //0x1:20us,for concurrence test,MP:0x5; //100us
  893. WRAP_WR32(PMIC_WRAP_STAUPD_GRPEN, 0xff);
  894. WRAP_WR32(PMIC_WRAP_WDT_UNIT,0xf);
  895. WRAP_WR32(PMIC_WRAP_WDT_SRC_EN,0xffffffff);
  896. WRAP_WR32(PMIC_WRAP_TIMER_EN,0x1);
  897. WRAP_WR32(PMIC_WRAP_INT_EN, 0x7ffffffd);
  898. //###############################
  899. // GPS Initialization
  900. // set address of ready bit register and thermal data register
  901. //###############################
  902. WRAP_WR32(PMIC_WRAP_ADC_CMD_ADDR, MT6350_AUXADC_CON21);
  903. WRAP_WR32(PMIC_WRAP_PWRAP_ADC_CMD, 0x8000);
  904. WRAP_WR32(PMIC_WRAP_ADC_RDY_ADDR, MT6350_AUXADC_ADC12);
  905. WRAP_WR32(PMIC_WRAP_ADC_RDATA_ADDR1, MT6350_AUXADC_ADC13);
  906. WRAP_WR32(PMIC_WRAP_ADC_RDATA_ADDR2, MT6350_AUXADC_ADC14);
  907. //###############################
  908. // Initialization Done
  909. //###############################
  910. WRAP_WR32(PMIC_WRAP_INIT_DONE2 , ENABLE);
  911. //###############################
  912. //TBD: Should be configured by MD MCU
  913. //###############################
  914. WRAP_WR32(PMIC_WRAP_INIT_DONE0 ,ENABLE);
  915. WRAP_WR32(PMIC_WRAP_INIT_DONE1 , ENABLE);
  916. return 0;
  917. }
  918. /*-pwrap debug--------------------------------------------------------------------------*/
  919. void pwrap_dump_ap_register(void)
  920. {
  921. U32 i = 0;
  922. PWRAPREG("address : 3 2 1 0 7 6 5 4 B A 9 8 F E D C \n");
  923. for (i = 0; i <= PMIC_WRAP_REG_RANGE; i += 4)
  924. {
  925. PWRAPREG("offset 0x%.3x:0x%.8x 0x%.8x 0x%.8x 0x%.8x \n",i * 4,
  926. WRAP_RD32(PMIC_WRAP_BASE + (i * 4) + 0),
  927. WRAP_RD32(PMIC_WRAP_BASE + (i * 4) + 0x4),
  928. WRAP_RD32(PMIC_WRAP_BASE + (i * 4) + 0x8),
  929. WRAP_RD32(PMIC_WRAP_BASE + (i * 4) + 0xC));
  930. }
  931. //PWRAPREG("elapse_time=%llx(ns)\n",elapse_time);
  932. }
  933. static inline void pwrap_dump_pmic_register(void)
  934. {
  935. #if 0
  936. U32 i=0;
  937. U32 reg_addr=0;
  938. U32 reg_value=0;
  939. PWRAPREG("dump dewrap register\n");
  940. for(i=0;i<=14;i++)
  941. {
  942. reg_addr=(DEW_BASE+i*4);
  943. reg_value=pwrap_read_nochk(reg_addr,&reg_value);
  944. PWRAPREG("0x%x=0x%x\n",reg_addr,reg_value);
  945. }
  946. #endif
  947. return;
  948. }
  949. static inline void pwrap_dump_all_register(void)
  950. {
  951. pwrap_dump_ap_register();
  952. pwrap_dump_pmic_register();
  953. return;
  954. }
  955. //#ifdef MACH_FPGA
  956. S32 pwrap_init_lk ( void )
  957. {
  958. u32 pwrap_ret=0,i=0;
  959. PWRAPFUC();
  960. for(i=0;i<3;i++)
  961. {
  962. pwrap_ret = pwrap_init();
  963. if(pwrap_ret!=0)
  964. {
  965. dprintf(CRITICAL,"[PMIC_WRAP]wrap_init fail,the return value=%x.\n",pwrap_ret);
  966. }
  967. else
  968. {
  969. dprintf(CRITICAL,"[PMIC_WRAP]wrap_init pass,the return value=%x.\n",pwrap_ret);
  970. break;//init pass
  971. }
  972. }
  973. return 0;
  974. }
  975. //--------------------------------------------------------
  976. // Function : _pwrap_status_update_test()
  977. // Description :only for early porting
  978. // Parameter :
  979. // Return :
  980. //--------------------------------------------------------
  981. static S32 _pwrap_status_update_test_porting( void )
  982. {
  983. //U32 i, j;
  984. U32 rdata;
  985. volatile U32 delay=1000*1000*1;
  986. PWRAPFUC();
  987. //disable signature interrupt
  988. WRAP_WR32(PMIC_WRAP_INT_EN,0x0);
  989. #ifdef SLV_6350
  990. pwrap_write(MT6350_DEW_WRITE_TEST, MT6350_WRITE_TEST_VALUE);
  991. WRAP_WR32(PMIC_WRAP_SIG_ADR,MT6350_DEW_WRITE_TEST);
  992. WRAP_WR32(PMIC_WRAP_SIG_VALUE,0xAA55);
  993. #endif
  994. WRAP_WR32(PMIC_WRAP_SIG_MODE, 0x1);
  995. while(delay--);
  996. rdata=WRAP_RD32(PMIC_WRAP_SIG_ERRVAL);
  997. #ifdef SLV_6350
  998. if( (rdata&0xFFFF) != MT6350_WRITE_TEST_VALUE )
  999. {
  1000. PWRAPERR("MT6350 _pwrap_status_update_test error,error code=%x, rdata=%x\n", 1, (rdata&0xFFFF));
  1001. //return 1;
  1002. }
  1003. #endif
  1004. #ifdef SLV_6350
  1005. WRAP_WR32(PMIC_WRAP_SIG_VALUE,MT6350_WRITE_TEST_VALUE);//tha same as write test
  1006. #endif
  1007. //clear sig_error interrupt flag bit
  1008. WRAP_WR32(PMIC_WRAP_INT_CLR,1<<1);
  1009. //enable signature interrupt
  1010. WRAP_WR32(PMIC_WRAP_INT_EN,0x7ffffff9);
  1011. WRAP_WR32(PMIC_WRAP_SIG_MODE, 0x0);
  1012. #ifdef SLV_6350
  1013. WRAP_WR32(PMIC_WRAP_SIG_ADR, MT6350_DEW_CRC_VAL);
  1014. #endif
  1015. return 0;
  1016. }
  1017. void pwrap_init_for_early_porting(void)
  1018. {
  1019. int ret = 0;
  1020. U32 res=0;
  1021. PWRAPFUC();
  1022. ret=_pwrap_status_update_test_porting();
  1023. if(ret==0)
  1024. {
  1025. PWRAPLOG("wrapper_StatusUpdateTest pass.\n");
  1026. }
  1027. else
  1028. {
  1029. PWRAPLOG("error:wrapper_StatusUpdateTest fail.\n");
  1030. res+=1;
  1031. }
  1032. }
  1033. //#endif
  1034. #endif //endif PMIC_WRAP_NO_PMIC