2016-09-22 303 views
2

我想使用linux的GPIO驅動程序來處理mpc8308處理器的一個GPIO引腳作爲輸出。所以我啓用了GPIO的驅動程序,它的調試工作:linux 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引腳被其他驅動程序保留,但不顯示任何內容。所以這個引腳是免費的。

我砍死內核錯誤的地點和發現,在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 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文件:

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

誰能幫我解決這個問題?

編輯:

我改變了DTS文件,以這樣的:

gpio1: [email protected] { 
      #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/gpiogpiochip224這gpiochip有32個GPIO。但我不知道21和224-255之間的映射是什麼? 任何人都可以告訴我MPC8308 PowerPC系列處理器的數據表中的PIN碼與內核中的GPIO數字之間的關係是什麼?我嘗試所有數字224-255,並且它們都不起作用。

回答

0

您需要使用GPIO控制器基板+ GPIO。

如果你有gpiochip451,並希望GPIO 21:

$ ls /sys/class/gpio 
export [email protected] unexport 

然後,你需要:回聲472>出口

+0

我在.dts不GPIO控制器,也是我沒有pinctrl司機在內核中。我應該添加gpio-controller還是pinctrl或兩者都可以在usetspace中使用GPIO? – AVM

+0

如果你有一箇舊的內核,可能有一個SICRH寄存器設置不正確的錯誤 – gj13

+0

我在啓動時設置了SICRH,但我不確定它的值是否正確。 – AVM