ipq806x: uart: replace hardware accessors
Originally ported QCA UART driver used hardware accessor macros where both address and data were represented by 32 bit integers. Coreboot uses macros where addresses are represented by pointers, this make the code more robust, as accidental swap between address and data does not go unnoticed. This patch converts ipq806x UART driver to use coreboot accessors. It relies on gcc void pointer arithmetic considering objects pointed at by void pointers to be one byte in size. Also replacing spaces with hard tabs where appropriate. BRANCH=storm BUG=chrome-os-partner:34790 TEST=new code still boots fine on Storm with console output present. Change-Id: I3ded9c338ff241bb1d839994f7296756aad8772d Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: 10616351704ebbcfcf25793ae974b256bc5bd6b0 Original-Change-Id: Ie15e09f9f3ea10a8566b6845219c2e09fed39218 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/240514 Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Original-Reviewed-by: Trevor Bourget <tbourget@codeaurora.org> Reviewed-on: http://review.coreboot.org/9793 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
ab7586fa26
commit
b67b7150fc
|
@ -46,8 +46,8 @@
|
||||||
#define FIFO_DATA_SIZE 4
|
#define FIFO_DATA_SIZE 4
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned uart_dm_base;
|
void *uart_dm_base;
|
||||||
unsigned uart_gsbi_base;
|
void *uart_gsbi_base;
|
||||||
unsigned uart_gsbi;
|
unsigned uart_gsbi;
|
||||||
uart_clk_mnd_t mnd_value;
|
uart_clk_mnd_t mnd_value;
|
||||||
gpio_func_data_t dbg_uart_gpio[NO_OF_DBG_UART_GPIOS];
|
gpio_func_data_t dbg_uart_gpio[NO_OF_DBG_UART_GPIOS];
|
||||||
|
@ -58,8 +58,8 @@ typedef struct {
|
||||||
* board/qcom/ipq806x_cdp/ipq806x_board_param.h
|
* board/qcom/ipq806x_cdp/ipq806x_board_param.h
|
||||||
*/
|
*/
|
||||||
static const uart_params_t uart_board_param = {
|
static const uart_params_t uart_board_param = {
|
||||||
.uart_dm_base = UART4_DM_BASE,
|
.uart_dm_base = (void *)UART4_DM_BASE,
|
||||||
.uart_gsbi_base = UART_GSBI4_BASE,
|
.uart_gsbi_base = (void *)UART_GSBI4_BASE,
|
||||||
.uart_gsbi = GSBI_4,
|
.uart_gsbi = GSBI_4,
|
||||||
.mnd_value = { 12, 625, 313 },
|
.mnd_value = { 12, 625, 313 },
|
||||||
.dbg_uart_gpio = {
|
.dbg_uart_gpio = {
|
||||||
|
@ -82,7 +82,7 @@ static const uart_params_t uart_board_param = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int msm_boot_uart_dm_init(unsigned int uart_dm_base);
|
static unsigned int msm_boot_uart_dm_init(void *uart_dm_base);
|
||||||
|
|
||||||
/* Received data is valid or not */
|
/* Received data is valid or not */
|
||||||
static int valid_data = 0;
|
static int valid_data = 0;
|
||||||
|
@ -94,24 +94,24 @@ static unsigned int word = 0;
|
||||||
* msm_boot_uart_dm_init_rx_transfer - Init Rx transfer
|
* msm_boot_uart_dm_init_rx_transfer - Init Rx transfer
|
||||||
* @uart_dm_base: UART controller base address
|
* @uart_dm_base: UART controller base address
|
||||||
*/
|
*/
|
||||||
static unsigned int msm_boot_uart_dm_init_rx_transfer(unsigned int uart_dm_base)
|
static unsigned int msm_boot_uart_dm_init_rx_transfer(void *uart_dm_base)
|
||||||
{
|
{
|
||||||
/* Reset receiver */
|
/* Reset receiver */
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RESET_RX,
|
writel(MSM_BOOT_UART_DM_CMD_RESET_RX,
|
||||||
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
||||||
|
|
||||||
/* Enable receiver */
|
/* Enable receiver */
|
||||||
writel_i(MSM_BOOT_UART_DM_CR_RX_ENABLE,
|
writel(MSM_BOOT_UART_DM_CR_RX_ENABLE,
|
||||||
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
||||||
writel_i(MSM_BOOT_UART_DM_DMRX_DEF_VALUE,
|
writel(MSM_BOOT_UART_DM_DMRX_DEF_VALUE,
|
||||||
MSM_BOOT_UART_DM_DMRX(uart_dm_base));
|
MSM_BOOT_UART_DM_DMRX(uart_dm_base));
|
||||||
|
|
||||||
/* Clear stale event */
|
/* Clear stale event */
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RES_STALE_INT,
|
writel(MSM_BOOT_UART_DM_CMD_RES_STALE_INT,
|
||||||
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
||||||
|
|
||||||
/* Enable stale event */
|
/* Enable stale event */
|
||||||
writel_i(MSM_BOOT_UART_DM_GCMD_ENA_STALE_EVT,
|
writel(MSM_BOOT_UART_DM_GCMD_ENA_STALE_EVT,
|
||||||
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
||||||
|
|
||||||
return MSM_BOOT_UART_DM_E_SUCCESS;
|
return MSM_BOOT_UART_DM_E_SUCCESS;
|
||||||
|
@ -132,7 +132,7 @@ msm_boot_uart_dm_read(unsigned int *data, int *count, int wait)
|
||||||
{
|
{
|
||||||
static int total_rx_data = 0;
|
static int total_rx_data = 0;
|
||||||
static int rx_data_read = 0;
|
static int rx_data_read = 0;
|
||||||
unsigned int base = 0;
|
void *base;
|
||||||
uint32_t status_reg;
|
uint32_t status_reg;
|
||||||
|
|
||||||
base = uart_board_param.uart_dm_base;
|
base = uart_board_param.uart_dm_base;
|
||||||
|
@ -140,19 +140,19 @@ msm_boot_uart_dm_read(unsigned int *data, int *count, int wait)
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return MSM_BOOT_UART_DM_E_INVAL;
|
return MSM_BOOT_UART_DM_E_INVAL;
|
||||||
|
|
||||||
status_reg = readl_i(MSM_BOOT_UART_DM_MISR(base));
|
status_reg = readl(MSM_BOOT_UART_DM_MISR(base));
|
||||||
|
|
||||||
/* Check for DM_RXSTALE for RX transfer to finish */
|
/* Check for DM_RXSTALE for RX transfer to finish */
|
||||||
while (!(status_reg & MSM_BOOT_UART_DM_RXSTALE)) {
|
while (!(status_reg & MSM_BOOT_UART_DM_RXSTALE)) {
|
||||||
status_reg = readl_i(MSM_BOOT_UART_DM_MISR(base));
|
status_reg = readl(MSM_BOOT_UART_DM_MISR(base));
|
||||||
if (!wait)
|
if (!wait)
|
||||||
return MSM_BOOT_UART_DM_E_RX_NOT_READY;
|
return MSM_BOOT_UART_DM_E_RX_NOT_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for Overrun error. We'll just reset Error Status */
|
/* Check for Overrun error. We'll just reset Error Status */
|
||||||
if (readl_i(MSM_BOOT_UART_DM_SR(base)) &
|
if (readl(MSM_BOOT_UART_DM_SR(base)) &
|
||||||
MSM_BOOT_UART_DM_SR_UART_OVERRUN) {
|
MSM_BOOT_UART_DM_SR_UART_OVERRUN) {
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RESET_ERR_STAT,
|
writel(MSM_BOOT_UART_DM_CMD_RESET_ERR_STAT,
|
||||||
MSM_BOOT_UART_DM_CR(base));
|
MSM_BOOT_UART_DM_CR(base));
|
||||||
total_rx_data = rx_data_read = 0;
|
total_rx_data = rx_data_read = 0;
|
||||||
msm_boot_uart_dm_init(base);
|
msm_boot_uart_dm_init(base);
|
||||||
|
@ -161,10 +161,10 @@ msm_boot_uart_dm_read(unsigned int *data, int *count, int wait)
|
||||||
|
|
||||||
/* Read UART_DM_RX_TOTAL_SNAP for actual number of bytes received */
|
/* Read UART_DM_RX_TOTAL_SNAP for actual number of bytes received */
|
||||||
if (total_rx_data == 0)
|
if (total_rx_data == 0)
|
||||||
total_rx_data = readl_i(MSM_BOOT_UART_DM_RX_TOTAL_SNAP(base));
|
total_rx_data = readl(MSM_BOOT_UART_DM_RX_TOTAL_SNAP(base));
|
||||||
|
|
||||||
/* Data available in FIFO; read a word. */
|
/* Data available in FIFO; read a word. */
|
||||||
*data = readl_i(MSM_BOOT_UART_DM_RF(base, 0));
|
*data = readl(MSM_BOOT_UART_DM_RF(base, 0));
|
||||||
|
|
||||||
/* WAR for http://prism/CR/548280 */
|
/* WAR for http://prism/CR/548280 */
|
||||||
if (*data == 0) {
|
if (*data == 0) {
|
||||||
|
@ -194,35 +194,36 @@ msm_boot_uart_dm_read(unsigned int *data, int *count, int wait)
|
||||||
|
|
||||||
void uart_tx_byte(int idx, unsigned char data)
|
void uart_tx_byte(int idx, unsigned char data)
|
||||||
{
|
{
|
||||||
unsigned int base = uart_board_param.uart_dm_base;
|
int num_of_chars = 1;
|
||||||
|
unsigned tx_data = 0;
|
||||||
|
void *base = uart_board_param.uart_dm_base;
|
||||||
|
|
||||||
/* Wait until transmit FIFO is empty. */
|
/* Wait until transmit FIFO is empty. */
|
||||||
while (!(readl_i(MSM_BOOT_UART_DM_SR(base)) &
|
while (!(readl(MSM_BOOT_UART_DM_SR(base)) &
|
||||||
MSM_BOOT_UART_DM_SR_TXEMT))
|
MSM_BOOT_UART_DM_SR_TXEMT))
|
||||||
udelay(1);
|
udelay(1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TX FIFO is ready to accept new character(s). First write number of
|
* TX FIFO is ready to accept new character(s). First write number of
|
||||||
* characters to be transmitted.
|
* characters to be transmitted.
|
||||||
*/
|
*/
|
||||||
writel_i(1, MSM_BOOT_UART_DM_NO_CHARS_FOR_TX(base));
|
writel(num_of_chars, MSM_BOOT_UART_DM_NO_CHARS_FOR_TX(base));
|
||||||
|
|
||||||
/* And now write the character(s) */
|
/* And now write the character(s) */
|
||||||
writel_i(data, MSM_BOOT_UART_DM_TF(base, 0));
|
writel(tx_data, MSM_BOOT_UART_DM_TF(base, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* msm_boot_uart_dm_reset - resets UART controller
|
* msm_boot_uart_dm_reset - resets UART controller
|
||||||
* @base: UART controller base address
|
* @base: UART controller base address
|
||||||
*/
|
*/
|
||||||
static unsigned int msm_boot_uart_dm_reset(unsigned int base)
|
static unsigned int msm_boot_uart_dm_reset(void *base)
|
||||||
{
|
{
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RESET_RX, MSM_BOOT_UART_DM_CR(base));
|
writel(MSM_BOOT_UART_DM_CMD_RESET_RX, MSM_BOOT_UART_DM_CR(base));
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RESET_TX, MSM_BOOT_UART_DM_CR(base));
|
writel(MSM_BOOT_UART_DM_CMD_RESET_TX, MSM_BOOT_UART_DM_CR(base));
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RESET_ERR_STAT,
|
writel(MSM_BOOT_UART_DM_CMD_RESET_ERR_STAT,
|
||||||
MSM_BOOT_UART_DM_CR(base));
|
MSM_BOOT_UART_DM_CR(base));
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RES_TX_ERR, MSM_BOOT_UART_DM_CR(base));
|
writel(MSM_BOOT_UART_DM_CMD_RES_TX_ERR, MSM_BOOT_UART_DM_CR(base));
|
||||||
writel_i(MSM_BOOT_UART_DM_CMD_RES_STALE_INT, MSM_BOOT_UART_DM_CR(base));
|
writel(MSM_BOOT_UART_DM_CMD_RES_STALE_INT, MSM_BOOT_UART_DM_CR(base));
|
||||||
|
|
||||||
return MSM_BOOT_UART_DM_E_SUCCESS;
|
return MSM_BOOT_UART_DM_E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -231,18 +232,18 @@ static unsigned int msm_boot_uart_dm_reset(unsigned int base)
|
||||||
* msm_boot_uart_dm_init - initilaizes UART controller
|
* msm_boot_uart_dm_init - initilaizes UART controller
|
||||||
* @uart_dm_base: UART controller base address
|
* @uart_dm_base: UART controller base address
|
||||||
*/
|
*/
|
||||||
static unsigned int msm_boot_uart_dm_init(unsigned int uart_dm_base)
|
static unsigned int msm_boot_uart_dm_init(void *uart_dm_base)
|
||||||
{
|
{
|
||||||
/* Configure UART mode registers MR1 and MR2 */
|
/* Configure UART mode registers MR1 and MR2 */
|
||||||
/* Hardware flow control isn't supported */
|
/* Hardware flow control isn't supported */
|
||||||
writel_i(0x0, MSM_BOOT_UART_DM_MR1(uart_dm_base));
|
writel(0x0, MSM_BOOT_UART_DM_MR1(uart_dm_base));
|
||||||
|
|
||||||
/* 8-N-1 configuration: 8 data bits - No parity - 1 stop bit */
|
/* 8-N-1 configuration: 8 data bits - No parity - 1 stop bit */
|
||||||
writel_i(MSM_BOOT_UART_DM_8_N_1_MODE,
|
writel(MSM_BOOT_UART_DM_8_N_1_MODE,
|
||||||
MSM_BOOT_UART_DM_MR2(uart_dm_base));
|
MSM_BOOT_UART_DM_MR2(uart_dm_base));
|
||||||
|
|
||||||
/* Configure Interrupt Mask register IMR */
|
/* Configure Interrupt Mask register IMR */
|
||||||
writel_i(MSM_BOOT_UART_DM_IMR_ENABLED,
|
writel(MSM_BOOT_UART_DM_IMR_ENABLED,
|
||||||
MSM_BOOT_UART_DM_IMR(uart_dm_base));
|
MSM_BOOT_UART_DM_IMR(uart_dm_base));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -250,25 +251,25 @@ static unsigned int msm_boot_uart_dm_init(unsigned int uart_dm_base)
|
||||||
* TX watermark value is set to 0 - interrupt is generated when
|
* TX watermark value is set to 0 - interrupt is generated when
|
||||||
* FIFO level is less than or equal to 0
|
* FIFO level is less than or equal to 0
|
||||||
*/
|
*/
|
||||||
writel_i(MSM_BOOT_UART_DM_TFW_VALUE,
|
writel(MSM_BOOT_UART_DM_TFW_VALUE,
|
||||||
MSM_BOOT_UART_DM_TFWR(uart_dm_base));
|
MSM_BOOT_UART_DM_TFWR(uart_dm_base));
|
||||||
|
|
||||||
/* RX watermark value */
|
/* RX watermark value */
|
||||||
writel_i(MSM_BOOT_UART_DM_RFW_VALUE,
|
writel(MSM_BOOT_UART_DM_RFW_VALUE,
|
||||||
MSM_BOOT_UART_DM_RFWR(uart_dm_base));
|
MSM_BOOT_UART_DM_RFWR(uart_dm_base));
|
||||||
|
|
||||||
/* Configure Interrupt Programming Register */
|
/* Configure Interrupt Programming Register */
|
||||||
/* Set initial Stale timeout value */
|
/* Set initial Stale timeout value */
|
||||||
writel_i(MSM_BOOT_UART_DM_STALE_TIMEOUT_LSB,
|
writel(MSM_BOOT_UART_DM_STALE_TIMEOUT_LSB,
|
||||||
MSM_BOOT_UART_DM_IPR(uart_dm_base));
|
MSM_BOOT_UART_DM_IPR(uart_dm_base));
|
||||||
|
|
||||||
/* Configure IRDA if required */
|
/* Configure IRDA if required */
|
||||||
/* Disabling IRDA mode */
|
/* Disabling IRDA mode */
|
||||||
writel_i(0x0, MSM_BOOT_UART_DM_IRDA(uart_dm_base));
|
writel(0x0, MSM_BOOT_UART_DM_IRDA(uart_dm_base));
|
||||||
|
|
||||||
/* Configure hunt character value in HCR register */
|
/* Configure hunt character value in HCR register */
|
||||||
/* Keep it in reset state */
|
/* Keep it in reset state */
|
||||||
writel_i(0x0, MSM_BOOT_UART_DM_HCR(uart_dm_base));
|
writel(0x0, MSM_BOOT_UART_DM_HCR(uart_dm_base));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configure Rx FIFO base address
|
* Configure Rx FIFO base address
|
||||||
|
@ -283,10 +284,10 @@ static unsigned int msm_boot_uart_dm_init(unsigned int uart_dm_base)
|
||||||
|
|
||||||
/* Enable/Disable Rx/Tx DM interfaces */
|
/* Enable/Disable Rx/Tx DM interfaces */
|
||||||
/* Data Mover not currently utilized. */
|
/* Data Mover not currently utilized. */
|
||||||
writel_i(0x0, MSM_BOOT_UART_DM_DMEN(uart_dm_base));
|
writel(0x0, MSM_BOOT_UART_DM_DMEN(uart_dm_base));
|
||||||
|
|
||||||
/* Enable transmitter */
|
/* Enable transmitter */
|
||||||
writel_i(MSM_BOOT_UART_DM_CR_TX_ENABLE,
|
writel(MSM_BOOT_UART_DM_CR_TX_ENABLE,
|
||||||
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
MSM_BOOT_UART_DM_CR(uart_dm_base));
|
||||||
|
|
||||||
/* Initialize Receive Path */
|
/* Initialize Receive Path */
|
||||||
|
@ -303,7 +304,8 @@ static unsigned int msm_boot_uart_dm_init(unsigned int uart_dm_base)
|
||||||
void uart_init(int idx)
|
void uart_init(int idx)
|
||||||
{
|
{
|
||||||
/* Note int idx isn't used in this driver. */
|
/* Note int idx isn't used in this driver. */
|
||||||
unsigned int dm_base, gsbi_base;
|
void *dm_base;
|
||||||
|
void *gsbi_base;
|
||||||
|
|
||||||
dm_base = uart_board_param.uart_dm_base;
|
dm_base = uart_board_param.uart_dm_base;
|
||||||
gsbi_base = uart_board_param.uart_gsbi_base;
|
gsbi_base = uart_board_param.uart_gsbi_base;
|
||||||
|
@ -317,10 +319,10 @@ void uart_init(int idx)
|
||||||
uart_board_param.mnd_value.d_value,
|
uart_board_param.mnd_value.d_value,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
writel_i(GSBI_PROTOCOL_CODE_I2C_UART <<
|
writel(GSBI_PROTOCOL_CODE_I2C_UART <<
|
||||||
GSBI_CTRL_REG_PROTOCOL_CODE_S,
|
GSBI_CTRL_REG_PROTOCOL_CODE_S,
|
||||||
GSBI_CTRL_REG(gsbi_base));
|
GSBI_CTRL_REG(gsbi_base));
|
||||||
writel_i(UART_DM_CLK_RX_TX_BIT_RATE, MSM_BOOT_UART_DM_CSR(dm_base));
|
writel(UART_DM_CLK_RX_TX_BIT_RATE, MSM_BOOT_UART_DM_CSR(dm_base));
|
||||||
|
|
||||||
/* Intialize UART_DM */
|
/* Intialize UART_DM */
|
||||||
msm_boot_uart_dm_init(dm_base);
|
msm_boot_uart_dm_init(dm_base);
|
||||||
|
@ -329,7 +331,7 @@ void uart_init(int idx)
|
||||||
#if 0 /* Not used yet */
|
#if 0 /* Not used yet */
|
||||||
uint32_t uartmem_getbaseaddr(void)
|
uint32_t uartmem_getbaseaddr(void)
|
||||||
{
|
{
|
||||||
return uart_board_param.uart_dm_base;
|
return (uint32_t)uart_board_param.uart_dm_base;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -339,9 +341,9 @@ uint32_t uartmem_getbaseaddr(void)
|
||||||
*/
|
*/
|
||||||
void uart_tx_flush(int idx)
|
void uart_tx_flush(int idx)
|
||||||
{
|
{
|
||||||
unsigned int base = uart_board_param.uart_dm_base;
|
void *base = uart_board_param.uart_dm_base;
|
||||||
|
|
||||||
while (!(readl_i(MSM_BOOT_UART_DM_SR(base)) &
|
while (!(readl(MSM_BOOT_UART_DM_SR(base)) &
|
||||||
MSM_BOOT_UART_DM_SR_TXEMT))
|
MSM_BOOT_UART_DM_SR_TXEMT))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue