chipcHw_inline.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. /*****************************************************************************
  2. * Copyright 2003 - 2008 Broadcom Corporation. All rights reserved.
  3. *
  4. * Unless you and Broadcom execute a separate written software license
  5. * agreement governing use of this software, this software is licensed to you
  6. * under the terms of the GNU General Public License version 2, available at
  7. * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8. *
  9. * Notwithstanding the above, under no circumstances may you combine this
  10. * software in any way with any other Broadcom software provided under a
  11. * license other than the GPL, without Broadcom's express prior written
  12. * consent.
  13. *****************************************************************************/
  14. #ifndef CHIPC_INLINE_H
  15. #define CHIPC_INLINE_H
  16. /* ---- Include Files ----------------------------------------------------- */
  17. #include <csp/errno.h>
  18. #include <csp/reg.h>
  19. #include <mach/csp/chipcHw_reg.h>
  20. #include <mach/csp/chipcHw_def.h>
  21. /* ---- Private Constants and Types --------------------------------------- */
  22. typedef enum {
  23. chipcHw_OPTYPE_BYPASS, /* Bypass operation */
  24. chipcHw_OPTYPE_OUTPUT /* Output operation */
  25. } chipcHw_OPTYPE_e;
  26. /* ---- Public Constants and Types ---------------------------------------- */
  27. /* ---- Public Variable Externs ------------------------------------------- */
  28. /* ---- Public Function Prototypes ---------------------------------------- */
  29. /* ---- Private Function Prototypes --------------------------------------- */
  30. static inline void chipcHw_setClock(chipcHw_CLOCK_e clock,
  31. chipcHw_OPTYPE_e type, int mode);
  32. /****************************************************************************/
  33. /**
  34. * @brief Get Numeric Chip ID
  35. *
  36. * This function returns Chip ID that includes the revison number
  37. *
  38. * @return Complete numeric Chip ID
  39. *
  40. */
  41. /****************************************************************************/
  42. static inline uint32_t chipcHw_getChipId(void)
  43. {
  44. return pChipcHw->ChipId;
  45. }
  46. /****************************************************************************/
  47. /**
  48. * @brief Enable Spread Spectrum
  49. *
  50. * @note chipcHw_Init() must be called earlier
  51. */
  52. /****************************************************************************/
  53. static inline void chipcHw_enableSpreadSpectrum(void)
  54. {
  55. if ((pChipcHw->
  56. PLLPreDivider & chipcHw_REG_PLL_PREDIVIDER_NDIV_MODE_MASK) !=
  57. chipcHw_REG_PLL_PREDIVIDER_NDIV_MODE_INTEGER) {
  58. ddrcReg_PHY_ADDR_CTL_REGP->ssCfg =
  59. (0xFFFF << ddrcReg_PHY_ADDR_SS_CFG_NDIV_AMPLITUDE_SHIFT) |
  60. (ddrcReg_PHY_ADDR_SS_CFG_MIN_CYCLE_PER_TICK <<
  61. ddrcReg_PHY_ADDR_SS_CFG_CYCLE_PER_TICK_SHIFT);
  62. ddrcReg_PHY_ADDR_CTL_REGP->ssCtl |=
  63. ddrcReg_PHY_ADDR_SS_CTRL_ENABLE;
  64. }
  65. }
  66. /****************************************************************************/
  67. /**
  68. * @brief Disable Spread Spectrum
  69. *
  70. */
  71. /****************************************************************************/
  72. static inline void chipcHw_disableSpreadSpectrum(void)
  73. {
  74. ddrcReg_PHY_ADDR_CTL_REGP->ssCtl &= ~ddrcReg_PHY_ADDR_SS_CTRL_ENABLE;
  75. }
  76. /****************************************************************************/
  77. /**
  78. * @brief Get Chip Product ID
  79. *
  80. * This function returns Chip Product ID
  81. *
  82. * @return Chip Product ID
  83. */
  84. /****************************************************************************/
  85. static inline uint32_t chipcHw_getChipProductId(void)
  86. {
  87. return (pChipcHw->
  88. ChipId & chipcHw_REG_CHIPID_BASE_MASK) >>
  89. chipcHw_REG_CHIPID_BASE_SHIFT;
  90. }
  91. /****************************************************************************/
  92. /**
  93. * @brief Get revision number
  94. *
  95. * This function returns revision number of the chip
  96. *
  97. * @return Revision number
  98. */
  99. /****************************************************************************/
  100. static inline chipcHw_REV_NUMBER_e chipcHw_getChipRevisionNumber(void)
  101. {
  102. return pChipcHw->ChipId & chipcHw_REG_CHIPID_REV_MASK;
  103. }
  104. /****************************************************************************/
  105. /**
  106. * @brief Enables bus interface clock
  107. *
  108. * Enables bus interface clock of various device
  109. *
  110. * @return void
  111. *
  112. * @note use chipcHw_REG_BUS_CLOCK_XXXX for mask
  113. */
  114. /****************************************************************************/
  115. static inline void chipcHw_busInterfaceClockEnable(uint32_t mask)
  116. {
  117. reg32_modify_or(&pChipcHw->BusIntfClock, mask);
  118. }
  119. /****************************************************************************/
  120. /**
  121. * @brief Disables bus interface clock
  122. *
  123. * Disables bus interface clock of various device
  124. *
  125. * @return void
  126. *
  127. * @note use chipcHw_REG_BUS_CLOCK_XXXX
  128. */
  129. /****************************************************************************/
  130. static inline void chipcHw_busInterfaceClockDisable(uint32_t mask)
  131. {
  132. reg32_modify_and(&pChipcHw->BusIntfClock, ~mask);
  133. }
  134. /****************************************************************************/
  135. /**
  136. * @brief Get status (enabled/disabled) of bus interface clock
  137. *
  138. * This function returns the status of devices' bus interface clock
  139. *
  140. * @return Bus interface clock
  141. *
  142. */
  143. /****************************************************************************/
  144. static inline uint32_t chipcHw_getBusInterfaceClockStatus(void)
  145. {
  146. return pChipcHw->BusIntfClock;
  147. }
  148. /****************************************************************************/
  149. /**
  150. * @brief Enables various audio channels
  151. *
  152. * Enables audio channel
  153. *
  154. * @return void
  155. *
  156. * @note use chipcHw_REG_AUDIO_CHANNEL_XXXXXX
  157. */
  158. /****************************************************************************/
  159. static inline void chipcHw_audioChannelEnable(uint32_t mask)
  160. {
  161. reg32_modify_or(&pChipcHw->AudioEnable, mask);
  162. }
  163. /****************************************************************************/
  164. /**
  165. * @brief Disables various audio channels
  166. *
  167. * Disables audio channel
  168. *
  169. * @return void
  170. *
  171. * @note use chipcHw_REG_AUDIO_CHANNEL_XXXXXX
  172. */
  173. /****************************************************************************/
  174. static inline void chipcHw_audioChannelDisable(uint32_t mask)
  175. {
  176. reg32_modify_and(&pChipcHw->AudioEnable, ~mask);
  177. }
  178. /****************************************************************************/
  179. /**
  180. * @brief Soft resets devices
  181. *
  182. * Soft resets various devices
  183. *
  184. * @return void
  185. *
  186. * @note use chipcHw_REG_SOFT_RESET_XXXXXX defines
  187. */
  188. /****************************************************************************/
  189. static inline void chipcHw_softReset(uint64_t mask)
  190. {
  191. chipcHw_softResetEnable(mask);
  192. chipcHw_softResetDisable(mask);
  193. }
  194. static inline void chipcHw_softResetDisable(uint64_t mask)
  195. {
  196. uint32_t ctrl1 = (uint32_t) mask;
  197. uint32_t ctrl2 = (uint32_t) (mask >> 32);
  198. /* Deassert module soft reset */
  199. REG_LOCAL_IRQ_SAVE;
  200. pChipcHw->SoftReset1 ^= ctrl1;
  201. pChipcHw->SoftReset2 ^= (ctrl2 & (~chipcHw_REG_SOFT_RESET_UNHOLD_MASK));
  202. REG_LOCAL_IRQ_RESTORE;
  203. }
  204. static inline void chipcHw_softResetEnable(uint64_t mask)
  205. {
  206. uint32_t ctrl1 = (uint32_t) mask;
  207. uint32_t ctrl2 = (uint32_t) (mask >> 32);
  208. uint32_t unhold = 0;
  209. REG_LOCAL_IRQ_SAVE;
  210. pChipcHw->SoftReset1 |= ctrl1;
  211. /* Mask out unhold request bits */
  212. pChipcHw->SoftReset2 |= (ctrl2 & (~chipcHw_REG_SOFT_RESET_UNHOLD_MASK));
  213. /* Process unhold requests */
  214. if (ctrl2 & chipcHw_REG_SOFT_RESET_VPM_GLOBAL_UNHOLD) {
  215. unhold = chipcHw_REG_SOFT_RESET_VPM_GLOBAL_HOLD;
  216. }
  217. if (ctrl2 & chipcHw_REG_SOFT_RESET_VPM_UNHOLD) {
  218. unhold |= chipcHw_REG_SOFT_RESET_VPM_HOLD;
  219. }
  220. if (ctrl2 & chipcHw_REG_SOFT_RESET_ARM_UNHOLD) {
  221. unhold |= chipcHw_REG_SOFT_RESET_ARM_HOLD;
  222. }
  223. if (unhold) {
  224. /* Make sure unhold request is effective */
  225. pChipcHw->SoftReset1 &= ~unhold;
  226. }
  227. REG_LOCAL_IRQ_RESTORE;
  228. }
  229. /****************************************************************************/
  230. /**
  231. * @brief Configures misc CHIP functionality
  232. *
  233. * Configures CHIP functionality
  234. *
  235. * @return void
  236. *
  237. * @note use chipcHw_REG_MISC_CTRL_XXXXXX
  238. */
  239. /****************************************************************************/
  240. static inline void chipcHw_miscControl(uint32_t mask)
  241. {
  242. reg32_write(&pChipcHw->MiscCtrl, mask);
  243. }
  244. static inline void chipcHw_miscControlDisable(uint32_t mask)
  245. {
  246. reg32_modify_and(&pChipcHw->MiscCtrl, ~mask);
  247. }
  248. static inline void chipcHw_miscControlEnable(uint32_t mask)
  249. {
  250. reg32_modify_or(&pChipcHw->MiscCtrl, mask);
  251. }
  252. /****************************************************************************/
  253. /**
  254. * @brief Set OTP options
  255. *
  256. * Set OTP options
  257. *
  258. * @return void
  259. *
  260. * @note use chipcHw_REG_OTP_XXXXXX
  261. */
  262. /****************************************************************************/
  263. static inline void chipcHw_setOTPOption(uint64_t mask)
  264. {
  265. uint32_t ctrl1 = (uint32_t) mask;
  266. uint32_t ctrl2 = (uint32_t) (mask >> 32);
  267. reg32_modify_or(&pChipcHw->SoftOTP1, ctrl1);
  268. reg32_modify_or(&pChipcHw->SoftOTP2, ctrl2);
  269. }
  270. /****************************************************************************/
  271. /**
  272. * @brief Get sticky bits
  273. *
  274. * @return Sticky bit options of type chipcHw_REG_STICKY_XXXXXX
  275. *
  276. */
  277. /****************************************************************************/
  278. static inline uint32_t chipcHw_getStickyBits(void)
  279. {
  280. return pChipcHw->Sticky;
  281. }
  282. /****************************************************************************/
  283. /**
  284. * @brief Set sticky bits
  285. *
  286. * @return void
  287. *
  288. * @note use chipcHw_REG_STICKY_XXXXXX
  289. */
  290. /****************************************************************************/
  291. static inline void chipcHw_setStickyBits(uint32_t mask)
  292. {
  293. uint32_t bits = 0;
  294. REG_LOCAL_IRQ_SAVE;
  295. if (mask & chipcHw_REG_STICKY_POR_BROM) {
  296. bits |= chipcHw_REG_STICKY_POR_BROM;
  297. } else {
  298. uint32_t sticky;
  299. sticky = pChipcHw->Sticky;
  300. if ((mask & chipcHw_REG_STICKY_BOOT_DONE)
  301. && (sticky & chipcHw_REG_STICKY_BOOT_DONE) == 0) {
  302. bits |= chipcHw_REG_STICKY_BOOT_DONE;
  303. }
  304. if ((mask & chipcHw_REG_STICKY_GENERAL_1)
  305. && (sticky & chipcHw_REG_STICKY_GENERAL_1) == 0) {
  306. bits |= chipcHw_REG_STICKY_GENERAL_1;
  307. }
  308. if ((mask & chipcHw_REG_STICKY_GENERAL_2)
  309. && (sticky & chipcHw_REG_STICKY_GENERAL_2) == 0) {
  310. bits |= chipcHw_REG_STICKY_GENERAL_2;
  311. }
  312. if ((mask & chipcHw_REG_STICKY_GENERAL_3)
  313. && (sticky & chipcHw_REG_STICKY_GENERAL_3) == 0) {
  314. bits |= chipcHw_REG_STICKY_GENERAL_3;
  315. }
  316. if ((mask & chipcHw_REG_STICKY_GENERAL_4)
  317. && (sticky & chipcHw_REG_STICKY_GENERAL_4) == 0) {
  318. bits |= chipcHw_REG_STICKY_GENERAL_4;
  319. }
  320. if ((mask & chipcHw_REG_STICKY_GENERAL_5)
  321. && (sticky & chipcHw_REG_STICKY_GENERAL_5) == 0) {
  322. bits |= chipcHw_REG_STICKY_GENERAL_5;
  323. }
  324. }
  325. pChipcHw->Sticky = bits;
  326. REG_LOCAL_IRQ_RESTORE;
  327. }
  328. /****************************************************************************/
  329. /**
  330. * @brief Clear sticky bits
  331. *
  332. * @return void
  333. *
  334. * @note use chipcHw_REG_STICKY_XXXXXX
  335. */
  336. /****************************************************************************/
  337. static inline void chipcHw_clearStickyBits(uint32_t mask)
  338. {
  339. uint32_t bits = 0;
  340. REG_LOCAL_IRQ_SAVE;
  341. if (mask &
  342. (chipcHw_REG_STICKY_BOOT_DONE | chipcHw_REG_STICKY_GENERAL_1 |
  343. chipcHw_REG_STICKY_GENERAL_2 | chipcHw_REG_STICKY_GENERAL_3 |
  344. chipcHw_REG_STICKY_GENERAL_4 | chipcHw_REG_STICKY_GENERAL_5)) {
  345. uint32_t sticky = pChipcHw->Sticky;
  346. if ((mask & chipcHw_REG_STICKY_BOOT_DONE)
  347. && (sticky & chipcHw_REG_STICKY_BOOT_DONE)) {
  348. bits = chipcHw_REG_STICKY_BOOT_DONE;
  349. mask &= ~chipcHw_REG_STICKY_BOOT_DONE;
  350. }
  351. if ((mask & chipcHw_REG_STICKY_GENERAL_1)
  352. && (sticky & chipcHw_REG_STICKY_GENERAL_1)) {
  353. bits |= chipcHw_REG_STICKY_GENERAL_1;
  354. mask &= ~chipcHw_REG_STICKY_GENERAL_1;
  355. }
  356. if ((mask & chipcHw_REG_STICKY_GENERAL_2)
  357. && (sticky & chipcHw_REG_STICKY_GENERAL_2)) {
  358. bits |= chipcHw_REG_STICKY_GENERAL_2;
  359. mask &= ~chipcHw_REG_STICKY_GENERAL_2;
  360. }
  361. if ((mask & chipcHw_REG_STICKY_GENERAL_3)
  362. && (sticky & chipcHw_REG_STICKY_GENERAL_3)) {
  363. bits |= chipcHw_REG_STICKY_GENERAL_3;
  364. mask &= ~chipcHw_REG_STICKY_GENERAL_3;
  365. }
  366. if ((mask & chipcHw_REG_STICKY_GENERAL_4)
  367. && (sticky & chipcHw_REG_STICKY_GENERAL_4)) {
  368. bits |= chipcHw_REG_STICKY_GENERAL_4;
  369. mask &= ~chipcHw_REG_STICKY_GENERAL_4;
  370. }
  371. if ((mask & chipcHw_REG_STICKY_GENERAL_5)
  372. && (sticky & chipcHw_REG_STICKY_GENERAL_5)) {
  373. bits |= chipcHw_REG_STICKY_GENERAL_5;
  374. mask &= ~chipcHw_REG_STICKY_GENERAL_5;
  375. }
  376. }
  377. pChipcHw->Sticky = bits | mask;
  378. REG_LOCAL_IRQ_RESTORE;
  379. }
  380. /****************************************************************************/
  381. /**
  382. * @brief Get software strap value
  383. *
  384. * Retrieves software strap value
  385. *
  386. * @return Software strap value
  387. *
  388. */
  389. /****************************************************************************/
  390. static inline uint32_t chipcHw_getSoftStraps(void)
  391. {
  392. return pChipcHw->SoftStraps;
  393. }
  394. /****************************************************************************/
  395. /**
  396. * @brief Set software override strap options
  397. *
  398. * set software override strap options
  399. *
  400. * @return nothing
  401. *
  402. */
  403. /****************************************************************************/
  404. static inline void chipcHw_setSoftStraps(uint32_t strapOptions)
  405. {
  406. reg32_write(&pChipcHw->SoftStraps, strapOptions);
  407. }
  408. /****************************************************************************/
  409. /**
  410. * @brief Get Pin Strap Options
  411. *
  412. * This function returns the raw boot strap options
  413. *
  414. * @return strap options
  415. *
  416. */
  417. /****************************************************************************/
  418. static inline uint32_t chipcHw_getPinStraps(void)
  419. {
  420. return pChipcHw->PinStraps;
  421. }
  422. /****************************************************************************/
  423. /**
  424. * @brief Get Valid Strap Options
  425. *
  426. * This function returns the valid raw boot strap options
  427. *
  428. * @return strap options
  429. *
  430. */
  431. /****************************************************************************/
  432. static inline uint32_t chipcHw_getValidStraps(void)
  433. {
  434. uint32_t softStraps;
  435. /*
  436. ** Always return the SoftStraps - bootROM calls chipcHw_initValidStraps
  437. ** which copies HW straps to soft straps if there is no override
  438. */
  439. softStraps = chipcHw_getSoftStraps();
  440. return softStraps;
  441. }
  442. /****************************************************************************/
  443. /**
  444. * @brief Initialize valid pin strap options
  445. *
  446. * Retrieves valid pin strap options by copying HW strap options to soft register
  447. * (if chipcHw_STRAPS_SOFT_OVERRIDE not set)
  448. *
  449. * @return nothing
  450. *
  451. */
  452. /****************************************************************************/
  453. static inline void chipcHw_initValidStraps(void)
  454. {
  455. uint32_t softStraps;
  456. REG_LOCAL_IRQ_SAVE;
  457. softStraps = chipcHw_getSoftStraps();
  458. if ((softStraps & chipcHw_STRAPS_SOFT_OVERRIDE) == 0) {
  459. /* Copy HW straps to software straps */
  460. chipcHw_setSoftStraps(chipcHw_getPinStraps());
  461. }
  462. REG_LOCAL_IRQ_RESTORE;
  463. }
  464. /****************************************************************************/
  465. /**
  466. * @brief Get boot device
  467. *
  468. * This function returns the device type used in booting the system
  469. *
  470. * @return Boot device of type chipcHw_BOOT_DEVICE
  471. *
  472. */
  473. /****************************************************************************/
  474. static inline chipcHw_BOOT_DEVICE_e chipcHw_getBootDevice(void)
  475. {
  476. return chipcHw_getValidStraps() & chipcHw_STRAPS_BOOT_DEVICE_MASK;
  477. }
  478. /****************************************************************************/
  479. /**
  480. * @brief Get boot mode
  481. *
  482. * This function returns the way the system was booted
  483. *
  484. * @return Boot mode of type chipcHw_BOOT_MODE
  485. *
  486. */
  487. /****************************************************************************/
  488. static inline chipcHw_BOOT_MODE_e chipcHw_getBootMode(void)
  489. {
  490. return chipcHw_getValidStraps() & chipcHw_STRAPS_BOOT_MODE_MASK;
  491. }
  492. /****************************************************************************/
  493. /**
  494. * @brief Get NAND flash page size
  495. *
  496. * This function returns the NAND device page size
  497. *
  498. * @return Boot NAND device page size
  499. *
  500. */
  501. /****************************************************************************/
  502. static inline chipcHw_NAND_PAGESIZE_e chipcHw_getNandPageSize(void)
  503. {
  504. return chipcHw_getValidStraps() & chipcHw_STRAPS_NAND_PAGESIZE_MASK;
  505. }
  506. /****************************************************************************/
  507. /**
  508. * @brief Get NAND flash address cycle configuration
  509. *
  510. * This function returns the NAND flash address cycle configuration
  511. *
  512. * @return 0 = Do not extra address cycle, 1 = Add extra cycle
  513. *
  514. */
  515. /****************************************************************************/
  516. static inline int chipcHw_getNandExtraCycle(void)
  517. {
  518. if (chipcHw_getValidStraps() & chipcHw_STRAPS_NAND_EXTRA_CYCLE) {
  519. return 1;
  520. } else {
  521. return 0;
  522. }
  523. }
  524. /****************************************************************************/
  525. /**
  526. * @brief Activates PIF interface
  527. *
  528. * This function activates PIF interface by taking control of LCD pins
  529. *
  530. * @note
  531. * When activated, LCD pins will be defined as follows for PIF operation
  532. *
  533. * CLD[17:0] = pif_data[17:0]
  534. * CLD[23:18] = pif_address[5:0]
  535. * CLPOWER = pif_wr_str
  536. * CLCP = pif_rd_str
  537. * CLAC = pif_hat1
  538. * CLFP = pif_hrdy1
  539. * CLLP = pif_hat2
  540. * GPIO[42] = pif_hrdy2
  541. *
  542. * In PIF mode, "pif_hrdy2" overrides other shared function for GPIO[42] pin
  543. *
  544. */
  545. /****************************************************************************/
  546. static inline void chipcHw_activatePifInterface(void)
  547. {
  548. reg32_write(&pChipcHw->LcdPifMode, chipcHw_REG_PIF_PIN_ENABLE);
  549. }
  550. /****************************************************************************/
  551. /**
  552. * @brief Activates LCD interface
  553. *
  554. * This function activates LCD interface
  555. *
  556. * @note
  557. * When activated, LCD pins will be defined as follows
  558. *
  559. * CLD[17:0] = LCD data
  560. * CLD[23:18] = LCD data
  561. * CLPOWER = LCD power
  562. * CLCP =
  563. * CLAC = LCD ack
  564. * CLFP =
  565. * CLLP =
  566. */
  567. /****************************************************************************/
  568. static inline void chipcHw_activateLcdInterface(void)
  569. {
  570. reg32_write(&pChipcHw->LcdPifMode, chipcHw_REG_LCD_PIN_ENABLE);
  571. }
  572. /****************************************************************************/
  573. /**
  574. * @brief Deactivates PIF/LCD interface
  575. *
  576. * This function deactivates PIF/LCD interface
  577. *
  578. * @note
  579. * When deactivated LCD pins will be in rti-stated
  580. *
  581. */
  582. /****************************************************************************/
  583. static inline void chipcHw_deactivatePifLcdInterface(void)
  584. {
  585. reg32_write(&pChipcHw->LcdPifMode, 0);
  586. }
  587. /****************************************************************************/
  588. /**
  589. * @brief Select GE2
  590. *
  591. * This function select GE2 as the graphic engine
  592. *
  593. */
  594. /****************************************************************************/
  595. static inline void chipcHw_selectGE2(void)
  596. {
  597. reg32_modify_and(&pChipcHw->MiscCtrl, ~chipcHw_REG_MISC_CTRL_GE_SEL);
  598. }
  599. /****************************************************************************/
  600. /**
  601. * @brief Select GE3
  602. *
  603. * This function select GE3 as the graphic engine
  604. *
  605. */
  606. /****************************************************************************/
  607. static inline void chipcHw_selectGE3(void)
  608. {
  609. reg32_modify_or(&pChipcHw->MiscCtrl, chipcHw_REG_MISC_CTRL_GE_SEL);
  610. }
  611. /****************************************************************************/
  612. /**
  613. * @brief Get to know the configuration of GPIO pin
  614. *
  615. */
  616. /****************************************************************************/
  617. static inline chipcHw_GPIO_FUNCTION_e chipcHw_getGpioPinFunction(int pin)
  618. {
  619. return (*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) &
  620. (chipcHw_REG_GPIO_MUX_MASK <<
  621. chipcHw_REG_GPIO_MUX_POSITION(pin))) >>
  622. chipcHw_REG_GPIO_MUX_POSITION(pin);
  623. }
  624. /****************************************************************************/
  625. /**
  626. * @brief Configure GPIO pin function
  627. *
  628. */
  629. /****************************************************************************/
  630. static inline void chipcHw_setGpioPinFunction(int pin,
  631. chipcHw_GPIO_FUNCTION_e func)
  632. {
  633. REG_LOCAL_IRQ_SAVE;
  634. *((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) &=
  635. ~(chipcHw_REG_GPIO_MUX_MASK << chipcHw_REG_GPIO_MUX_POSITION(pin));
  636. *((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) |=
  637. func << chipcHw_REG_GPIO_MUX_POSITION(pin);
  638. REG_LOCAL_IRQ_RESTORE;
  639. }
  640. /****************************************************************************/
  641. /**
  642. * @brief Set Pin slew rate
  643. *
  644. * This function sets the slew of individual pin
  645. *
  646. */
  647. /****************************************************************************/
  648. static inline void chipcHw_setPinSlewRate(uint32_t pin,
  649. chipcHw_PIN_SLEW_RATE_e slewRate)
  650. {
  651. REG_LOCAL_IRQ_SAVE;
  652. *((uint32_t *) chipcHw_REG_SLEW_RATE(pin)) &=
  653. ~(chipcHw_REG_SLEW_RATE_MASK <<
  654. chipcHw_REG_SLEW_RATE_POSITION(pin));
  655. *((uint32_t *) chipcHw_REG_SLEW_RATE(pin)) |=
  656. (uint32_t) slewRate << chipcHw_REG_SLEW_RATE_POSITION(pin);
  657. REG_LOCAL_IRQ_RESTORE;
  658. }
  659. /****************************************************************************/
  660. /**
  661. * @brief Set Pin output drive current
  662. *
  663. * This function sets output drive current of individual pin
  664. *
  665. * Note: Avoid the use of the word 'current' since linux headers define this
  666. * to be the current task.
  667. */
  668. /****************************************************************************/
  669. static inline void chipcHw_setPinOutputCurrent(uint32_t pin,
  670. chipcHw_PIN_CURRENT_STRENGTH_e
  671. curr)
  672. {
  673. REG_LOCAL_IRQ_SAVE;
  674. *((uint32_t *) chipcHw_REG_CURRENT(pin)) &=
  675. ~(chipcHw_REG_CURRENT_MASK << chipcHw_REG_CURRENT_POSITION(pin));
  676. *((uint32_t *) chipcHw_REG_CURRENT(pin)) |=
  677. (uint32_t) curr << chipcHw_REG_CURRENT_POSITION(pin);
  678. REG_LOCAL_IRQ_RESTORE;
  679. }
  680. /****************************************************************************/
  681. /**
  682. * @brief Set Pin pullup register
  683. *
  684. * This function sets pullup register of individual pin
  685. *
  686. */
  687. /****************************************************************************/
  688. static inline void chipcHw_setPinPullup(uint32_t pin, chipcHw_PIN_PULL_e pullup)
  689. {
  690. REG_LOCAL_IRQ_SAVE;
  691. *((uint32_t *) chipcHw_REG_PULLUP(pin)) &=
  692. ~(chipcHw_REG_PULLUP_MASK << chipcHw_REG_PULLUP_POSITION(pin));
  693. *((uint32_t *) chipcHw_REG_PULLUP(pin)) |=
  694. (uint32_t) pullup << chipcHw_REG_PULLUP_POSITION(pin);
  695. REG_LOCAL_IRQ_RESTORE;
  696. }
  697. /****************************************************************************/
  698. /**
  699. * @brief Set Pin input type
  700. *
  701. * This function sets input type of individual pin
  702. *
  703. */
  704. /****************************************************************************/
  705. static inline void chipcHw_setPinInputType(uint32_t pin,
  706. chipcHw_PIN_INPUTTYPE_e inputType)
  707. {
  708. REG_LOCAL_IRQ_SAVE;
  709. *((uint32_t *) chipcHw_REG_INPUTTYPE(pin)) &=
  710. ~(chipcHw_REG_INPUTTYPE_MASK <<
  711. chipcHw_REG_INPUTTYPE_POSITION(pin));
  712. *((uint32_t *) chipcHw_REG_INPUTTYPE(pin)) |=
  713. (uint32_t) inputType << chipcHw_REG_INPUTTYPE_POSITION(pin);
  714. REG_LOCAL_IRQ_RESTORE;
  715. }
  716. /****************************************************************************/
  717. /**
  718. * @brief Power up the USB PHY
  719. *
  720. * This function powers up the USB PHY
  721. *
  722. */
  723. /****************************************************************************/
  724. static inline void chipcHw_powerUpUsbPhy(void)
  725. {
  726. reg32_modify_and(&pChipcHw->MiscCtrl,
  727. chipcHw_REG_MISC_CTRL_USB_POWERON);
  728. }
  729. /****************************************************************************/
  730. /**
  731. * @brief Power down the USB PHY
  732. *
  733. * This function powers down the USB PHY
  734. *
  735. */
  736. /****************************************************************************/
  737. static inline void chipcHw_powerDownUsbPhy(void)
  738. {
  739. reg32_modify_or(&pChipcHw->MiscCtrl,
  740. chipcHw_REG_MISC_CTRL_USB_POWEROFF);
  741. }
  742. /****************************************************************************/
  743. /**
  744. * @brief Set the 2nd USB as host
  745. *
  746. * This function sets the 2nd USB as host
  747. *
  748. */
  749. /****************************************************************************/
  750. static inline void chipcHw_setUsbHost(void)
  751. {
  752. reg32_modify_or(&pChipcHw->MiscCtrl,
  753. chipcHw_REG_MISC_CTRL_USB_MODE_HOST);
  754. }
  755. /****************************************************************************/
  756. /**
  757. * @brief Set the 2nd USB as device
  758. *
  759. * This function sets the 2nd USB as device
  760. *
  761. */
  762. /****************************************************************************/
  763. static inline void chipcHw_setUsbDevice(void)
  764. {
  765. reg32_modify_and(&pChipcHw->MiscCtrl,
  766. chipcHw_REG_MISC_CTRL_USB_MODE_DEVICE);
  767. }
  768. /****************************************************************************/
  769. /**
  770. * @brief Lower layer funtion to enable/disable a clock of a certain device
  771. *
  772. * This function enables/disables a core clock
  773. *
  774. */
  775. /****************************************************************************/
  776. static inline void chipcHw_setClock(chipcHw_CLOCK_e clock,
  777. chipcHw_OPTYPE_e type, int mode)
  778. {
  779. volatile uint32_t *pPLLReg = (uint32_t *) 0x0;
  780. volatile uint32_t *pClockCtrl = (uint32_t *) 0x0;
  781. switch (clock) {
  782. case chipcHw_CLOCK_DDR:
  783. pPLLReg = &pChipcHw->DDRClock;
  784. break;
  785. case chipcHw_CLOCK_ARM:
  786. pPLLReg = &pChipcHw->ARMClock;
  787. break;
  788. case chipcHw_CLOCK_ESW:
  789. pPLLReg = &pChipcHw->ESWClock;
  790. break;
  791. case chipcHw_CLOCK_VPM:
  792. pPLLReg = &pChipcHw->VPMClock;
  793. break;
  794. case chipcHw_CLOCK_ESW125:
  795. pPLLReg = &pChipcHw->ESW125Clock;
  796. break;
  797. case chipcHw_CLOCK_UART:
  798. pPLLReg = &pChipcHw->UARTClock;
  799. break;
  800. case chipcHw_CLOCK_SDIO0:
  801. pPLLReg = &pChipcHw->SDIO0Clock;
  802. break;
  803. case chipcHw_CLOCK_SDIO1:
  804. pPLLReg = &pChipcHw->SDIO1Clock;
  805. break;
  806. case chipcHw_CLOCK_SPI:
  807. pPLLReg = &pChipcHw->SPIClock;
  808. break;
  809. case chipcHw_CLOCK_ETM:
  810. pPLLReg = &pChipcHw->ETMClock;
  811. break;
  812. case chipcHw_CLOCK_USB:
  813. pPLLReg = &pChipcHw->USBClock;
  814. if (type == chipcHw_OPTYPE_OUTPUT) {
  815. if (mode) {
  816. reg32_modify_and(pPLLReg,
  817. ~chipcHw_REG_PLL_CLOCK_POWER_DOWN);
  818. } else {
  819. reg32_modify_or(pPLLReg,
  820. chipcHw_REG_PLL_CLOCK_POWER_DOWN);
  821. }
  822. }
  823. break;
  824. case chipcHw_CLOCK_LCD:
  825. pPLLReg = &pChipcHw->LCDClock;
  826. if (type == chipcHw_OPTYPE_OUTPUT) {
  827. if (mode) {
  828. reg32_modify_and(pPLLReg,
  829. ~chipcHw_REG_PLL_CLOCK_POWER_DOWN);
  830. } else {
  831. reg32_modify_or(pPLLReg,
  832. chipcHw_REG_PLL_CLOCK_POWER_DOWN);
  833. }
  834. }
  835. break;
  836. case chipcHw_CLOCK_APM:
  837. pPLLReg = &pChipcHw->APMClock;
  838. if (type == chipcHw_OPTYPE_OUTPUT) {
  839. if (mode) {
  840. reg32_modify_and(pPLLReg,
  841. ~chipcHw_REG_PLL_CLOCK_POWER_DOWN);
  842. } else {
  843. reg32_modify_or(pPLLReg,
  844. chipcHw_REG_PLL_CLOCK_POWER_DOWN);
  845. }
  846. }
  847. break;
  848. case chipcHw_CLOCK_BUS:
  849. pClockCtrl = &pChipcHw->ACLKClock;
  850. break;
  851. case chipcHw_CLOCK_OTP:
  852. pClockCtrl = &pChipcHw->OTPClock;
  853. break;
  854. case chipcHw_CLOCK_I2C:
  855. pClockCtrl = &pChipcHw->I2CClock;
  856. break;
  857. case chipcHw_CLOCK_I2S0:
  858. pClockCtrl = &pChipcHw->I2S0Clock;
  859. break;
  860. case chipcHw_CLOCK_RTBUS:
  861. pClockCtrl = &pChipcHw->RTBUSClock;
  862. break;
  863. case chipcHw_CLOCK_APM100:
  864. pClockCtrl = &pChipcHw->APM100Clock;
  865. break;
  866. case chipcHw_CLOCK_TSC:
  867. pClockCtrl = &pChipcHw->TSCClock;
  868. break;
  869. case chipcHw_CLOCK_LED:
  870. pClockCtrl = &pChipcHw->LEDClock;
  871. break;
  872. case chipcHw_CLOCK_I2S1:
  873. pClockCtrl = &pChipcHw->I2S1Clock;
  874. break;
  875. }
  876. if (pPLLReg) {
  877. switch (type) {
  878. case chipcHw_OPTYPE_OUTPUT:
  879. /* PLL clock output enable/disable */
  880. if (mode) {
  881. if (clock == chipcHw_CLOCK_DDR) {
  882. /* DDR clock enable is inverted */
  883. reg32_modify_and(pPLLReg,
  884. ~chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
  885. } else {
  886. reg32_modify_or(pPLLReg,
  887. chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
  888. }
  889. } else {
  890. if (clock == chipcHw_CLOCK_DDR) {
  891. /* DDR clock disable is inverted */
  892. reg32_modify_or(pPLLReg,
  893. chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
  894. } else {
  895. reg32_modify_and(pPLLReg,
  896. ~chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);
  897. }
  898. }
  899. break;
  900. case chipcHw_OPTYPE_BYPASS:
  901. /* PLL clock bypass enable/disable */
  902. if (mode) {
  903. reg32_modify_or(pPLLReg,
  904. chipcHw_REG_PLL_CLOCK_BYPASS_SELECT);
  905. } else {
  906. reg32_modify_and(pPLLReg,
  907. ~chipcHw_REG_PLL_CLOCK_BYPASS_SELECT);
  908. }
  909. break;
  910. }
  911. } else if (pClockCtrl) {
  912. switch (type) {
  913. case chipcHw_OPTYPE_OUTPUT:
  914. if (mode) {
  915. reg32_modify_or(pClockCtrl,
  916. chipcHw_REG_DIV_CLOCK_OUTPUT_ENABLE);
  917. } else {
  918. reg32_modify_and(pClockCtrl,
  919. ~chipcHw_REG_DIV_CLOCK_OUTPUT_ENABLE);
  920. }
  921. break;
  922. case chipcHw_OPTYPE_BYPASS:
  923. if (mode) {
  924. reg32_modify_or(pClockCtrl,
  925. chipcHw_REG_DIV_CLOCK_BYPASS_SELECT);
  926. } else {
  927. reg32_modify_and(pClockCtrl,
  928. ~chipcHw_REG_DIV_CLOCK_BYPASS_SELECT);
  929. }
  930. break;
  931. }
  932. }
  933. }
  934. /****************************************************************************/
  935. /**
  936. * @brief Disables a core clock of a certain device
  937. *
  938. * This function disables a core clock
  939. *
  940. * @note no change in power consumption
  941. */
  942. /****************************************************************************/
  943. static inline void chipcHw_setClockDisable(chipcHw_CLOCK_e clock)
  944. {
  945. /* Disable output of the clock */
  946. chipcHw_setClock(clock, chipcHw_OPTYPE_OUTPUT, 0);
  947. }
  948. /****************************************************************************/
  949. /**
  950. * @brief Enable a core clock of a certain device
  951. *
  952. * This function enables a core clock
  953. *
  954. * @note no change in power consumption
  955. */
  956. /****************************************************************************/
  957. static inline void chipcHw_setClockEnable(chipcHw_CLOCK_e clock)
  958. {
  959. /* Enable output of the clock */
  960. chipcHw_setClock(clock, chipcHw_OPTYPE_OUTPUT, 1);
  961. }
  962. /****************************************************************************/
  963. /**
  964. * @brief Enables bypass clock of a certain device
  965. *
  966. * This function enables bypass clock
  967. *
  968. * @note Doesnot affect the bus interface clock
  969. */
  970. /****************************************************************************/
  971. static inline void chipcHw_bypassClockEnable(chipcHw_CLOCK_e clock)
  972. {
  973. /* Enable bypass clock */
  974. chipcHw_setClock(clock, chipcHw_OPTYPE_BYPASS, 1);
  975. }
  976. /****************************************************************************/
  977. /**
  978. * @brief Disabled bypass clock of a certain device
  979. *
  980. * This function disables bypass clock
  981. *
  982. * @note Doesnot affect the bus interface clock
  983. */
  984. /****************************************************************************/
  985. static inline void chipcHw_bypassClockDisable(chipcHw_CLOCK_e clock)
  986. {
  987. /* Disable bypass clock */
  988. chipcHw_setClock(clock, chipcHw_OPTYPE_BYPASS, 0);
  989. }
  990. /****************************************************************************/
  991. /** @brief Checks if software strap is enabled
  992. *
  993. * @return 1 : When enable
  994. * 0 : When disable
  995. */
  996. /****************************************************************************/
  997. static inline int chipcHw_isSoftwareStrapsEnable(void)
  998. {
  999. return pChipcHw->SoftStraps & 0x00000001;
  1000. }
  1001. /****************************************************************************/
  1002. /** @brief Enable software strap
  1003. */
  1004. /****************************************************************************/
  1005. static inline void chipcHw_softwareStrapsEnable(void)
  1006. {
  1007. reg32_modify_or(&pChipcHw->SoftStraps, 0x00000001);
  1008. }
  1009. /****************************************************************************/
  1010. /** @brief Disable software strap
  1011. */
  1012. /****************************************************************************/
  1013. static inline void chipcHw_softwareStrapsDisable(void)
  1014. {
  1015. reg32_modify_and(&pChipcHw->SoftStraps, (~0x00000001));
  1016. }
  1017. /****************************************************************************/
  1018. /** @brief PLL test enable
  1019. */
  1020. /****************************************************************************/
  1021. static inline void chipcHw_pllTestEnable(void)
  1022. {
  1023. reg32_modify_or(&pChipcHw->PLLConfig,
  1024. chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
  1025. }
  1026. /****************************************************************************/
  1027. /** @brief PLL2 test enable
  1028. */
  1029. /****************************************************************************/
  1030. static inline void chipcHw_pll2TestEnable(void)
  1031. {
  1032. reg32_modify_or(&pChipcHw->PLLConfig2,
  1033. chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
  1034. }
  1035. /****************************************************************************/
  1036. /** @brief PLL test disable
  1037. */
  1038. /****************************************************************************/
  1039. static inline void chipcHw_pllTestDisable(void)
  1040. {
  1041. reg32_modify_and(&pChipcHw->PLLConfig,
  1042. ~chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
  1043. }
  1044. /****************************************************************************/
  1045. /** @brief PLL2 test disable
  1046. */
  1047. /****************************************************************************/
  1048. static inline void chipcHw_pll2TestDisable(void)
  1049. {
  1050. reg32_modify_and(&pChipcHw->PLLConfig2,
  1051. ~chipcHw_REG_PLL_CONFIG_TEST_ENABLE);
  1052. }
  1053. /****************************************************************************/
  1054. /** @brief Get PLL test status
  1055. */
  1056. /****************************************************************************/
  1057. static inline int chipcHw_isPllTestEnable(void)
  1058. {
  1059. return pChipcHw->PLLConfig & chipcHw_REG_PLL_CONFIG_TEST_ENABLE;
  1060. }
  1061. /****************************************************************************/
  1062. /** @brief Get PLL2 test status
  1063. */
  1064. /****************************************************************************/
  1065. static inline int chipcHw_isPll2TestEnable(void)
  1066. {
  1067. return pChipcHw->PLLConfig2 & chipcHw_REG_PLL_CONFIG_TEST_ENABLE;
  1068. }
  1069. /****************************************************************************/
  1070. /** @brief PLL test select
  1071. */
  1072. /****************************************************************************/
  1073. static inline void chipcHw_pllTestSelect(uint32_t val)
  1074. {
  1075. REG_LOCAL_IRQ_SAVE;
  1076. pChipcHw->PLLConfig &= ~chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK;
  1077. pChipcHw->PLLConfig |=
  1078. (val) << chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT;
  1079. REG_LOCAL_IRQ_RESTORE;
  1080. }
  1081. /****************************************************************************/
  1082. /** @brief PLL2 test select
  1083. */
  1084. /****************************************************************************/
  1085. static inline void chipcHw_pll2TestSelect(uint32_t val)
  1086. {
  1087. REG_LOCAL_IRQ_SAVE;
  1088. pChipcHw->PLLConfig2 &= ~chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK;
  1089. pChipcHw->PLLConfig2 |=
  1090. (val) << chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT;
  1091. REG_LOCAL_IRQ_RESTORE;
  1092. }
  1093. /****************************************************************************/
  1094. /** @brief Get PLL test selected option
  1095. */
  1096. /****************************************************************************/
  1097. static inline uint8_t chipcHw_getPllTestSelected(void)
  1098. {
  1099. return (uint8_t) ((pChipcHw->
  1100. PLLConfig & chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK)
  1101. >> chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT);
  1102. }
  1103. /****************************************************************************/
  1104. /** @brief Get PLL2 test selected option
  1105. */
  1106. /****************************************************************************/
  1107. static inline uint8_t chipcHw_getPll2TestSelected(void)
  1108. {
  1109. return (uint8_t) ((pChipcHw->
  1110. PLLConfig2 & chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK)
  1111. >> chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT);
  1112. }
  1113. /****************************************************************************/
  1114. /**
  1115. * @brief Disable the PLL1
  1116. *
  1117. */
  1118. /****************************************************************************/
  1119. static inline void chipcHw_pll1Disable(void)
  1120. {
  1121. REG_LOCAL_IRQ_SAVE;
  1122. pChipcHw->PLLConfig |= chipcHw_REG_PLL_CONFIG_POWER_DOWN;
  1123. REG_LOCAL_IRQ_RESTORE;
  1124. }
  1125. /****************************************************************************/
  1126. /**
  1127. * @brief Disable the PLL2
  1128. *
  1129. */
  1130. /****************************************************************************/
  1131. static inline void chipcHw_pll2Disable(void)
  1132. {
  1133. REG_LOCAL_IRQ_SAVE;
  1134. pChipcHw->PLLConfig2 |= chipcHw_REG_PLL_CONFIG_POWER_DOWN;
  1135. REG_LOCAL_IRQ_RESTORE;
  1136. }
  1137. /****************************************************************************/
  1138. /**
  1139. * @brief Enables DDR SW phase alignment interrupt
  1140. */
  1141. /****************************************************************************/
  1142. static inline void chipcHw_ddrPhaseAlignInterruptEnable(void)
  1143. {
  1144. REG_LOCAL_IRQ_SAVE;
  1145. pChipcHw->Spare1 |= chipcHw_REG_SPARE1_DDR_PHASE_INTR_ENABLE;
  1146. REG_LOCAL_IRQ_RESTORE;
  1147. }
  1148. /****************************************************************************/
  1149. /**
  1150. * @brief Disables DDR SW phase alignment interrupt
  1151. */
  1152. /****************************************************************************/
  1153. static inline void chipcHw_ddrPhaseAlignInterruptDisable(void)
  1154. {
  1155. REG_LOCAL_IRQ_SAVE;
  1156. pChipcHw->Spare1 &= ~chipcHw_REG_SPARE1_DDR_PHASE_INTR_ENABLE;
  1157. REG_LOCAL_IRQ_RESTORE;
  1158. }
  1159. /****************************************************************************/
  1160. /**
  1161. * @brief Set VPM SW phase alignment interrupt mode
  1162. *
  1163. * This function sets VPM phase alignment interrupt
  1164. */
  1165. /****************************************************************************/
  1166. static inline void
  1167. chipcHw_vpmPhaseAlignInterruptMode(chipcHw_VPM_HW_PHASE_INTR_e mode)
  1168. {
  1169. REG_LOCAL_IRQ_SAVE;
  1170. if (mode == chipcHw_VPM_HW_PHASE_INTR_DISABLE) {
  1171. pChipcHw->Spare1 &= ~chipcHw_REG_SPARE1_VPM_PHASE_INTR_ENABLE;
  1172. } else {
  1173. pChipcHw->Spare1 |= chipcHw_REG_SPARE1_VPM_PHASE_INTR_ENABLE;
  1174. }
  1175. pChipcHw->VPMPhaseCtrl2 =
  1176. (pChipcHw->
  1177. VPMPhaseCtrl2 & ~(chipcHw_REG_VPM_INTR_SELECT_MASK <<
  1178. chipcHw_REG_VPM_INTR_SELECT_SHIFT)) | mode;
  1179. REG_LOCAL_IRQ_RESTORE;
  1180. }
  1181. /****************************************************************************/
  1182. /**
  1183. * @brief Enable DDR phase alignment in software
  1184. *
  1185. */
  1186. /****************************************************************************/
  1187. static inline void chipcHw_ddrSwPhaseAlignEnable(void)
  1188. {
  1189. REG_LOCAL_IRQ_SAVE;
  1190. pChipcHw->DDRPhaseCtrl1 |= chipcHw_REG_DDR_SW_PHASE_CTRL_ENABLE;
  1191. REG_LOCAL_IRQ_RESTORE;
  1192. }
  1193. /****************************************************************************/
  1194. /**
  1195. * @brief Disable DDR phase alignment in software
  1196. *
  1197. */
  1198. /****************************************************************************/
  1199. static inline void chipcHw_ddrSwPhaseAlignDisable(void)
  1200. {
  1201. REG_LOCAL_IRQ_SAVE;
  1202. pChipcHw->DDRPhaseCtrl1 &= ~chipcHw_REG_DDR_SW_PHASE_CTRL_ENABLE;
  1203. REG_LOCAL_IRQ_RESTORE;
  1204. }
  1205. /****************************************************************************/
  1206. /**
  1207. * @brief Enable DDR phase alignment in hardware
  1208. *
  1209. */
  1210. /****************************************************************************/
  1211. static inline void chipcHw_ddrHwPhaseAlignEnable(void)
  1212. {
  1213. REG_LOCAL_IRQ_SAVE;
  1214. pChipcHw->DDRPhaseCtrl1 |= chipcHw_REG_DDR_HW_PHASE_CTRL_ENABLE;
  1215. REG_LOCAL_IRQ_RESTORE;
  1216. }
  1217. /****************************************************************************/
  1218. /**
  1219. * @brief Disable DDR phase alignment in hardware
  1220. *
  1221. */
  1222. /****************************************************************************/
  1223. static inline void chipcHw_ddrHwPhaseAlignDisable(void)
  1224. {
  1225. REG_LOCAL_IRQ_SAVE;
  1226. pChipcHw->DDRPhaseCtrl1 &= ~chipcHw_REG_DDR_HW_PHASE_CTRL_ENABLE;
  1227. REG_LOCAL_IRQ_RESTORE;
  1228. }
  1229. /****************************************************************************/
  1230. /**
  1231. * @brief Enable VPM phase alignment in software
  1232. *
  1233. */
  1234. /****************************************************************************/
  1235. static inline void chipcHw_vpmSwPhaseAlignEnable(void)
  1236. {
  1237. REG_LOCAL_IRQ_SAVE;
  1238. pChipcHw->VPMPhaseCtrl1 |= chipcHw_REG_VPM_SW_PHASE_CTRL_ENABLE;
  1239. REG_LOCAL_IRQ_RESTORE;
  1240. }
  1241. /****************************************************************************/
  1242. /**
  1243. * @brief Disable VPM phase alignment in software
  1244. *
  1245. */
  1246. /****************************************************************************/
  1247. static inline void chipcHw_vpmSwPhaseAlignDisable(void)
  1248. {
  1249. REG_LOCAL_IRQ_SAVE;
  1250. pChipcHw->VPMPhaseCtrl1 &= ~chipcHw_REG_VPM_SW_PHASE_CTRL_ENABLE;
  1251. REG_LOCAL_IRQ_RESTORE;
  1252. }
  1253. /****************************************************************************/
  1254. /**
  1255. * @brief Enable VPM phase alignment in hardware
  1256. *
  1257. */
  1258. /****************************************************************************/
  1259. static inline void chipcHw_vpmHwPhaseAlignEnable(void)
  1260. {
  1261. REG_LOCAL_IRQ_SAVE;
  1262. pChipcHw->VPMPhaseCtrl1 |= chipcHw_REG_VPM_HW_PHASE_CTRL_ENABLE;
  1263. REG_LOCAL_IRQ_RESTORE;
  1264. }
  1265. /****************************************************************************/
  1266. /**
  1267. * @brief Disable VPM phase alignment in hardware
  1268. *
  1269. */
  1270. /****************************************************************************/
  1271. static inline void chipcHw_vpmHwPhaseAlignDisable(void)
  1272. {
  1273. REG_LOCAL_IRQ_SAVE;
  1274. pChipcHw->VPMPhaseCtrl1 &= ~chipcHw_REG_VPM_HW_PHASE_CTRL_ENABLE;
  1275. REG_LOCAL_IRQ_RESTORE;
  1276. }
  1277. /****************************************************************************/
  1278. /**
  1279. * @brief Set DDR phase alignment margin in hardware
  1280. *
  1281. */
  1282. /****************************************************************************/
  1283. static inline void
  1284. chipcHw_setDdrHwPhaseAlignMargin(chipcHw_DDR_HW_PHASE_MARGIN_e margin)
  1285. {
  1286. uint32_t ge = 0;
  1287. uint32_t le = 0;
  1288. switch (margin) {
  1289. case chipcHw_DDR_HW_PHASE_MARGIN_STRICT:
  1290. ge = 0x0F;
  1291. le = 0x0F;
  1292. break;
  1293. case chipcHw_DDR_HW_PHASE_MARGIN_MEDIUM:
  1294. ge = 0x03;
  1295. le = 0x3F;
  1296. break;
  1297. case chipcHw_DDR_HW_PHASE_MARGIN_WIDE:
  1298. ge = 0x01;
  1299. le = 0x7F;
  1300. break;
  1301. }
  1302. {
  1303. REG_LOCAL_IRQ_SAVE;
  1304. pChipcHw->DDRPhaseCtrl1 &=
  1305. ~((chipcHw_REG_DDR_PHASE_VALUE_GE_MASK <<
  1306. chipcHw_REG_DDR_PHASE_VALUE_GE_SHIFT)
  1307. || (chipcHw_REG_DDR_PHASE_VALUE_LE_MASK <<
  1308. chipcHw_REG_DDR_PHASE_VALUE_LE_SHIFT));
  1309. pChipcHw->DDRPhaseCtrl1 |=
  1310. ((ge << chipcHw_REG_DDR_PHASE_VALUE_GE_SHIFT)
  1311. || (le << chipcHw_REG_DDR_PHASE_VALUE_LE_SHIFT));
  1312. REG_LOCAL_IRQ_RESTORE;
  1313. }
  1314. }
  1315. /****************************************************************************/
  1316. /**
  1317. * @brief Set VPM phase alignment margin in hardware
  1318. *
  1319. */
  1320. /****************************************************************************/
  1321. static inline void
  1322. chipcHw_setVpmHwPhaseAlignMargin(chipcHw_VPM_HW_PHASE_MARGIN_e margin)
  1323. {
  1324. uint32_t ge = 0;
  1325. uint32_t le = 0;
  1326. switch (margin) {
  1327. case chipcHw_VPM_HW_PHASE_MARGIN_STRICT:
  1328. ge = 0x0F;
  1329. le = 0x0F;
  1330. break;
  1331. case chipcHw_VPM_HW_PHASE_MARGIN_MEDIUM:
  1332. ge = 0x03;
  1333. le = 0x3F;
  1334. break;
  1335. case chipcHw_VPM_HW_PHASE_MARGIN_WIDE:
  1336. ge = 0x01;
  1337. le = 0x7F;
  1338. break;
  1339. }
  1340. {
  1341. REG_LOCAL_IRQ_SAVE;
  1342. pChipcHw->VPMPhaseCtrl1 &=
  1343. ~((chipcHw_REG_VPM_PHASE_VALUE_GE_MASK <<
  1344. chipcHw_REG_VPM_PHASE_VALUE_GE_SHIFT)
  1345. || (chipcHw_REG_VPM_PHASE_VALUE_LE_MASK <<
  1346. chipcHw_REG_VPM_PHASE_VALUE_LE_SHIFT));
  1347. pChipcHw->VPMPhaseCtrl1 |=
  1348. ((ge << chipcHw_REG_VPM_PHASE_VALUE_GE_SHIFT)
  1349. || (le << chipcHw_REG_VPM_PHASE_VALUE_LE_SHIFT));
  1350. REG_LOCAL_IRQ_RESTORE;
  1351. }
  1352. }
  1353. /****************************************************************************/
  1354. /**
  1355. * @brief Checks DDR phase aligned status done by HW
  1356. *
  1357. * @return 1: When aligned
  1358. * 0: When not aligned
  1359. */
  1360. /****************************************************************************/
  1361. static inline uint32_t chipcHw_isDdrHwPhaseAligned(void)
  1362. {
  1363. return (pChipcHw->
  1364. PhaseAlignStatus & chipcHw_REG_DDR_PHASE_ALIGNED) ? 1 : 0;
  1365. }
  1366. /****************************************************************************/
  1367. /**
  1368. * @brief Checks VPM phase aligned status done by HW
  1369. *
  1370. * @return 1: When aligned
  1371. * 0: When not aligned
  1372. */
  1373. /****************************************************************************/
  1374. static inline uint32_t chipcHw_isVpmHwPhaseAligned(void)
  1375. {
  1376. return (pChipcHw->
  1377. PhaseAlignStatus & chipcHw_REG_VPM_PHASE_ALIGNED) ? 1 : 0;
  1378. }
  1379. /****************************************************************************/
  1380. /**
  1381. * @brief Get DDR phase aligned status done by HW
  1382. *
  1383. */
  1384. /****************************************************************************/
  1385. static inline uint32_t chipcHw_getDdrHwPhaseAlignStatus(void)
  1386. {
  1387. return (pChipcHw->
  1388. PhaseAlignStatus & chipcHw_REG_DDR_PHASE_STATUS_MASK) >>
  1389. chipcHw_REG_DDR_PHASE_STATUS_SHIFT;
  1390. }
  1391. /****************************************************************************/
  1392. /**
  1393. * @brief Get VPM phase aligned status done by HW
  1394. *
  1395. */
  1396. /****************************************************************************/
  1397. static inline uint32_t chipcHw_getVpmHwPhaseAlignStatus(void)
  1398. {
  1399. return (pChipcHw->
  1400. PhaseAlignStatus & chipcHw_REG_VPM_PHASE_STATUS_MASK) >>
  1401. chipcHw_REG_VPM_PHASE_STATUS_SHIFT;
  1402. }
  1403. /****************************************************************************/
  1404. /**
  1405. * @brief Get DDR phase control value
  1406. *
  1407. */
  1408. /****************************************************************************/
  1409. static inline uint32_t chipcHw_getDdrPhaseControl(void)
  1410. {
  1411. return (pChipcHw->
  1412. PhaseAlignStatus & chipcHw_REG_DDR_PHASE_CTRL_MASK) >>
  1413. chipcHw_REG_DDR_PHASE_CTRL_SHIFT;
  1414. }
  1415. /****************************************************************************/
  1416. /**
  1417. * @brief Get VPM phase control value
  1418. *
  1419. */
  1420. /****************************************************************************/
  1421. static inline uint32_t chipcHw_getVpmPhaseControl(void)
  1422. {
  1423. return (pChipcHw->
  1424. PhaseAlignStatus & chipcHw_REG_VPM_PHASE_CTRL_MASK) >>
  1425. chipcHw_REG_VPM_PHASE_CTRL_SHIFT;
  1426. }
  1427. /****************************************************************************/
  1428. /**
  1429. * @brief DDR phase alignment timeout count
  1430. *
  1431. * @note If HW fails to perform the phase alignment, it will trigger
  1432. * a DDR phase alignment timeout interrupt.
  1433. */
  1434. /****************************************************************************/
  1435. static inline void chipcHw_ddrHwPhaseAlignTimeout(uint32_t busCycle)
  1436. {
  1437. REG_LOCAL_IRQ_SAVE;
  1438. pChipcHw->DDRPhaseCtrl2 &=
  1439. ~(chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_MASK <<
  1440. chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_SHIFT);
  1441. pChipcHw->DDRPhaseCtrl2 |=
  1442. (busCycle & chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_MASK) <<
  1443. chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_SHIFT;
  1444. REG_LOCAL_IRQ_RESTORE;
  1445. }
  1446. /****************************************************************************/
  1447. /**
  1448. * @brief VPM phase alignment timeout count
  1449. *
  1450. * @note If HW fails to perform the phase alignment, it will trigger
  1451. * a VPM phase alignment timeout interrupt.
  1452. */
  1453. /****************************************************************************/
  1454. static inline void chipcHw_vpmHwPhaseAlignTimeout(uint32_t busCycle)
  1455. {
  1456. REG_LOCAL_IRQ_SAVE;
  1457. pChipcHw->VPMPhaseCtrl2 &=
  1458. ~(chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_MASK <<
  1459. chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_SHIFT);
  1460. pChipcHw->VPMPhaseCtrl2 |=
  1461. (busCycle & chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_MASK) <<
  1462. chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_SHIFT;
  1463. REG_LOCAL_IRQ_RESTORE;
  1464. }
  1465. /****************************************************************************/
  1466. /**
  1467. * @brief Clear DDR phase alignment timeout interrupt
  1468. *
  1469. */
  1470. /****************************************************************************/
  1471. static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptClear(void)
  1472. {
  1473. REG_LOCAL_IRQ_SAVE;
  1474. /* Clear timeout interrupt service bit */
  1475. pChipcHw->DDRPhaseCtrl2 |= chipcHw_REG_DDR_INTR_SERVICED;
  1476. pChipcHw->DDRPhaseCtrl2 &= ~chipcHw_REG_DDR_INTR_SERVICED;
  1477. REG_LOCAL_IRQ_RESTORE;
  1478. }
  1479. /****************************************************************************/
  1480. /**
  1481. * @brief Clear VPM phase alignment timeout interrupt
  1482. *
  1483. */
  1484. /****************************************************************************/
  1485. static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptClear(void)
  1486. {
  1487. REG_LOCAL_IRQ_SAVE;
  1488. /* Clear timeout interrupt service bit */
  1489. pChipcHw->VPMPhaseCtrl2 |= chipcHw_REG_VPM_INTR_SERVICED;
  1490. pChipcHw->VPMPhaseCtrl2 &= ~chipcHw_REG_VPM_INTR_SERVICED;
  1491. REG_LOCAL_IRQ_RESTORE;
  1492. }
  1493. /****************************************************************************/
  1494. /**
  1495. * @brief DDR phase alignment timeout interrupt enable
  1496. *
  1497. */
  1498. /****************************************************************************/
  1499. static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptEnable(void)
  1500. {
  1501. REG_LOCAL_IRQ_SAVE;
  1502. chipcHw_ddrHwPhaseAlignTimeoutInterruptClear(); /* Recommended */
  1503. /* Enable timeout interrupt */
  1504. pChipcHw->DDRPhaseCtrl2 |= chipcHw_REG_DDR_TIMEOUT_INTR_ENABLE;
  1505. REG_LOCAL_IRQ_RESTORE;
  1506. }
  1507. /****************************************************************************/
  1508. /**
  1509. * @brief VPM phase alignment timeout interrupt enable
  1510. *
  1511. */
  1512. /****************************************************************************/
  1513. static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptEnable(void)
  1514. {
  1515. REG_LOCAL_IRQ_SAVE;
  1516. chipcHw_vpmHwPhaseAlignTimeoutInterruptClear(); /* Recommended */
  1517. /* Enable timeout interrupt */
  1518. pChipcHw->VPMPhaseCtrl2 |= chipcHw_REG_VPM_TIMEOUT_INTR_ENABLE;
  1519. REG_LOCAL_IRQ_RESTORE;
  1520. }
  1521. /****************************************************************************/
  1522. /**
  1523. * @brief DDR phase alignment timeout interrupt disable
  1524. *
  1525. */
  1526. /****************************************************************************/
  1527. static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptDisable(void)
  1528. {
  1529. REG_LOCAL_IRQ_SAVE;
  1530. pChipcHw->DDRPhaseCtrl2 &= ~chipcHw_REG_DDR_TIMEOUT_INTR_ENABLE;
  1531. REG_LOCAL_IRQ_RESTORE;
  1532. }
  1533. /****************************************************************************/
  1534. /**
  1535. * @brief VPM phase alignment timeout interrupt disable
  1536. *
  1537. */
  1538. /****************************************************************************/
  1539. static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptDisable(void)
  1540. {
  1541. REG_LOCAL_IRQ_SAVE;
  1542. pChipcHw->VPMPhaseCtrl2 &= ~chipcHw_REG_VPM_TIMEOUT_INTR_ENABLE;
  1543. REG_LOCAL_IRQ_RESTORE;
  1544. }
  1545. #endif /* CHIPC_INLINE_H */