Skip to content

[bsp/milkv 仅用于讨论-后续拆分提交]为后续使用ioremap做准备 #9120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions bsp/cvitek/cv18xx_aarch64/board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,3 @@ void rt_hw_board_init(void)
rt_hw_common_setup();
}
#endif /* RT_USING_OFW */

static rt_ubase_t pinmux_base = RT_NULL;

rt_ubase_t pinmux_base_ioremap(void)
{
if (pinmux_base == RT_NULL)
{
pinmux_base = (rt_size_t)rt_ioremap((void*)0x03001000, 0x1000);
}

return pinmux_base;
}
7 changes: 4 additions & 3 deletions bsp/cvitek/drivers/drv_gpio.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写法建议修改为如下方式。理由,没有必要赋值两次,定义时直接放 BSS,可以有助于减小 bin 文件 size

diff --git a/bsp/cvitek/drivers/drv_gpio.c b/bsp/cvitek/drivers/drv_gpio.c
index aef6b291d7..be24f5dcc4 100644
--- a/bsp/cvitek/drivers/drv_gpio.c
+++ b/bsp/cvitek/drivers/drv_gpio.c
@@ -53,8 +53,8 @@ rt_inline void dwapb_write32(rt_ubase_t addr, rt_uint32_t value)
     HWREG32(addr) = value;
 }
 
