加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
board_pinmux.c 18.69 KB
一键复制 编辑 原始数据 按行查看 历史
pandygui@13.com 提交于 2021-09-17 17:04 . initial version
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
/******************************************************************************
* Copyright (c) 2019-2020 Texas Instruments Incorporated - http://www.ti.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
/**
* \file board_pinmux.c
*
* \brief This file enables pinmux for the board
*
*/
#include <ti/csl/soc.h>
#include "board_internal.h"
#include "board_pinmux.h"
static Board_PinmuxConfig_t gBoardPinmuxCfg = {BOARD_PINMUX_CUSTOM,
BOARD_PINMUX_INFO_VOUT,
BOARD_PINMUX_CSI_COMMON,
BOARD_PINMUX_ENET_QSGMII};
/**
* \brief Gets base address of padconfig registers
*
* \param domain [IN] SoC domain for pinmux
* \n BOARD_SOC_DOMAIN_MAIN - Main domain
* \n BOARD_SOC_DOMAIN_WKUP - Wakeup domain
*
* \return Valid address in case success or 0 in case of failure
*/
static void Board_pinmuxWriteProxy1Reg(uint8_t domain,
uint32_t baseAddr,
uint32_t regVal)
{
uint32_t claimAddr;
uint32_t claimOffset;
uint32_t claimShift;
uint32_t claimRegVal;
if(domain == BOARD_SOC_DOMAIN_MAIN)
{
claimAddr = BOARD_MAIN_MMR_P7_CLAIM_ADDR;
/* Get the register offset from base of P7 claim offset range */
claimOffset = (baseAddr - BOARD_MAIN_PMUX_CTRL_ADDR);
}
else
{
claimAddr = BOARD_WKUP_MMR_P7_CLAIM_ADDR;
/* Get the register offset from base of P7 claim offset range */
claimOffset = (baseAddr - BOARD_WKUP_PMUX_CTRL_ADDR);
}
/* Each claim register configures 128 byte address range.
Calculate the register offset for P7 claim register block and
and shift values within the claim register */
claimShift = claimOffset % BOARD_MMR_CLAIM_ADDR_PER_REG;
claimOffset = claimOffset / BOARD_MMR_CLAIM_ADDR_PER_REG;
claimRegVal = HW_RD_REG32((claimAddr + 4*claimOffset));
claimRegVal |= (1 << claimShift);
/* Claim the register access */
HW_WR_REG32((claimAddr + 4*claimOffset), claimRegVal);
/* Write PAD config MMR register */
HW_WR_REG32(baseAddr, regVal);
}
/**
* \brief Gets base address of padconfig registers
*
* \param domain [IN] SoC domain for pinmux
* \n BOARD_SOC_DOMAIN_MAIN - Main domain
* \n BOARD_SOC_DOMAIN_WKUP - Wakeup domain
*
* \return Valid address in case success or 0 in case of failure
*/
static uint32_t Board_pinmuxGetBaseAddr(uint8_t domain)
{
uint32_t baseAddr;
switch(domain)
{
case BOARD_SOC_DOMAIN_MAIN:
baseAddr = BOARD_MAIN_PMUX_CTRL_ADDR;
break;
case BOARD_SOC_DOMAIN_WKUP:
baseAddr = BOARD_WKUP_PMUX_CTRL_ADDR;
break;
default:
baseAddr = 0;
break;
}
return baseAddr;
}
/**
* \brief Sets pinmux mode for a pin in main domain
*
* Only pinmux mode is updated by this function. Other values of
* padconfig register remains unchanged after this function call.
*
* \param offset [IN] Pad config offset of the pin
* \param mode [IN] Pad config mux mode.
*
* \return None
*/
void Board_pinMuxSetMode(uint32_t offset, uint32_t mode)
{
uint32_t baseAddr;
uint32_t regVal;
Board_unlockMMR();
baseAddr = Board_pinmuxGetBaseAddr(BOARD_SOC_DOMAIN_MAIN);
regVal = HW_RD_REG32((baseAddr + offset));
regVal &= ~(BOARD_MODE_PIN_MASK);
mode &= BOARD_MODE_PIN_MASK;
regVal |= mode;
Board_pinmuxWriteProxy1Reg(BOARD_SOC_DOMAIN_MAIN,
(baseAddr + offset),
regVal);
}
/**
* \brief Sets pinmux mode for a pin in wake-up domain
*
* Only pinmux mode is updated by this function. Other values of
* padconfig register remains unchanged after this function call.
*
* \param offset [IN] Pad config offset of the pin
* \param mode [IN] Pad config mux mode.
*
* \return None
*/
void Board_pinMuxSetModeWkup(uint32_t offset, uint32_t mode)
{
uint32_t baseAddr;
uint32_t regVal;
Board_unlockMMR();
baseAddr = Board_pinmuxGetBaseAddr(BOARD_SOC_DOMAIN_WKUP);
regVal = HW_RD_REG32((baseAddr + offset));
regVal &= ~(BOARD_MODE_PIN_MASK);
mode &= BOARD_MODE_PIN_MASK;
regVal |= mode;
Board_pinmuxWriteProxy1Reg(BOARD_SOC_DOMAIN_WKUP,
(baseAddr + offset),
regVal);
}
/**
* \brief Sets padconfig register of a pin at given offset
*
* Configures whole padconfig register of the pin at given offset
* with the value in 'muxData'.
*
* \param domain [IN] SoC domain for pinmux
* \n BOARD_SOC_DOMAIN_MAIN - Main domain
* \n BOARD_SOC_DOMAIN_WKUP - Wakeup domain
*
* \param offset [IN] Pad config offset of the pin
* \param muxData [IN] Value to be written to padconfig register
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxSetReg(uint8_t domain,
uint32_t offset,
uint32_t muxData)
{
uint32_t baseAddr;
Board_STATUS status = BOARD_SOK;
Board_unlockMMR();
baseAddr = Board_pinmuxGetBaseAddr(domain);
if(baseAddr != 0)
{
Board_pinmuxWriteProxy1Reg(domain,
(baseAddr + offset),
muxData);
}
else
{
status = BOARD_INVALID_PARAM;
}
return status;
}
/**
* \brief Gets padconfig register of a pin at given offset
*
* \param domain [IN] SoC domain for pinmux
* \n BOARD_SOC_DOMAIN_MAIN - Main domain
* \n BOARD_SOC_DOMAIN_WKUP - Wakeup domain
* \param offset [IN] Pad config offset of the pin
* \param muxData [OUT] Value of padconfig register
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxGetReg(uint8_t domain,
uint32_t offset,
uint32_t *muxData)
{
uint32_t baseAddr;
Board_STATUS status = BOARD_SOK;
baseAddr = Board_pinmuxGetBaseAddr(domain);
if(baseAddr != 0)
{
*muxData = HW_RD_REG32((baseAddr + offset));
}
else
{
status = BOARD_INVALID_PARAM;
}
return status;
}
/**
* \brief Sets the board pinmux configuration.
*
* There are multiple addon cards that can connected to baseboard and
* multiple addon cards can be connected to one expansion connector.
* Pinmux configured through Board_init will be set to a default
* combination of the boards which can be changed using this function.
*
* \n Usage:
* \n - Call Board_pinmuxGetCfg to get default pinmux config
* \n - Call Board_pinmuxSetCfg to change pinmux config
* \n - Call Board_init with pinmux flag to apply the updated pinmux config
*
* \param pinmuxCfg [IN] Pinmux configurations
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxSetCfg(Board_PinmuxConfig_t *pinmuxCfg)
{
gBoardPinmuxCfg = *pinmuxCfg;
return BOARD_SOK;
}
/**
* \brief Gets the board pinmux configuration.
*
* There are multiple addon cards that can connected to baseboard and
* multiple addon cards can be connected to one expansion connector.
* Pinmux configured through Board_init will be set to a default
* combination of the boards which can be read using this function.
*
* \param pinmuxCfg [IN] Pinmux configurations
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxGetCfg(Board_PinmuxConfig_t *pinmuxCfg)
{
*pinmuxCfg = gBoardPinmuxCfg;
return BOARD_SOK;
}
/**
* \brief Board pinmuxing update function
*
* Provides the option to configure/update the pinmux.
* This function can be used to change the pinmux set by
* Board_init by default.
*
* \param pinmuxData [IN] Pinmux data structure
* \param domain [IN] SoC domain for pinmux
* \n BOARD_SOC_DOMAIN_MAIN - Main domain
* \n BOARD_SOC_DOMAIN_WKUP - Wakeup domain
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxUpdate (pinmuxBoardCfg_t *pinmuxData,
uint32_t domain)
{
pinmuxModuleCfg_t *pModuleData = NULL;
pinmuxPerCfg_t *pInstanceData = NULL;
int32_t i, j, k;
uint32_t rdRegVal;
uint32_t baseAddr;
Board_STATUS status = BOARD_SOK;
Board_unlockMMR();
/* MAIN domain pinmux needs RAT configuration for C66x core. */
if(domain == BOARD_SOC_DOMAIN_MAIN)
{
Board_setRATCfg();
}
baseAddr = Board_pinmuxGetBaseAddr(domain);
if(baseAddr != 0)
{
for(i = 0; PINMUX_END != pinmuxData[i].moduleId; i++)
{
pModuleData = pinmuxData[i].modulePinCfg;
for(j = 0; (PINMUX_END != pModuleData[j].modInstNum); j++)
{
if(pModuleData[j].doPinConfig == TRUE)
{
pInstanceData = pModuleData[j].instPins;
for(k = 0; (PINMUX_END != pInstanceData[k].pinOffset); k++)
{
rdRegVal = HW_RD_REG32((baseAddr + pInstanceData[k].pinOffset));
rdRegVal = (rdRegVal & BOARD_PINMUX_BIT_MASK);
Board_pinmuxWriteProxy1Reg(domain,
(baseAddr + pInstanceData[k].pinOffset),
(pInstanceData[k].pinSettings));
}
}
}
}
}
else
{
status = BOARD_INVALID_PARAM;
}
if(domain == BOARD_SOC_DOMAIN_MAIN)
{
/* Clear the RAT configuration to allow applications to use the region */
Board_restoreRATCfg();
}
return status;
}
/**
* \brief Board pinmuxing enable function
*
* Enables pinmux for the board interfaces. Pin mux is done based
* on the default/primary functionality of the board. Any pins shared by
* multiple interfaces need to be reconfigured to access the secondary
* functionality.
*
* \param void
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxConfig (void)
{
Board_STATUS status = BOARD_SOK;
/* Pinmux for baseboard */
Board_pinmuxUpdate(gJ721E_MainPinmuxData,
BOARD_SOC_DOMAIN_MAIN);
Board_pinmuxUpdate(gJ721E_WkupPinmuxData,
BOARD_SOC_DOMAIN_WKUP);
/* Pinmux for Application cards */
if(gBoardPinmuxCfg.autoCfg)
{
/* Auto detect the application boards connected and configure the pinmux */
if(Board_detectBoard(BOARD_ID_GESI) == TRUE)
{
gBoardPinmuxCfg.gesiExp = BOARD_PINMUX_GESI_CPSW;
}
else
{
if(Board_detectBoard(BOARD_ID_INFOTAINMENT) == TRUE)
{
gBoardPinmuxCfg.gesiExp = BOARD_PINMUX_INFO_VOUT;
}
}
}
if((gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_ICSSG) ||
(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_CPSW))
{
/* By default ICSSG RGMII is enabled */
Board_pinmuxUpdate(gJ721E_MainPinmuxDataGesiIcssg,
BOARD_SOC_DOMAIN_MAIN);
Board_pinmuxUpdate(gJ721E_WkupPinmuxDataGesiIcssg,
BOARD_SOC_DOMAIN_WKUP);
if(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_CPSW)
{
/* Overwrite the ICSSG RGMII muc configurations with CPSW9G RGMII */
Board_pinmuxUpdate(gJ721E_MainPinmuxDataGesiCpsw9g,
BOARD_SOC_DOMAIN_MAIN);
Board_pinmuxUpdate(gJ721E_WkupPinmuxDataGesiCpsw9g,
BOARD_SOC_DOMAIN_WKUP);
}
}
else if(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_INFO_VOUT)
{
Board_pinmuxUpdate(gJ721E_MainPinmuxDataInfo,
BOARD_SOC_DOMAIN_MAIN);
Board_pinmuxUpdate(gJ721E_WkupPinmuxDataInfo,
BOARD_SOC_DOMAIN_WKUP);
}
else
{
return (BOARD_INVALID_PARAM);
}
// if(gBoardPinmuxCfg.fssCfg == BOARD_PINMUX_FSS_HPB)
// {
// Board_pinmuxUpdate(gJ721E_WkupPinmuxDataHpb,
// BOARD_SOC_DOMAIN_WKUP);
// }
return status;
}
/**
* \brief Board pinmuxing enable function for main domain
*
* Enables pinmux for the board interfaces connected to main domain.
* Pin mux is done based on the default/primary functionality of the board.
* Any pins shared by multiple interfaces need to be reconfigured to access
* the secondary functionality.
*
* \param void
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxConfigMain (void)
{
Board_STATUS status = BOARD_SOK;
/* Pinmux for baseboard */
Board_pinmuxUpdate(gJ721E_MainPinmuxData,
BOARD_SOC_DOMAIN_MAIN);
if(gBoardPinmuxCfg.autoCfg)
{
/* Auto detect the application boards connected and configure the pinmux */
if(Board_detectBoard(BOARD_ID_GESI) == TRUE)
{
gBoardPinmuxCfg.gesiExp = BOARD_PINMUX_GESI_CPSW;
}
else
{
if(Board_detectBoard(BOARD_ID_INFOTAINMENT) == TRUE)
{
gBoardPinmuxCfg.gesiExp = BOARD_PINMUX_INFO_VOUT;
}
}
}
if((gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_ICSSG) ||
(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_CPSW))
{
/* By default ICSSG RGMII is enabled */
Board_pinmuxUpdate(gJ721E_MainPinmuxDataGesiIcssg,
BOARD_SOC_DOMAIN_MAIN);
if(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_CPSW)
{
/* Overwrite the ICSSG RGMII muc configurations with CPSW9G RGMII */
Board_pinmuxUpdate(gJ721E_MainPinmuxDataGesiCpsw9g,
BOARD_SOC_DOMAIN_MAIN);
}
}
else if(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_INFO_VOUT)
{
Board_pinmuxUpdate(gJ721E_MainPinmuxDataInfo,
BOARD_SOC_DOMAIN_MAIN);
}
else
{
return (BOARD_INVALID_PARAM);
}
return status;
}
/**
* \brief Board pinmuxing enable function for wakeup/mcu domain
*
* Enables pinmux for the board interfaces connected to wakeup/mcu domain.
* Pin mux is done based on the default/primary functionality of the board.
* Any pins shared by multiple interfaces need to be reconfigured to access
* the secondary functionality.
*
* \param void
*
* \return BOARD_SOK in case of success or appropriate error code
*
*/
Board_STATUS Board_pinmuxConfigWkup (void)
{
Board_STATUS status = BOARD_SOK;
Board_pinmuxUpdate(gJ721E_WkupPinmuxData,
BOARD_SOC_DOMAIN_WKUP);
if(gBoardPinmuxCfg.autoCfg)
{
/* Auto detect the application boards connected and configure the pinmux */
if(Board_detectBoard(BOARD_ID_GESI) == TRUE)
{
gBoardPinmuxCfg.gesiExp = BOARD_PINMUX_GESI_CPSW;
}
else
{
if(Board_detectBoard(BOARD_ID_INFOTAINMENT) == TRUE)
{
gBoardPinmuxCfg.gesiExp = BOARD_PINMUX_INFO_VOUT;
}
}
}
if((gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_ICSSG) ||
(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_CPSW))
{
Board_pinmuxUpdate(gJ721E_WkupPinmuxDataGesiIcssg,
BOARD_SOC_DOMAIN_WKUP);
if(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_GESI_CPSW)
{
Board_pinmuxUpdate(gJ721E_WkupPinmuxDataGesiCpsw9g,
BOARD_SOC_DOMAIN_WKUP);
}
}
else if(gBoardPinmuxCfg.gesiExp == BOARD_PINMUX_INFO_VOUT)
{
Board_pinmuxUpdate(gJ721E_WkupPinmuxDataInfo,
BOARD_SOC_DOMAIN_WKUP);
}
else
{
return (BOARD_INVALID_PARAM);
}
// if(gBoardPinmuxCfg.fssCfg == BOARD_PINMUX_FSS_HPB)
// {
// Board_pinmuxUpdate(gJ721E_WkupPinmuxDataHpb,
// BOARD_SOC_DOMAIN_WKUP);
// }
return status;
}
void Board_uartTxPinmuxConfig(void)
{
/* Unlock partition lock kick */
HW_WR_REG32(BOARD_MCU_UART_TX_LOCK_KICK_ADDR, BOARD_KICK0_UNLOCK_VAL);
HW_WR_REG32(BOARD_MCU_UART_TX_LOCK_KICK_ADDR + 4U, BOARD_KICK1_UNLOCK_VAL);
/* Configure pinmux for UART Tx pin */
HW_WR_REG32(BOARD_MCU_UART_TX_PINMUX_ADDR, BOARD_MCU_UART_TX_PINMUX_VAL);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化