我想使用linux GPIO驱动程序来处理mpc8308处理器的一个GPIO引脚作为输出。所以我启用了GPIO驱动程序,它正在调试中:
Device Drivers ---> GPIO Support ---> /sys/class/gpio/... (sysfs interface)
但是当使用echo命令导出GPIO21时,它会给出无效的参数errno:
gpio_request: gpio-21 (sysfs) status -22
export_store: status -22我使用cat /sys/kernel/debug/gpio查看哪些GPIO引脚是由其他驱动程序保留的,但没有显示任何内容。所以这个引脚是空闲的。
我破解了内核的错误位置,发现在gpiolib.c中gpio_request函数的开头,它在下面的最后一行崩溃:
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 donegpio_desc[gpio]是驱动程序(static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];)中必须由驱动程序中的gpiochip_add函数初始化的数组条目。而且这个函数必须像driver所说的那样提前调用:
/**
* 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>;
};现在它在/sys/class/gpio中显示gpiochip224,这个GPIO芯片有32个GPIO。但是我不知道21和224-255之间的映射是什么?谁能告诉我MPC8308 PowerPC系列处理器的数据手册中的PIN号和内核中的GPIO号之间是什么关系?我尝试了所有的224-255号,但没有一个有效。
发布于 2016-09-22 19:18:10
您需要使用GPIO控制器底座+ GPIO。
如果你有gpiochip451并且想要GPIO21:
$ ls /sys/class/gpio
export gpiochip451@ unexport然后您需要: echo 472 > export
https://stackoverflow.com/questions/39632455
复制相似问题