7 Star 1 Fork 4

TenonOS/plat-rk3568

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gpio.c 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
/*
* Copyright 2024 Hangzhou Yingyi Technology Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <rk3568/gpio.h>
#include <uk/assert.h>
#include <uk/ofw/fdt.h>
#include <libfdt.h>
static uint64_t grf_base_addr;
static uint8_t gpio_initialized;
/* Macros to access gpio Registers with base address 'grf_base_addr'*/
#define GPIO_REG(r) ((uint32_t *)(grf_base_addr + (r)))
#define GPIO_REG_READ(r) ioreg_read32(GPIO_REG(r))
#define GPIO_REG_WRITE(r, v) ioreg_write32(GPIO_REG(r), v)
/**
* @brief map uart4 to gpio39/40
*
* @return -1: gpio not initialized, mapping error
* 0: mapping success
*/
static int map_uart_to_gpio(void)
{
if (!gpio_initialized) {
UK_CRASH("GPIO not initialized!\n");
return -1;
}
GPIO_REG_WRITE(GRF_IOFUNC_SEL3, MODE_UART4_SEL);
GPIO_REG_WRITE(GRF_GPIO3B_IOMUX_L, UART4_ON);
return 0;
}
void _librk3568plat_init_gpio(void *fdtp)
{
int grf_offset, rc;
uint64_t addr, size;
grf_offset = fdt_node_offset_by_compatible(fdtp, -1,
"rockchip,rk3568-grf");
if (grf_offset < 0)
UK_CRASH("No General Register Files node found!\n");
rc = fdt_get_address(fdtp, grf_offset, 0, &addr, &size);
if (rc < 0)
UK_CRASH("Could not find grf address!\n");
grf_base_addr = addr;
gpio_initialized = 1;
map_uart_to_gpio();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/tenonos/plat-rk3568.git
git@gitee.com:tenonos/plat-rk3568.git
tenonos
plat-rk3568
plat-rk3568
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385