-static rt_ubase_t dwapb_gpio_base = DWAPB_GPIOA_BASE;
-static rt_ubase_t dwapb_gpio_base_e = DWAPB_GPIOE_BASE;
+static rt_ubase_t dwapb_gpio_base;
+static rt_ubase_t dwapb_gpio_base_e;
 
 static struct dwapb_event
 {
@@ -303,6 +303,9 @@ static void rt_hw_gpio_isr(int irqno, void *param)
 
 int rt_hw_gpio_init(void)
 {
+    dwapb_gpio_base = (rt_size_t)rt_ioremap(DWAPB_GPIOA_BASE, DWAPB_GPIO_SIZE);
+    dwapb_gpio_base_e = (rt_size_t)rt_ioremap(DWAPB_GPIOE_BASE, DWAPB_GPIO_SIZE);
+
     rt_device_pin_register("gpio", &_dwapb_ops, RT_NULL);
 
 #define INT_INSTALL_GPIO_DEVICE(no)     \

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#ifdef RT_USING_SMART
#include <ioremap.h>
#endif
#include "drv_ioremap.h"

#ifdef RT_USING_PIN
#include "drv_gpio.h"
Expand Down Expand Up @@ -303,6 +301,9 @@ static void rt_hw_gpio_isr(int irqno, void *param)

int rt_hw_gpio_init(void)
{
dwapb_gpio_base = (rt_size_t)rt_ioremap((void*)dwapb_gpio_base, DWAPB_GPIO_SIZE);
dwapb_gpio_base_e = (rt_size_t)rt_ioremap((void*)dwapb_gpio_base_e, DWAPB_GPIO_SIZE);

rt_device_pin_register("gpio", &_dwapb_ops, RT_NULL);

#define INT_INSTALL_GPIO_DEVICE(no) \
Expand Down
10 changes: 10 additions & 0 deletions bsp/cvitek/drivers/drv_ioremap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <rtconfig.h>

#ifdef RT_USING_SMART
#include <ioremap.h>
#else
#define rt_ioremap(a, s) (a)
#define rt_iounmap(a)
#endif
12 changes: 2 additions & 10 deletions bsp/cvitek/drivers/drv_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define DBG_LVL DBG_WARNING
#include <rtdbg.h>

#include "drv_ioremap.h"

/*
* Divide positive or negative dividend by positive divisor and round
* to closest integer. Result is undefined for negative divisors and
Expand Down Expand Up @@ -252,45 +254,35 @@ int rt_hw_uart_init(void)
PINMUX_CONFIG(UART0_RX, UART0_RX);
PINMUX_CONFIG(UART0_TX, UART0_TX);
BSP_INSTALL_UART_DEVICE(0);
#if defined(ARCH_ARM)
uart->hw_base = (rt_size_t)rt_ioremap((void*)uart->hw_base, 0x10000);
#endif /* defined(ARCH_ARM) */
#endif

#ifdef RT_USING_UART1
PINMUX_CONFIG(IIC0_SDA, UART1_RX);
PINMUX_CONFIG(IIC0_SCL, UART1_TX);
BSP_INSTALL_UART_DEVICE(1);
#if defined(ARCH_ARM)
uart->hw_base = (rt_size_t)rt_ioremap((void*)uart->hw_base, 0x10000);
#endif /* defined(ARCH_ARM) */
#endif

#ifdef RT_USING_UART2
PINMUX_CONFIG(SD1_D1, UART2_RX);
PINMUX_CONFIG(SD1_D2, UART2_TX);
BSP_INSTALL_UART_DEVICE(2);
#if defined(ARCH_ARM)
uart->hw_base = (rt_size_t)rt_ioremap((void*)uart->hw_base, 0x10000);
#endif /* defined(ARCH_ARM) */
#endif

#ifdef RT_USING_UART3
PINMUX_CONFIG(SD1_D1, UART3_RX);
PINMUX_CONFIG(SD1_D2, UART3_TX);
BSP_INSTALL_UART_DEVICE(3);
#if defined(ARCH_ARM)
uart->hw_base = (rt_size_t)rt_ioremap((void*)uart->hw_base, 0x10000);
#endif /* defined(ARCH_ARM) */
#endif

#ifdef RT_USING_UART4
PINMUX_CONFIG(SD1_GP0, UART4_RX);
PINMUX_CONFIG(SD1_GP1, UART4_TX);
BSP_INSTALL_UART_DEVICE(4);
#if defined(ARCH_ARM)
uart->hw_base = (rt_size_t)rt_ioremap((void*)uart->hw_base, 0x10000);
#endif /* defined(ARCH_ARM) */
#endif

return 0;
Expand Down
5 changes: 1 addition & 4 deletions bsp/cvitek/drivers/libraries/cv181x/pinctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
#define PAD_MIPI_TXM0__MIPI_TXM0 0
#define PAD_MIPI_TXP0__MIPI_TXP0 0

#if defined(ARCH_ARM)
extern rt_ubase_t pinmux_base_ioremap(void);
#define PINMUX_BASE pinmux_base_ioremap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PINMUX_BASE 的访问会很多,可以搜一下 bsp/cvitek/ 下,我发现除了涉及 PINMUX_CONFIG 外,在 sdmmc 驱动中,很多寄存器的定义都是相对于 PINMUX_BASE 的,见 bsp/cvitek/drivers/libraries/sdif/dw_sdmmc.h。如果将 PINMUX_BASE 定义为调用 pinmux_base_ioremap(),效率会降低很多。

所以我这里建议:是否可以将 PINMUX_BASE 定义为 pinmux_base 全局变量, 然后在 board 初始化阶段,确保在早于 uart 初始化之前,就把 pinmux 给初始化了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PINMUX_BASE这个暂时保留,这次提交主要是想不太多修改原来代码基础上使用ioremap,效率问题可以后面修改

#else
#define PINMUX_BASE 0x03001000
#endif /* defined(ARCH_ARM) */

#define PINMUX_MASK(PIN_NAME) FMUX_GPIO_FUNCSEL_##PIN_NAME##_MASK
#define PINMUX_OFFSET(PIN_NAME) FMUX_GPIO_FUNCSEL_##PIN_NAME##_OFFSET
#define PINMUX_VALUE(PIN_NAME, FUNC_NAME) PIN_NAME##__##FUNC_NAME
Expand Down
14 changes: 14 additions & 0 deletions bsp/cvitek/drivers/pinctrl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <rtdef.h>
#include "drv_ioremap.h"

static rt_ubase_t pinmux_base = RT_NULL;

rt_ubase_t pinmux_base_ioremap(void)
{
if (pinmux_base == RT_NULL)
{
pinmux_base = (rt_size_t)rt_ioremap((void*)0x03001000, 0x1000);
}

return pinmux_base;
}
Loading