简体   繁体   English

linux gpio驱动无法导出GPIO

[英]linux gpio driver can't export GPIO

I want to use linux GPIO driver to handle one of the GPIO pins of mpc8308 processor as output. 我想使用linux GPIO驱动程序来处理mpc8308处理器的一个GPIO引脚作为输出。 so I enabled the GPIO driver and it's debugging in: 所以我启用了GPIO驱动程序并调试它:

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

but when using echo command to export GPIO21, it gives Invalid argument errno: 但是当使用echo命令导出GPIO21时,它会给出无效参数errno:

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

I used cat /sys/kernel/debug/gpio to see which GPIO pins are reserved by other drivers, but it shows nothing. 我使用cat /sys/kernel/debug/gpio来查看其他驱动程序保留哪些GPIO引脚,但它什么都没有显示。 so this pin is free. 所以这个针是免费的。

I hacked the kernel for the place of error and found that in beginning of gpio_request function in gpiolib.c it crashes at last line in bellow: 我在内核中找到了错误的地方,并发现在gpio_request中的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 done

gpio_desc[gpio] is an entry of an array in driver ( static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; ) that must be initialized by gpiochip_add function in driver. gpio_desc[gpio]是驱动程序中数组的一个条目( static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; ),必须由驱动程序中的gpiochip_add函数初始化。 and this function must be called early as driver says: 并且必须尽早调用此函数,因为驱动程序说:

/**
 * 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.
 */

but gpiochip_add function never is called during boot. 但是在启动过程中永远不会调用gpiochip_add函数。

Here is the .dts file: 这是.dts文件:

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

can anyone help me with this problem? 任何人都可以帮我解决这个问题吗?

Edit: 编辑:

I changed dts file to this: 我将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>;
        };

and now it shows gpiochip224 in /sys/class/gpio and this gpiochip has 32 GPIOs. 现在它在/sys/class/gpio显示了gpiochip224 ,这个gpiochip有32个GPIO。 but I don't know what is the mapping between 21 and 224-255? 但我不知道21和224-255之间的映射是什么? can anyone tell me what is the relation between PIN numbers in datasheet and GPIO numbers in kernel for MPC8308 PowerPC series processor?I try all numbers 224-255 and none of them works. 任何人都可以告诉我数据表中的PIN码与MPC8308 PowerPC系列处理器内核中的GPIO号码之间的关系是什么?我尝试所有数字224-255并且它们都不起作用。

You need to use GPIO controller base + GPIO. 您需要使用GPIO控制器base + GPIO。

If you have gpiochip451 and want gpio 21: 如果你有gpiochip451并想要gpio 21:

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

Then you need: echo 472 > export 然后你需要:echo 472> export

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM