簡體   English   中英

linux gpio驅動無法導出GPIO

[英]linux gpio driver can't export GPIO

我想使用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引腳,但它什么都沒有顯示。 所以這個針是免費的。

我在內核中找到了錯誤的地方,並發現在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]是驅動程序中數組的一個條目( 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>;
        };

現在它在/sys/class/gpio顯示了gpiochip224 ,這個gpiochip有32個GPIO。 但我不知道21和224-255之間的映射是什么? 任何人都可以告訴我數據表中的PIN碼與MPC8308 PowerPC系列處理器內核中的GPIO號碼之間的關系是什么?我嘗試所有數字224-255並且它們都不起作用。

您需要使用GPIO控制器base + GPIO。

如果你有gpiochip451並想要gpio 21:

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

然后你需要:echo 472> export

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM