chipcHw_inline.h 49 KB

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