野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 545|回复: 1

[求助] 鲁班猫RV1106开发板 扩展GPIO5基地址

[复制链接]
发表于 2026-5-14 21:48:50 | 显示全部楼层 |阅读模式
老师好!

      请教个问题:[野火]《快速使用手册-基于LubanCat-RV110x系列板卡》_20250312.pdf中Page 98描述扩展的GPIO5基地址为272:
      “ ... 板卡上除了主控芯片原生IO,也使用i2c扩展gpio(GPIO5),使用拓展IO的计算方式不一样,基地址是272,因此基于GPIO5的引脚公式需要加上基地址,...."
      请问基地址272是在sdk的什么地方定义的?


回复

使用道具 举报

 楼主| 发表于 2026-5-16 09:27:18 | 显示全部楼层
找到扩展GPIO5接口的基地址定义了:
1、在sysdrv/source/kernel/drivers/gpio/gpiolib.c中的gpiochip_find_base(int ngpio)中增加调试日志:
static int gpiochip_find_base(int ngpio)
{
        struct gpio_device *gdev;
        int base = ARCH_NR_GPIOS - ngpio;

        pr_info("[GPIO DEBUG] gpiochip_find_base() called, ngpio=%d, ARCH_NR_GPIOS=%d, initial base=%d\n",
                ngpio, ARCH_NR_GPIOS, base);

        if (list_empty(&gpio_devices)) {
                pr_info("[GPIO DEBUG] gpio_devices list is empty, returning base=%d\n", base);
                if (gpio_is_valid(base))
                        return base;
                else
                        return -ENOSPC;
        }

        pr_info("[GPIO DEBUG] Scanning existing gpio_devices list:\n");
        list_for_each_entry_reverse(gdev, &gpio_devices, list) {
                pr_info("[GPIO DEBUG]   gdev->base=%d, gdev->ngpio=%d, gdev->label=%s\n",
                        gdev->base, gdev->ngpio, gdev->label ? gdev->label : "NULL");
                /* found a free space? */
                if (gdev->base + gdev->ngpio <= base) {
                        pr_info("[GPIO DEBUG]   Found free space before this chip, breaking\n");
                        break;
                } else {
                        /* nope, check the space right before the chip */
                        pr_info("[GPIO DEBUG]   Overlap detected, moving base from %d to %d\n",
                                base, gdev->base - ngpio);
                        base = gdev->base - ngpio;
                }
        }

        if (gpio_is_valid(base)) {
                pr_info("[GPIO DEBUG] gpiochip_find_base() succeeded, returning base=%d\n", base);
                return base;
        } else {
                pr_err("[GPIO DEBUG] gpiochip_find_base() failed, cannot find free range\n");
                return -ENOSPC;
        }
}
在日志中可以追踪到如下输出:
[    0.215682] [GPIO DEBUG] gpiochip_find_base() called, ngpio=16, ARCH_NR_GPIOS=288, initial base=272
[    0.215699] [GPIO DEBUG] Scanning existing gpio_devices list:
[    0.215707] [GPIO DEBUG]   gdev->base=128, gdev->ngpio=24, gdev->label=gpio4
[    0.215713] [GPIO DEBUG]   Found free space before this chip, breaking
[    0.215718] [GPIO DEBUG] gpiochip_find_base() succeeded, returning base=272

2、追踪ARCH_NR_GPIOS定义:
  在sysdrv/source/kernel/include/asm-generic/gpio.h中追踪到下面定义:
#ifndef ARCH_NR_GPIOS
#if defined(CONFIG_ARCH_NR_GPIO) && CONFIG_ARCH_NR_GPIO > 0
#define ARCH_NR_GPIOS CONFIG_ARCH_NR_GPIO
#else
#define ARCH_NR_GPIOS                512
#endif
#endif

3.在sysdrv/source/objs_kernel/.config 追踪到:
  CONFIG_ARCH_NR_GPIO=288
   
完美解决。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2026-5-25 17:01 , Processed in 0.074266 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表