gpt4 book ai didi

c - linux gpio 驱动程序无法导出 GPIO

转载 作者:太空狗 更新时间:2023-10-29 11:21:31 27 4
gpt4 key购买 nike

我想使用 linux GPIO 驱动程序来处理 mpc8308 处理器的 GPIO 引脚之一作为输出。所以我启用了 GPIO 驱动程序并在以下位置进行调试:

Device Drivers ---> GPIO Support ---> /sys/class/gpio/... (sysfs interface)

但是当使用 echo 时命令导出 GPIO21,它给出无效参数错误号:

gpio_request: gpio-21 (sysfs) status -22
export_store: status -22

我用了cat /sys/kernel/debug/gpio查看其他驱动程序保留了哪些 GPIO 引脚,但它什么也没显示。所以这个 pin 是免费的。

我破解了内核的错误位置,发现在 gpio_request 的开头gpiolib.c 中的函数在波纹管的最后一行崩溃:

int gpio_request(unsigned gpio, const char *label)
{
struct gpio_desc *desc;
struct gpio_chip *chip;
int status = -EINVAL;
unsigned long flags;

spin_lock_irqsave(&gpio_lock, flags);

if (!gpio_is_valid(gpio))
goto done;
desc = &gpio_desc[gpio];
chip = desc->chip;
if (chip == NULL)
goto done

gpio_desc[gpio]是驱动程序 ( static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; ) 中的数组条目,必须由 gpiochip_add 初始化驱动程序中的功能。并且必须像驱动程序所说的那样尽早调用此函数:

/**
* gpiochip_add() - register a gpio_chip
* @chip: the chip to register, with chip->base initialized
* Context: potentially before irqs or kmalloc will work
*
* Returns a negative errno if the chip can't be registered, such as
* because the chip->base is invalid or already associated with a
* different chip. Otherwise it returns zero as a success code.
*
* When gpiochip_add() is called very early during boot, so that GPIOs
* can be freely used, the chip->dev device must be registered before
* the gpio framework's arch_initcall(). Otherwise sysfs initialization
* for GPIOs will fail rudely.
*
* If chip->base is negative, this requests dynamic assignment of
* a range of valid GPIOs.
*/

但是gpiochip_add启动期间永远不会调用函数。

这是 .dts 文件:

gpio@c00 {
device_type = "gpio";
compatible = "fsl,mpc8315-gpio";
reg = <0xc00 0x100>; //reg = <0xc00 0x18>;
interrupt-parent = < &ipic >;
};

谁能帮我解决这个问题?

编辑:

我将 dts 文件更改为:

gpio1: gpio-controller@c00 {
#gpio-cells = <2>;
compatible = "fsl,mpc8308-gpio", "fsl,mpc8349-gpio";
reg = <0xc00 0x100>;
interrupt-parent = <&ipic>;
interrupts = <74 0x8>;
gpio-controller;
interrupt-controller;
#interrupt-cells = <2>;
};

现在显示gpiochip224/sys/class/gpio这个gpio芯片有32个GPIO。但我不知道21和224-255之间的映射是什么?谁能告诉我数据表中的 PIN 号与 MPC8308 PowerPC 系列处理器内核中的 GPIO 号之间的关系是什么?我尝试了所有数字 224-255,但没有一个有效。

最佳答案

需要使用GPIO controller base + GPIO。

如果你有 gpiochip451 并且想要 gpio 21:

$ ls /sys/class/gpio
export gpiochip451@ unexport

然后你需要:echo 472 > export

关于c - linux gpio 驱动程序无法导出 GPIO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39632455/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com