Path: blob/master/arch/arm/mach-bcmring/include/mach/csp/chipcHw_inline.h
10821 views
/*****************************************************************************1* Copyright 2003 - 2008 Broadcom Corporation. All rights reserved.2*3* Unless you and Broadcom execute a separate written software license4* agreement governing use of this software, this software is licensed to you5* under the terms of the GNU General Public License version 2, available at6* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").7*8* Notwithstanding the above, under no circumstances may you combine this9* software in any way with any other Broadcom software provided under a10* license other than the GPL, without Broadcom's express prior written11* consent.12*****************************************************************************/1314#ifndef CHIPC_INLINE_H15#define CHIPC_INLINE_H1617/* ---- Include Files ----------------------------------------------------- */1819#include <csp/errno.h>20#include <csp/reg.h>21#include <mach/csp/chipcHw_reg.h>22#include <mach/csp/chipcHw_def.h>2324/* ---- Private Constants and Types --------------------------------------- */25typedef enum {26chipcHw_OPTYPE_BYPASS, /* Bypass operation */27chipcHw_OPTYPE_OUTPUT /* Output operation */28} chipcHw_OPTYPE_e;2930/* ---- Public Constants and Types ---------------------------------------- */31/* ---- Public Variable Externs ------------------------------------------- */32/* ---- Public Function Prototypes ---------------------------------------- */33/* ---- Private Function Prototypes --------------------------------------- */34static inline void chipcHw_setClock(chipcHw_CLOCK_e clock,35chipcHw_OPTYPE_e type, int mode);3637/****************************************************************************/38/**39* @brief Get Numeric Chip ID40*41* This function returns Chip ID that includes the revison number42*43* @return Complete numeric Chip ID44*45*/46/****************************************************************************/47static inline uint32_t chipcHw_getChipId(void)48{49return pChipcHw->ChipId;50}5152/****************************************************************************/53/**54* @brief Enable Spread Spectrum55*56* @note chipcHw_Init() must be called earlier57*/58/****************************************************************************/59static inline void chipcHw_enableSpreadSpectrum(void)60{61if ((pChipcHw->62PLLPreDivider & chipcHw_REG_PLL_PREDIVIDER_NDIV_MODE_MASK) !=63chipcHw_REG_PLL_PREDIVIDER_NDIV_MODE_INTEGER) {64ddrcReg_PHY_ADDR_CTL_REGP->ssCfg =65(0xFFFF << ddrcReg_PHY_ADDR_SS_CFG_NDIV_AMPLITUDE_SHIFT) |66(ddrcReg_PHY_ADDR_SS_CFG_MIN_CYCLE_PER_TICK <<67ddrcReg_PHY_ADDR_SS_CFG_CYCLE_PER_TICK_SHIFT);68ddrcReg_PHY_ADDR_CTL_REGP->ssCtl |=69ddrcReg_PHY_ADDR_SS_CTRL_ENABLE;70}71}7273/****************************************************************************/74/**75* @brief Disable Spread Spectrum76*77*/78/****************************************************************************/79static inline void chipcHw_disableSpreadSpectrum(void)80{81ddrcReg_PHY_ADDR_CTL_REGP->ssCtl &= ~ddrcReg_PHY_ADDR_SS_CTRL_ENABLE;82}8384/****************************************************************************/85/**86* @brief Get Chip Product ID87*88* This function returns Chip Product ID89*90* @return Chip Product ID91*/92/****************************************************************************/93static inline uint32_t chipcHw_getChipProductId(void)94{95return (pChipcHw->96ChipId & chipcHw_REG_CHIPID_BASE_MASK) >>97chipcHw_REG_CHIPID_BASE_SHIFT;98}99100/****************************************************************************/101/**102* @brief Get revision number103*104* This function returns revision number of the chip105*106* @return Revision number107*/108/****************************************************************************/109static inline chipcHw_REV_NUMBER_e chipcHw_getChipRevisionNumber(void)110{111return pChipcHw->ChipId & chipcHw_REG_CHIPID_REV_MASK;112}113114/****************************************************************************/115/**116* @brief Enables bus interface clock117*118* Enables bus interface clock of various device119*120* @return void121*122* @note use chipcHw_REG_BUS_CLOCK_XXXX for mask123*/124/****************************************************************************/125static inline void chipcHw_busInterfaceClockEnable(uint32_t mask)126{127reg32_modify_or(&pChipcHw->BusIntfClock, mask);128}129130/****************************************************************************/131/**132* @brief Disables bus interface clock133*134* Disables bus interface clock of various device135*136* @return void137*138* @note use chipcHw_REG_BUS_CLOCK_XXXX139*/140/****************************************************************************/141static inline void chipcHw_busInterfaceClockDisable(uint32_t mask)142{143reg32_modify_and(&pChipcHw->BusIntfClock, ~mask);144}145146/****************************************************************************/147/**148* @brief Get status (enabled/disabled) of bus interface clock149*150* This function returns the status of devices' bus interface clock151*152* @return Bus interface clock153*154*/155/****************************************************************************/156static inline uint32_t chipcHw_getBusInterfaceClockStatus(void)157{158return pChipcHw->BusIntfClock;159}160161/****************************************************************************/162/**163* @brief Enables various audio channels164*165* Enables audio channel166*167* @return void168*169* @note use chipcHw_REG_AUDIO_CHANNEL_XXXXXX170*/171/****************************************************************************/172static inline void chipcHw_audioChannelEnable(uint32_t mask)173{174reg32_modify_or(&pChipcHw->AudioEnable, mask);175}176177/****************************************************************************/178/**179* @brief Disables various audio channels180*181* Disables audio channel182*183* @return void184*185* @note use chipcHw_REG_AUDIO_CHANNEL_XXXXXX186*/187/****************************************************************************/188static inline void chipcHw_audioChannelDisable(uint32_t mask)189{190reg32_modify_and(&pChipcHw->AudioEnable, ~mask);191}192193/****************************************************************************/194/**195* @brief Soft resets devices196*197* Soft resets various devices198*199* @return void200*201* @note use chipcHw_REG_SOFT_RESET_XXXXXX defines202*/203/****************************************************************************/204static inline void chipcHw_softReset(uint64_t mask)205{206chipcHw_softResetEnable(mask);207chipcHw_softResetDisable(mask);208}209210static inline void chipcHw_softResetDisable(uint64_t mask)211{212uint32_t ctrl1 = (uint32_t) mask;213uint32_t ctrl2 = (uint32_t) (mask >> 32);214215/* Deassert module soft reset */216REG_LOCAL_IRQ_SAVE;217pChipcHw->SoftReset1 ^= ctrl1;218pChipcHw->SoftReset2 ^= (ctrl2 & (~chipcHw_REG_SOFT_RESET_UNHOLD_MASK));219REG_LOCAL_IRQ_RESTORE;220}221222static inline void chipcHw_softResetEnable(uint64_t mask)223{224uint32_t ctrl1 = (uint32_t) mask;225uint32_t ctrl2 = (uint32_t) (mask >> 32);226uint32_t unhold = 0;227228REG_LOCAL_IRQ_SAVE;229pChipcHw->SoftReset1 |= ctrl1;230/* Mask out unhold request bits */231pChipcHw->SoftReset2 |= (ctrl2 & (~chipcHw_REG_SOFT_RESET_UNHOLD_MASK));232233/* Process unhold requests */234if (ctrl2 & chipcHw_REG_SOFT_RESET_VPM_GLOBAL_UNHOLD) {235unhold = chipcHw_REG_SOFT_RESET_VPM_GLOBAL_HOLD;236}237238if (ctrl2 & chipcHw_REG_SOFT_RESET_VPM_UNHOLD) {239unhold |= chipcHw_REG_SOFT_RESET_VPM_HOLD;240}241242if (ctrl2 & chipcHw_REG_SOFT_RESET_ARM_UNHOLD) {243unhold |= chipcHw_REG_SOFT_RESET_ARM_HOLD;244}245246if (unhold) {247/* Make sure unhold request is effective */248pChipcHw->SoftReset1 &= ~unhold;249}250REG_LOCAL_IRQ_RESTORE;251}252253/****************************************************************************/254/**255* @brief Configures misc CHIP functionality256*257* Configures CHIP functionality258*259* @return void260*261* @note use chipcHw_REG_MISC_CTRL_XXXXXX262*/263/****************************************************************************/264static inline void chipcHw_miscControl(uint32_t mask)265{266reg32_write(&pChipcHw->MiscCtrl, mask);267}268269static inline void chipcHw_miscControlDisable(uint32_t mask)270{271reg32_modify_and(&pChipcHw->MiscCtrl, ~mask);272}273274static inline void chipcHw_miscControlEnable(uint32_t mask)275{276reg32_modify_or(&pChipcHw->MiscCtrl, mask);277}278279/****************************************************************************/280/**281* @brief Set OTP options282*283* Set OTP options284*285* @return void286*287* @note use chipcHw_REG_OTP_XXXXXX288*/289/****************************************************************************/290static inline void chipcHw_setOTPOption(uint64_t mask)291{292uint32_t ctrl1 = (uint32_t) mask;293uint32_t ctrl2 = (uint32_t) (mask >> 32);294295reg32_modify_or(&pChipcHw->SoftOTP1, ctrl1);296reg32_modify_or(&pChipcHw->SoftOTP2, ctrl2);297}298299/****************************************************************************/300/**301* @brief Get sticky bits302*303* @return Sticky bit options of type chipcHw_REG_STICKY_XXXXXX304*305*/306/****************************************************************************/307static inline uint32_t chipcHw_getStickyBits(void)308{309return pChipcHw->Sticky;310}311312/****************************************************************************/313/**314* @brief Set sticky bits315*316* @return void317*318* @note use chipcHw_REG_STICKY_XXXXXX319*/320/****************************************************************************/321static inline void chipcHw_setStickyBits(uint32_t mask)322{323uint32_t bits = 0;324325REG_LOCAL_IRQ_SAVE;326if (mask & chipcHw_REG_STICKY_POR_BROM) {327bits |= chipcHw_REG_STICKY_POR_BROM;328} else {329uint32_t sticky;330sticky = pChipcHw->Sticky;331332if ((mask & chipcHw_REG_STICKY_BOOT_DONE)333&& (sticky & chipcHw_REG_STICKY_BOOT_DONE) == 0) {334bits |= chipcHw_REG_STICKY_BOOT_DONE;335}336if ((mask & chipcHw_REG_STICKY_GENERAL_1)337&& (sticky & chipcHw_REG_STICKY_GENERAL_1) == 0) {338bits |= chipcHw_REG_STICKY_GENERAL_1;339}340if ((mask & chipcHw_REG_STICKY_GENERAL_2)341&& (sticky & chipcHw_REG_STICKY_GENERAL_2) == 0) {342bits |= chipcHw_REG_STICKY_GENERAL_2;343}344if ((mask & chipcHw_REG_STICKY_GENERAL_3)345&& (sticky & chipcHw_REG_STICKY_GENERAL_3) == 0) {346bits |= chipcHw_REG_STICKY_GENERAL_3;347}348if ((mask & chipcHw_REG_STICKY_GENERAL_4)349&& (sticky & chipcHw_REG_STICKY_GENERAL_4) == 0) {350bits |= chipcHw_REG_STICKY_GENERAL_4;351}352if ((mask & chipcHw_REG_STICKY_GENERAL_5)353&& (sticky & chipcHw_REG_STICKY_GENERAL_5) == 0) {354bits |= chipcHw_REG_STICKY_GENERAL_5;355}356}357pChipcHw->Sticky = bits;358REG_LOCAL_IRQ_RESTORE;359}360361/****************************************************************************/362/**363* @brief Clear sticky bits364*365* @return void366*367* @note use chipcHw_REG_STICKY_XXXXXX368*/369/****************************************************************************/370static inline void chipcHw_clearStickyBits(uint32_t mask)371{372uint32_t bits = 0;373374REG_LOCAL_IRQ_SAVE;375if (mask &376(chipcHw_REG_STICKY_BOOT_DONE | chipcHw_REG_STICKY_GENERAL_1 |377chipcHw_REG_STICKY_GENERAL_2 | chipcHw_REG_STICKY_GENERAL_3 |378chipcHw_REG_STICKY_GENERAL_4 | chipcHw_REG_STICKY_GENERAL_5)) {379uint32_t sticky = pChipcHw->Sticky;380381if ((mask & chipcHw_REG_STICKY_BOOT_DONE)382&& (sticky & chipcHw_REG_STICKY_BOOT_DONE)) {383bits = chipcHw_REG_STICKY_BOOT_DONE;384mask &= ~chipcHw_REG_STICKY_BOOT_DONE;385}386if ((mask & chipcHw_REG_STICKY_GENERAL_1)387&& (sticky & chipcHw_REG_STICKY_GENERAL_1)) {388bits |= chipcHw_REG_STICKY_GENERAL_1;389mask &= ~chipcHw_REG_STICKY_GENERAL_1;390}391if ((mask & chipcHw_REG_STICKY_GENERAL_2)392&& (sticky & chipcHw_REG_STICKY_GENERAL_2)) {393bits |= chipcHw_REG_STICKY_GENERAL_2;394mask &= ~chipcHw_REG_STICKY_GENERAL_2;395}396if ((mask & chipcHw_REG_STICKY_GENERAL_3)397&& (sticky & chipcHw_REG_STICKY_GENERAL_3)) {398bits |= chipcHw_REG_STICKY_GENERAL_3;399mask &= ~chipcHw_REG_STICKY_GENERAL_3;400}401if ((mask & chipcHw_REG_STICKY_GENERAL_4)402&& (sticky & chipcHw_REG_STICKY_GENERAL_4)) {403bits |= chipcHw_REG_STICKY_GENERAL_4;404mask &= ~chipcHw_REG_STICKY_GENERAL_4;405}406if ((mask & chipcHw_REG_STICKY_GENERAL_5)407&& (sticky & chipcHw_REG_STICKY_GENERAL_5)) {408bits |= chipcHw_REG_STICKY_GENERAL_5;409mask &= ~chipcHw_REG_STICKY_GENERAL_5;410}411}412pChipcHw->Sticky = bits | mask;413REG_LOCAL_IRQ_RESTORE;414}415416/****************************************************************************/417/**418* @brief Get software strap value419*420* Retrieves software strap value421*422* @return Software strap value423*424*/425/****************************************************************************/426static inline uint32_t chipcHw_getSoftStraps(void)427{428return pChipcHw->SoftStraps;429}430431/****************************************************************************/432/**433* @brief Set software override strap options434*435* set software override strap options436*437* @return nothing438*439*/440/****************************************************************************/441static inline void chipcHw_setSoftStraps(uint32_t strapOptions)442{443reg32_write(&pChipcHw->SoftStraps, strapOptions);444}445446/****************************************************************************/447/**448* @brief Get Pin Strap Options449*450* This function returns the raw boot strap options451*452* @return strap options453*454*/455/****************************************************************************/456static inline uint32_t chipcHw_getPinStraps(void)457{458return pChipcHw->PinStraps;459}460461/****************************************************************************/462/**463* @brief Get Valid Strap Options464*465* This function returns the valid raw boot strap options466*467* @return strap options468*469*/470/****************************************************************************/471static inline uint32_t chipcHw_getValidStraps(void)472{473uint32_t softStraps;474475/*476** Always return the SoftStraps - bootROM calls chipcHw_initValidStraps477** which copies HW straps to soft straps if there is no override478*/479softStraps = chipcHw_getSoftStraps();480481return softStraps;482}483484/****************************************************************************/485/**486* @brief Initialize valid pin strap options487*488* Retrieves valid pin strap options by copying HW strap options to soft register489* (if chipcHw_STRAPS_SOFT_OVERRIDE not set)490*491* @return nothing492*493*/494/****************************************************************************/495static inline void chipcHw_initValidStraps(void)496{497uint32_t softStraps;498499REG_LOCAL_IRQ_SAVE;500softStraps = chipcHw_getSoftStraps();501502if ((softStraps & chipcHw_STRAPS_SOFT_OVERRIDE) == 0) {503/* Copy HW straps to software straps */504chipcHw_setSoftStraps(chipcHw_getPinStraps());505}506REG_LOCAL_IRQ_RESTORE;507}508509/****************************************************************************/510/**511* @brief Get boot device512*513* This function returns the device type used in booting the system514*515* @return Boot device of type chipcHw_BOOT_DEVICE516*517*/518/****************************************************************************/519static inline chipcHw_BOOT_DEVICE_e chipcHw_getBootDevice(void)520{521return chipcHw_getValidStraps() & chipcHw_STRAPS_BOOT_DEVICE_MASK;522}523524/****************************************************************************/525/**526* @brief Get boot mode527*528* This function returns the way the system was booted529*530* @return Boot mode of type chipcHw_BOOT_MODE531*532*/533/****************************************************************************/534static inline chipcHw_BOOT_MODE_e chipcHw_getBootMode(void)535{536return chipcHw_getValidStraps() & chipcHw_STRAPS_BOOT_MODE_MASK;537}538539/****************************************************************************/540/**541* @brief Get NAND flash page size542*543* This function returns the NAND device page size544*545* @return Boot NAND device page size546*547*/548/****************************************************************************/549static inline chipcHw_NAND_PAGESIZE_e chipcHw_getNandPageSize(void)550{551return chipcHw_getValidStraps() & chipcHw_STRAPS_NAND_PAGESIZE_MASK;552}553554/****************************************************************************/555/**556* @brief Get NAND flash address cycle configuration557*558* This function returns the NAND flash address cycle configuration559*560* @return 0 = Do not extra address cycle, 1 = Add extra cycle561*562*/563/****************************************************************************/564static inline int chipcHw_getNandExtraCycle(void)565{566if (chipcHw_getValidStraps() & chipcHw_STRAPS_NAND_EXTRA_CYCLE) {567return 1;568} else {569return 0;570}571}572573/****************************************************************************/574/**575* @brief Activates PIF interface576*577* This function activates PIF interface by taking control of LCD pins578*579* @note580* When activated, LCD pins will be defined as follows for PIF operation581*582* CLD[17:0] = pif_data[17:0]583* CLD[23:18] = pif_address[5:0]584* CLPOWER = pif_wr_str585* CLCP = pif_rd_str586* CLAC = pif_hat1587* CLFP = pif_hrdy1588* CLLP = pif_hat2589* GPIO[42] = pif_hrdy2590*591* In PIF mode, "pif_hrdy2" overrides other shared function for GPIO[42] pin592*593*/594/****************************************************************************/595static inline void chipcHw_activatePifInterface(void)596{597reg32_write(&pChipcHw->LcdPifMode, chipcHw_REG_PIF_PIN_ENABLE);598}599600/****************************************************************************/601/**602* @brief Activates LCD interface603*604* This function activates LCD interface605*606* @note607* When activated, LCD pins will be defined as follows608*609* CLD[17:0] = LCD data610* CLD[23:18] = LCD data611* CLPOWER = LCD power612* CLCP =613* CLAC = LCD ack614* CLFP =615* CLLP =616*/617/****************************************************************************/618static inline void chipcHw_activateLcdInterface(void)619{620reg32_write(&pChipcHw->LcdPifMode, chipcHw_REG_LCD_PIN_ENABLE);621}622623/****************************************************************************/624/**625* @brief Deactivates PIF/LCD interface626*627* This function deactivates PIF/LCD interface628*629* @note630* When deactivated LCD pins will be in rti-stated631*632*/633/****************************************************************************/634static inline void chipcHw_deactivatePifLcdInterface(void)635{636reg32_write(&pChipcHw->LcdPifMode, 0);637}638639/****************************************************************************/640/**641* @brief Select GE2642*643* This function select GE2 as the graphic engine644*645*/646/****************************************************************************/647static inline void chipcHw_selectGE2(void)648{649reg32_modify_and(&pChipcHw->MiscCtrl, ~chipcHw_REG_MISC_CTRL_GE_SEL);650}651652/****************************************************************************/653/**654* @brief Select GE3655*656* This function select GE3 as the graphic engine657*658*/659/****************************************************************************/660static inline void chipcHw_selectGE3(void)661{662reg32_modify_or(&pChipcHw->MiscCtrl, chipcHw_REG_MISC_CTRL_GE_SEL);663}664665/****************************************************************************/666/**667* @brief Get to know the configuration of GPIO pin668*669*/670/****************************************************************************/671static inline chipcHw_GPIO_FUNCTION_e chipcHw_getGpioPinFunction(int pin)672{673return (*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) &674(chipcHw_REG_GPIO_MUX_MASK <<675chipcHw_REG_GPIO_MUX_POSITION(pin))) >>676chipcHw_REG_GPIO_MUX_POSITION(pin);677}678679/****************************************************************************/680/**681* @brief Configure GPIO pin function682*683*/684/****************************************************************************/685static inline void chipcHw_setGpioPinFunction(int pin,686chipcHw_GPIO_FUNCTION_e func)687{688REG_LOCAL_IRQ_SAVE;689*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) &=690~(chipcHw_REG_GPIO_MUX_MASK << chipcHw_REG_GPIO_MUX_POSITION(pin));691*((uint32_t *) chipcHw_REG_GPIO_MUX(pin)) |=692func << chipcHw_REG_GPIO_MUX_POSITION(pin);693REG_LOCAL_IRQ_RESTORE;694}695696/****************************************************************************/697/**698* @brief Set Pin slew rate699*700* This function sets the slew of individual pin701*702*/703/****************************************************************************/704static inline void chipcHw_setPinSlewRate(uint32_t pin,705chipcHw_PIN_SLEW_RATE_e slewRate)706{707REG_LOCAL_IRQ_SAVE;708*((uint32_t *) chipcHw_REG_SLEW_RATE(pin)) &=709~(chipcHw_REG_SLEW_RATE_MASK <<710chipcHw_REG_SLEW_RATE_POSITION(pin));711*((uint32_t *) chipcHw_REG_SLEW_RATE(pin)) |=712(uint32_t) slewRate << chipcHw_REG_SLEW_RATE_POSITION(pin);713REG_LOCAL_IRQ_RESTORE;714}715716/****************************************************************************/717/**718* @brief Set Pin output drive current719*720* This function sets output drive current of individual pin721*722* Note: Avoid the use of the word 'current' since linux headers define this723* to be the current task.724*/725/****************************************************************************/726static inline void chipcHw_setPinOutputCurrent(uint32_t pin,727chipcHw_PIN_CURRENT_STRENGTH_e728curr)729{730REG_LOCAL_IRQ_SAVE;731*((uint32_t *) chipcHw_REG_CURRENT(pin)) &=732~(chipcHw_REG_CURRENT_MASK << chipcHw_REG_CURRENT_POSITION(pin));733*((uint32_t *) chipcHw_REG_CURRENT(pin)) |=734(uint32_t) curr << chipcHw_REG_CURRENT_POSITION(pin);735REG_LOCAL_IRQ_RESTORE;736}737738/****************************************************************************/739/**740* @brief Set Pin pullup register741*742* This function sets pullup register of individual pin743*744*/745/****************************************************************************/746static inline void chipcHw_setPinPullup(uint32_t pin, chipcHw_PIN_PULL_e pullup)747{748REG_LOCAL_IRQ_SAVE;749*((uint32_t *) chipcHw_REG_PULLUP(pin)) &=750~(chipcHw_REG_PULLUP_MASK << chipcHw_REG_PULLUP_POSITION(pin));751*((uint32_t *) chipcHw_REG_PULLUP(pin)) |=752(uint32_t) pullup << chipcHw_REG_PULLUP_POSITION(pin);753REG_LOCAL_IRQ_RESTORE;754}755756/****************************************************************************/757/**758* @brief Set Pin input type759*760* This function sets input type of individual pin761*762*/763/****************************************************************************/764static inline void chipcHw_setPinInputType(uint32_t pin,765chipcHw_PIN_INPUTTYPE_e inputType)766{767REG_LOCAL_IRQ_SAVE;768*((uint32_t *) chipcHw_REG_INPUTTYPE(pin)) &=769~(chipcHw_REG_INPUTTYPE_MASK <<770chipcHw_REG_INPUTTYPE_POSITION(pin));771*((uint32_t *) chipcHw_REG_INPUTTYPE(pin)) |=772(uint32_t) inputType << chipcHw_REG_INPUTTYPE_POSITION(pin);773REG_LOCAL_IRQ_RESTORE;774}775776/****************************************************************************/777/**778* @brief Power up the USB PHY779*780* This function powers up the USB PHY781*782*/783/****************************************************************************/784static inline void chipcHw_powerUpUsbPhy(void)785{786reg32_modify_and(&pChipcHw->MiscCtrl,787chipcHw_REG_MISC_CTRL_USB_POWERON);788}789790/****************************************************************************/791/**792* @brief Power down the USB PHY793*794* This function powers down the USB PHY795*796*/797/****************************************************************************/798static inline void chipcHw_powerDownUsbPhy(void)799{800reg32_modify_or(&pChipcHw->MiscCtrl,801chipcHw_REG_MISC_CTRL_USB_POWEROFF);802}803804/****************************************************************************/805/**806* @brief Set the 2nd USB as host807*808* This function sets the 2nd USB as host809*810*/811/****************************************************************************/812static inline void chipcHw_setUsbHost(void)813{814reg32_modify_or(&pChipcHw->MiscCtrl,815chipcHw_REG_MISC_CTRL_USB_MODE_HOST);816}817818/****************************************************************************/819/**820* @brief Set the 2nd USB as device821*822* This function sets the 2nd USB as device823*824*/825/****************************************************************************/826static inline void chipcHw_setUsbDevice(void)827{828reg32_modify_and(&pChipcHw->MiscCtrl,829chipcHw_REG_MISC_CTRL_USB_MODE_DEVICE);830}831832/****************************************************************************/833/**834* @brief Lower layer function to enable/disable a clock of a certain device835*836* This function enables/disables a core clock837*838*/839/****************************************************************************/840static inline void chipcHw_setClock(chipcHw_CLOCK_e clock,841chipcHw_OPTYPE_e type, int mode)842{843volatile uint32_t *pPLLReg = (uint32_t *) 0x0;844volatile uint32_t *pClockCtrl = (uint32_t *) 0x0;845846switch (clock) {847case chipcHw_CLOCK_DDR:848pPLLReg = &pChipcHw->DDRClock;849break;850case chipcHw_CLOCK_ARM:851pPLLReg = &pChipcHw->ARMClock;852break;853case chipcHw_CLOCK_ESW:854pPLLReg = &pChipcHw->ESWClock;855break;856case chipcHw_CLOCK_VPM:857pPLLReg = &pChipcHw->VPMClock;858break;859case chipcHw_CLOCK_ESW125:860pPLLReg = &pChipcHw->ESW125Clock;861break;862case chipcHw_CLOCK_UART:863pPLLReg = &pChipcHw->UARTClock;864break;865case chipcHw_CLOCK_SDIO0:866pPLLReg = &pChipcHw->SDIO0Clock;867break;868case chipcHw_CLOCK_SDIO1:869pPLLReg = &pChipcHw->SDIO1Clock;870break;871case chipcHw_CLOCK_SPI:872pPLLReg = &pChipcHw->SPIClock;873break;874case chipcHw_CLOCK_ETM:875pPLLReg = &pChipcHw->ETMClock;876break;877case chipcHw_CLOCK_USB:878pPLLReg = &pChipcHw->USBClock;879if (type == chipcHw_OPTYPE_OUTPUT) {880if (mode) {881reg32_modify_and(pPLLReg,882~chipcHw_REG_PLL_CLOCK_POWER_DOWN);883} else {884reg32_modify_or(pPLLReg,885chipcHw_REG_PLL_CLOCK_POWER_DOWN);886}887}888break;889case chipcHw_CLOCK_LCD:890pPLLReg = &pChipcHw->LCDClock;891if (type == chipcHw_OPTYPE_OUTPUT) {892if (mode) {893reg32_modify_and(pPLLReg,894~chipcHw_REG_PLL_CLOCK_POWER_DOWN);895} else {896reg32_modify_or(pPLLReg,897chipcHw_REG_PLL_CLOCK_POWER_DOWN);898}899}900break;901case chipcHw_CLOCK_APM:902pPLLReg = &pChipcHw->APMClock;903if (type == chipcHw_OPTYPE_OUTPUT) {904if (mode) {905reg32_modify_and(pPLLReg,906~chipcHw_REG_PLL_CLOCK_POWER_DOWN);907} else {908reg32_modify_or(pPLLReg,909chipcHw_REG_PLL_CLOCK_POWER_DOWN);910}911}912break;913case chipcHw_CLOCK_BUS:914pClockCtrl = &pChipcHw->ACLKClock;915break;916case chipcHw_CLOCK_OTP:917pClockCtrl = &pChipcHw->OTPClock;918break;919case chipcHw_CLOCK_I2C:920pClockCtrl = &pChipcHw->I2CClock;921break;922case chipcHw_CLOCK_I2S0:923pClockCtrl = &pChipcHw->I2S0Clock;924break;925case chipcHw_CLOCK_RTBUS:926pClockCtrl = &pChipcHw->RTBUSClock;927break;928case chipcHw_CLOCK_APM100:929pClockCtrl = &pChipcHw->APM100Clock;930break;931case chipcHw_CLOCK_TSC:932pClockCtrl = &pChipcHw->TSCClock;933break;934case chipcHw_CLOCK_LED:935pClockCtrl = &pChipcHw->LEDClock;936break;937case chipcHw_CLOCK_I2S1:938pClockCtrl = &pChipcHw->I2S1Clock;939break;940}941942if (pPLLReg) {943switch (type) {944case chipcHw_OPTYPE_OUTPUT:945/* PLL clock output enable/disable */946if (mode) {947if (clock == chipcHw_CLOCK_DDR) {948/* DDR clock enable is inverted */949reg32_modify_and(pPLLReg,950~chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);951} else {952reg32_modify_or(pPLLReg,953chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);954}955} else {956if (clock == chipcHw_CLOCK_DDR) {957/* DDR clock disable is inverted */958reg32_modify_or(pPLLReg,959chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);960} else {961reg32_modify_and(pPLLReg,962~chipcHw_REG_PLL_CLOCK_OUTPUT_ENABLE);963}964}965break;966case chipcHw_OPTYPE_BYPASS:967/* PLL clock bypass enable/disable */968if (mode) {969reg32_modify_or(pPLLReg,970chipcHw_REG_PLL_CLOCK_BYPASS_SELECT);971} else {972reg32_modify_and(pPLLReg,973~chipcHw_REG_PLL_CLOCK_BYPASS_SELECT);974}975break;976}977} else if (pClockCtrl) {978switch (type) {979case chipcHw_OPTYPE_OUTPUT:980if (mode) {981reg32_modify_or(pClockCtrl,982chipcHw_REG_DIV_CLOCK_OUTPUT_ENABLE);983} else {984reg32_modify_and(pClockCtrl,985~chipcHw_REG_DIV_CLOCK_OUTPUT_ENABLE);986}987break;988case chipcHw_OPTYPE_BYPASS:989if (mode) {990reg32_modify_or(pClockCtrl,991chipcHw_REG_DIV_CLOCK_BYPASS_SELECT);992} else {993reg32_modify_and(pClockCtrl,994~chipcHw_REG_DIV_CLOCK_BYPASS_SELECT);995}996break;997}998}999}10001001/****************************************************************************/1002/**1003* @brief Disables a core clock of a certain device1004*1005* This function disables a core clock1006*1007* @note no change in power consumption1008*/1009/****************************************************************************/1010static inline void chipcHw_setClockDisable(chipcHw_CLOCK_e clock)1011{10121013/* Disable output of the clock */1014chipcHw_setClock(clock, chipcHw_OPTYPE_OUTPUT, 0);1015}10161017/****************************************************************************/1018/**1019* @brief Enable a core clock of a certain device1020*1021* This function enables a core clock1022*1023* @note no change in power consumption1024*/1025/****************************************************************************/1026static inline void chipcHw_setClockEnable(chipcHw_CLOCK_e clock)1027{10281029/* Enable output of the clock */1030chipcHw_setClock(clock, chipcHw_OPTYPE_OUTPUT, 1);1031}10321033/****************************************************************************/1034/**1035* @brief Enables bypass clock of a certain device1036*1037* This function enables bypass clock1038*1039* @note Doesnot affect the bus interface clock1040*/1041/****************************************************************************/1042static inline void chipcHw_bypassClockEnable(chipcHw_CLOCK_e clock)1043{1044/* Enable bypass clock */1045chipcHw_setClock(clock, chipcHw_OPTYPE_BYPASS, 1);1046}10471048/****************************************************************************/1049/**1050* @brief Disabled bypass clock of a certain device1051*1052* This function disables bypass clock1053*1054* @note Doesnot affect the bus interface clock1055*/1056/****************************************************************************/1057static inline void chipcHw_bypassClockDisable(chipcHw_CLOCK_e clock)1058{1059/* Disable bypass clock */1060chipcHw_setClock(clock, chipcHw_OPTYPE_BYPASS, 0);10611062}10631064/****************************************************************************/1065/** @brief Checks if software strap is enabled1066*1067* @return 1 : When enable1068* 0 : When disable1069*/1070/****************************************************************************/1071static inline int chipcHw_isSoftwareStrapsEnable(void)1072{1073return pChipcHw->SoftStraps & 0x00000001;1074}10751076/****************************************************************************/1077/** @brief Enable software strap1078*/1079/****************************************************************************/1080static inline void chipcHw_softwareStrapsEnable(void)1081{1082reg32_modify_or(&pChipcHw->SoftStraps, 0x00000001);1083}10841085/****************************************************************************/1086/** @brief Disable software strap1087*/1088/****************************************************************************/1089static inline void chipcHw_softwareStrapsDisable(void)1090{1091reg32_modify_and(&pChipcHw->SoftStraps, (~0x00000001));1092}10931094/****************************************************************************/1095/** @brief PLL test enable1096*/1097/****************************************************************************/1098static inline void chipcHw_pllTestEnable(void)1099{1100reg32_modify_or(&pChipcHw->PLLConfig,1101chipcHw_REG_PLL_CONFIG_TEST_ENABLE);1102}11031104/****************************************************************************/1105/** @brief PLL2 test enable1106*/1107/****************************************************************************/1108static inline void chipcHw_pll2TestEnable(void)1109{1110reg32_modify_or(&pChipcHw->PLLConfig2,1111chipcHw_REG_PLL_CONFIG_TEST_ENABLE);1112}11131114/****************************************************************************/1115/** @brief PLL test disable1116*/1117/****************************************************************************/1118static inline void chipcHw_pllTestDisable(void)1119{1120reg32_modify_and(&pChipcHw->PLLConfig,1121~chipcHw_REG_PLL_CONFIG_TEST_ENABLE);1122}11231124/****************************************************************************/1125/** @brief PLL2 test disable1126*/1127/****************************************************************************/1128static inline void chipcHw_pll2TestDisable(void)1129{1130reg32_modify_and(&pChipcHw->PLLConfig2,1131~chipcHw_REG_PLL_CONFIG_TEST_ENABLE);1132}11331134/****************************************************************************/1135/** @brief Get PLL test status1136*/1137/****************************************************************************/1138static inline int chipcHw_isPllTestEnable(void)1139{1140return pChipcHw->PLLConfig & chipcHw_REG_PLL_CONFIG_TEST_ENABLE;1141}11421143/****************************************************************************/1144/** @brief Get PLL2 test status1145*/1146/****************************************************************************/1147static inline int chipcHw_isPll2TestEnable(void)1148{1149return pChipcHw->PLLConfig2 & chipcHw_REG_PLL_CONFIG_TEST_ENABLE;1150}11511152/****************************************************************************/1153/** @brief PLL test select1154*/1155/****************************************************************************/1156static inline void chipcHw_pllTestSelect(uint32_t val)1157{1158REG_LOCAL_IRQ_SAVE;1159pChipcHw->PLLConfig &= ~chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK;1160pChipcHw->PLLConfig |=1161(val) << chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT;1162REG_LOCAL_IRQ_RESTORE;1163}11641165/****************************************************************************/1166/** @brief PLL2 test select1167*/1168/****************************************************************************/1169static inline void chipcHw_pll2TestSelect(uint32_t val)1170{11711172REG_LOCAL_IRQ_SAVE;1173pChipcHw->PLLConfig2 &= ~chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK;1174pChipcHw->PLLConfig2 |=1175(val) << chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT;1176REG_LOCAL_IRQ_RESTORE;1177}11781179/****************************************************************************/1180/** @brief Get PLL test selected option1181*/1182/****************************************************************************/1183static inline uint8_t chipcHw_getPllTestSelected(void)1184{1185return (uint8_t) ((pChipcHw->1186PLLConfig & chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK)1187>> chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT);1188}11891190/****************************************************************************/1191/** @brief Get PLL2 test selected option1192*/1193/****************************************************************************/1194static inline uint8_t chipcHw_getPll2TestSelected(void)1195{1196return (uint8_t) ((pChipcHw->1197PLLConfig2 & chipcHw_REG_PLL_CONFIG_TEST_SELECT_MASK)1198>> chipcHw_REG_PLL_CONFIG_TEST_SELECT_SHIFT);1199}12001201/****************************************************************************/1202/**1203* @brief Disable the PLL11204*1205*/1206/****************************************************************************/1207static inline void chipcHw_pll1Disable(void)1208{1209REG_LOCAL_IRQ_SAVE;1210pChipcHw->PLLConfig |= chipcHw_REG_PLL_CONFIG_POWER_DOWN;1211REG_LOCAL_IRQ_RESTORE;1212}12131214/****************************************************************************/1215/**1216* @brief Disable the PLL21217*1218*/1219/****************************************************************************/1220static inline void chipcHw_pll2Disable(void)1221{1222REG_LOCAL_IRQ_SAVE;1223pChipcHw->PLLConfig2 |= chipcHw_REG_PLL_CONFIG_POWER_DOWN;1224REG_LOCAL_IRQ_RESTORE;1225}12261227/****************************************************************************/1228/**1229* @brief Enables DDR SW phase alignment interrupt1230*/1231/****************************************************************************/1232static inline void chipcHw_ddrPhaseAlignInterruptEnable(void)1233{1234REG_LOCAL_IRQ_SAVE;1235pChipcHw->Spare1 |= chipcHw_REG_SPARE1_DDR_PHASE_INTR_ENABLE;1236REG_LOCAL_IRQ_RESTORE;1237}12381239/****************************************************************************/1240/**1241* @brief Disables DDR SW phase alignment interrupt1242*/1243/****************************************************************************/1244static inline void chipcHw_ddrPhaseAlignInterruptDisable(void)1245{1246REG_LOCAL_IRQ_SAVE;1247pChipcHw->Spare1 &= ~chipcHw_REG_SPARE1_DDR_PHASE_INTR_ENABLE;1248REG_LOCAL_IRQ_RESTORE;1249}12501251/****************************************************************************/1252/**1253* @brief Set VPM SW phase alignment interrupt mode1254*1255* This function sets VPM phase alignment interrupt1256*/1257/****************************************************************************/1258static inline void1259chipcHw_vpmPhaseAlignInterruptMode(chipcHw_VPM_HW_PHASE_INTR_e mode)1260{1261REG_LOCAL_IRQ_SAVE;1262if (mode == chipcHw_VPM_HW_PHASE_INTR_DISABLE) {1263pChipcHw->Spare1 &= ~chipcHw_REG_SPARE1_VPM_PHASE_INTR_ENABLE;1264} else {1265pChipcHw->Spare1 |= chipcHw_REG_SPARE1_VPM_PHASE_INTR_ENABLE;1266}1267pChipcHw->VPMPhaseCtrl2 =1268(pChipcHw->1269VPMPhaseCtrl2 & ~(chipcHw_REG_VPM_INTR_SELECT_MASK <<1270chipcHw_REG_VPM_INTR_SELECT_SHIFT)) | mode;1271REG_LOCAL_IRQ_RESTORE;1272}12731274/****************************************************************************/1275/**1276* @brief Enable DDR phase alignment in software1277*1278*/1279/****************************************************************************/1280static inline void chipcHw_ddrSwPhaseAlignEnable(void)1281{1282REG_LOCAL_IRQ_SAVE;1283pChipcHw->DDRPhaseCtrl1 |= chipcHw_REG_DDR_SW_PHASE_CTRL_ENABLE;1284REG_LOCAL_IRQ_RESTORE;1285}12861287/****************************************************************************/1288/**1289* @brief Disable DDR phase alignment in software1290*1291*/1292/****************************************************************************/1293static inline void chipcHw_ddrSwPhaseAlignDisable(void)1294{1295REG_LOCAL_IRQ_SAVE;1296pChipcHw->DDRPhaseCtrl1 &= ~chipcHw_REG_DDR_SW_PHASE_CTRL_ENABLE;1297REG_LOCAL_IRQ_RESTORE;1298}12991300/****************************************************************************/1301/**1302* @brief Enable DDR phase alignment in hardware1303*1304*/1305/****************************************************************************/1306static inline void chipcHw_ddrHwPhaseAlignEnable(void)1307{1308REG_LOCAL_IRQ_SAVE;1309pChipcHw->DDRPhaseCtrl1 |= chipcHw_REG_DDR_HW_PHASE_CTRL_ENABLE;1310REG_LOCAL_IRQ_RESTORE;1311}13121313/****************************************************************************/1314/**1315* @brief Disable DDR phase alignment in hardware1316*1317*/1318/****************************************************************************/1319static inline void chipcHw_ddrHwPhaseAlignDisable(void)1320{1321REG_LOCAL_IRQ_SAVE;1322pChipcHw->DDRPhaseCtrl1 &= ~chipcHw_REG_DDR_HW_PHASE_CTRL_ENABLE;1323REG_LOCAL_IRQ_RESTORE;1324}13251326/****************************************************************************/1327/**1328* @brief Enable VPM phase alignment in software1329*1330*/1331/****************************************************************************/1332static inline void chipcHw_vpmSwPhaseAlignEnable(void)1333{1334REG_LOCAL_IRQ_SAVE;1335pChipcHw->VPMPhaseCtrl1 |= chipcHw_REG_VPM_SW_PHASE_CTRL_ENABLE;1336REG_LOCAL_IRQ_RESTORE;1337}13381339/****************************************************************************/1340/**1341* @brief Disable VPM phase alignment in software1342*1343*/1344/****************************************************************************/1345static inline void chipcHw_vpmSwPhaseAlignDisable(void)1346{1347REG_LOCAL_IRQ_SAVE;1348pChipcHw->VPMPhaseCtrl1 &= ~chipcHw_REG_VPM_SW_PHASE_CTRL_ENABLE;1349REG_LOCAL_IRQ_RESTORE;1350}13511352/****************************************************************************/1353/**1354* @brief Enable VPM phase alignment in hardware1355*1356*/1357/****************************************************************************/1358static inline void chipcHw_vpmHwPhaseAlignEnable(void)1359{1360REG_LOCAL_IRQ_SAVE;1361pChipcHw->VPMPhaseCtrl1 |= chipcHw_REG_VPM_HW_PHASE_CTRL_ENABLE;1362REG_LOCAL_IRQ_RESTORE;1363}13641365/****************************************************************************/1366/**1367* @brief Disable VPM phase alignment in hardware1368*1369*/1370/****************************************************************************/1371static inline void chipcHw_vpmHwPhaseAlignDisable(void)1372{1373REG_LOCAL_IRQ_SAVE;1374pChipcHw->VPMPhaseCtrl1 &= ~chipcHw_REG_VPM_HW_PHASE_CTRL_ENABLE;1375REG_LOCAL_IRQ_RESTORE;1376}13771378/****************************************************************************/1379/**1380* @brief Set DDR phase alignment margin in hardware1381*1382*/1383/****************************************************************************/1384static inline void1385chipcHw_setDdrHwPhaseAlignMargin(chipcHw_DDR_HW_PHASE_MARGIN_e margin)1386{1387uint32_t ge = 0;1388uint32_t le = 0;13891390switch (margin) {1391case chipcHw_DDR_HW_PHASE_MARGIN_STRICT:1392ge = 0x0F;1393le = 0x0F;1394break;1395case chipcHw_DDR_HW_PHASE_MARGIN_MEDIUM:1396ge = 0x03;1397le = 0x3F;1398break;1399case chipcHw_DDR_HW_PHASE_MARGIN_WIDE:1400ge = 0x01;1401le = 0x7F;1402break;1403}14041405{1406REG_LOCAL_IRQ_SAVE;14071408pChipcHw->DDRPhaseCtrl1 &=1409~((chipcHw_REG_DDR_PHASE_VALUE_GE_MASK <<1410chipcHw_REG_DDR_PHASE_VALUE_GE_SHIFT)1411|| (chipcHw_REG_DDR_PHASE_VALUE_LE_MASK <<1412chipcHw_REG_DDR_PHASE_VALUE_LE_SHIFT));14131414pChipcHw->DDRPhaseCtrl1 |=1415((ge << chipcHw_REG_DDR_PHASE_VALUE_GE_SHIFT)1416|| (le << chipcHw_REG_DDR_PHASE_VALUE_LE_SHIFT));14171418REG_LOCAL_IRQ_RESTORE;1419}1420}14211422/****************************************************************************/1423/**1424* @brief Set VPM phase alignment margin in hardware1425*1426*/1427/****************************************************************************/1428static inline void1429chipcHw_setVpmHwPhaseAlignMargin(chipcHw_VPM_HW_PHASE_MARGIN_e margin)1430{1431uint32_t ge = 0;1432uint32_t le = 0;14331434switch (margin) {1435case chipcHw_VPM_HW_PHASE_MARGIN_STRICT:1436ge = 0x0F;1437le = 0x0F;1438break;1439case chipcHw_VPM_HW_PHASE_MARGIN_MEDIUM:1440ge = 0x03;1441le = 0x3F;1442break;1443case chipcHw_VPM_HW_PHASE_MARGIN_WIDE:1444ge = 0x01;1445le = 0x7F;1446break;1447}14481449{1450REG_LOCAL_IRQ_SAVE;14511452pChipcHw->VPMPhaseCtrl1 &=1453~((chipcHw_REG_VPM_PHASE_VALUE_GE_MASK <<1454chipcHw_REG_VPM_PHASE_VALUE_GE_SHIFT)1455|| (chipcHw_REG_VPM_PHASE_VALUE_LE_MASK <<1456chipcHw_REG_VPM_PHASE_VALUE_LE_SHIFT));14571458pChipcHw->VPMPhaseCtrl1 |=1459((ge << chipcHw_REG_VPM_PHASE_VALUE_GE_SHIFT)1460|| (le << chipcHw_REG_VPM_PHASE_VALUE_LE_SHIFT));14611462REG_LOCAL_IRQ_RESTORE;1463}1464}14651466/****************************************************************************/1467/**1468* @brief Checks DDR phase aligned status done by HW1469*1470* @return 1: When aligned1471* 0: When not aligned1472*/1473/****************************************************************************/1474static inline uint32_t chipcHw_isDdrHwPhaseAligned(void)1475{1476return (pChipcHw->1477PhaseAlignStatus & chipcHw_REG_DDR_PHASE_ALIGNED) ? 1 : 0;1478}14791480/****************************************************************************/1481/**1482* @brief Checks VPM phase aligned status done by HW1483*1484* @return 1: When aligned1485* 0: When not aligned1486*/1487/****************************************************************************/1488static inline uint32_t chipcHw_isVpmHwPhaseAligned(void)1489{1490return (pChipcHw->1491PhaseAlignStatus & chipcHw_REG_VPM_PHASE_ALIGNED) ? 1 : 0;1492}14931494/****************************************************************************/1495/**1496* @brief Get DDR phase aligned status done by HW1497*1498*/1499/****************************************************************************/1500static inline uint32_t chipcHw_getDdrHwPhaseAlignStatus(void)1501{1502return (pChipcHw->1503PhaseAlignStatus & chipcHw_REG_DDR_PHASE_STATUS_MASK) >>1504chipcHw_REG_DDR_PHASE_STATUS_SHIFT;1505}15061507/****************************************************************************/1508/**1509* @brief Get VPM phase aligned status done by HW1510*1511*/1512/****************************************************************************/1513static inline uint32_t chipcHw_getVpmHwPhaseAlignStatus(void)1514{1515return (pChipcHw->1516PhaseAlignStatus & chipcHw_REG_VPM_PHASE_STATUS_MASK) >>1517chipcHw_REG_VPM_PHASE_STATUS_SHIFT;1518}15191520/****************************************************************************/1521/**1522* @brief Get DDR phase control value1523*1524*/1525/****************************************************************************/1526static inline uint32_t chipcHw_getDdrPhaseControl(void)1527{1528return (pChipcHw->1529PhaseAlignStatus & chipcHw_REG_DDR_PHASE_CTRL_MASK) >>1530chipcHw_REG_DDR_PHASE_CTRL_SHIFT;1531}15321533/****************************************************************************/1534/**1535* @brief Get VPM phase control value1536*1537*/1538/****************************************************************************/1539static inline uint32_t chipcHw_getVpmPhaseControl(void)1540{1541return (pChipcHw->1542PhaseAlignStatus & chipcHw_REG_VPM_PHASE_CTRL_MASK) >>1543chipcHw_REG_VPM_PHASE_CTRL_SHIFT;1544}15451546/****************************************************************************/1547/**1548* @brief DDR phase alignment timeout count1549*1550* @note If HW fails to perform the phase alignment, it will trigger1551* a DDR phase alignment timeout interrupt.1552*/1553/****************************************************************************/1554static inline void chipcHw_ddrHwPhaseAlignTimeout(uint32_t busCycle)1555{1556REG_LOCAL_IRQ_SAVE;1557pChipcHw->DDRPhaseCtrl2 &=1558~(chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_MASK <<1559chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_SHIFT);1560pChipcHw->DDRPhaseCtrl2 |=1561(busCycle & chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_MASK) <<1562chipcHw_REG_DDR_PHASE_TIMEOUT_COUNT_SHIFT;1563REG_LOCAL_IRQ_RESTORE;1564}15651566/****************************************************************************/1567/**1568* @brief VPM phase alignment timeout count1569*1570* @note If HW fails to perform the phase alignment, it will trigger1571* a VPM phase alignment timeout interrupt.1572*/1573/****************************************************************************/1574static inline void chipcHw_vpmHwPhaseAlignTimeout(uint32_t busCycle)1575{1576REG_LOCAL_IRQ_SAVE;1577pChipcHw->VPMPhaseCtrl2 &=1578~(chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_MASK <<1579chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_SHIFT);1580pChipcHw->VPMPhaseCtrl2 |=1581(busCycle & chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_MASK) <<1582chipcHw_REG_VPM_PHASE_TIMEOUT_COUNT_SHIFT;1583REG_LOCAL_IRQ_RESTORE;1584}15851586/****************************************************************************/1587/**1588* @brief Clear DDR phase alignment timeout interrupt1589*1590*/1591/****************************************************************************/1592static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptClear(void)1593{1594REG_LOCAL_IRQ_SAVE;1595/* Clear timeout interrupt service bit */1596pChipcHw->DDRPhaseCtrl2 |= chipcHw_REG_DDR_INTR_SERVICED;1597pChipcHw->DDRPhaseCtrl2 &= ~chipcHw_REG_DDR_INTR_SERVICED;1598REG_LOCAL_IRQ_RESTORE;1599}16001601/****************************************************************************/1602/**1603* @brief Clear VPM phase alignment timeout interrupt1604*1605*/1606/****************************************************************************/1607static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptClear(void)1608{1609REG_LOCAL_IRQ_SAVE;1610/* Clear timeout interrupt service bit */1611pChipcHw->VPMPhaseCtrl2 |= chipcHw_REG_VPM_INTR_SERVICED;1612pChipcHw->VPMPhaseCtrl2 &= ~chipcHw_REG_VPM_INTR_SERVICED;1613REG_LOCAL_IRQ_RESTORE;1614}16151616/****************************************************************************/1617/**1618* @brief DDR phase alignment timeout interrupt enable1619*1620*/1621/****************************************************************************/1622static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptEnable(void)1623{1624REG_LOCAL_IRQ_SAVE;1625chipcHw_ddrHwPhaseAlignTimeoutInterruptClear(); /* Recommended */1626/* Enable timeout interrupt */1627pChipcHw->DDRPhaseCtrl2 |= chipcHw_REG_DDR_TIMEOUT_INTR_ENABLE;1628REG_LOCAL_IRQ_RESTORE;1629}16301631/****************************************************************************/1632/**1633* @brief VPM phase alignment timeout interrupt enable1634*1635*/1636/****************************************************************************/1637static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptEnable(void)1638{1639REG_LOCAL_IRQ_SAVE;1640chipcHw_vpmHwPhaseAlignTimeoutInterruptClear(); /* Recommended */1641/* Enable timeout interrupt */1642pChipcHw->VPMPhaseCtrl2 |= chipcHw_REG_VPM_TIMEOUT_INTR_ENABLE;1643REG_LOCAL_IRQ_RESTORE;1644}16451646/****************************************************************************/1647/**1648* @brief DDR phase alignment timeout interrupt disable1649*1650*/1651/****************************************************************************/1652static inline void chipcHw_ddrHwPhaseAlignTimeoutInterruptDisable(void)1653{1654REG_LOCAL_IRQ_SAVE;1655pChipcHw->DDRPhaseCtrl2 &= ~chipcHw_REG_DDR_TIMEOUT_INTR_ENABLE;1656REG_LOCAL_IRQ_RESTORE;1657}16581659/****************************************************************************/1660/**1661* @brief VPM phase alignment timeout interrupt disable1662*1663*/1664/****************************************************************************/1665static inline void chipcHw_vpmHwPhaseAlignTimeoutInterruptDisable(void)1666{1667REG_LOCAL_IRQ_SAVE;1668pChipcHw->VPMPhaseCtrl2 &= ~chipcHw_REG_VPM_TIMEOUT_INTR_ENABLE;1669REG_LOCAL_IRQ_RESTORE;1670}16711672#endif /* CHIPC_INLINE_H */167316741675