初中生
最后登录1970-1-1
在线时间 小时
注册时间2025-3-2
|

楼主 |
发表于 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
完美解决。 |
|