2010-08-11 6 views
1

장치 드라이버 개발을 처음 사용합니다. MPC837xERDB 평가 보드의 GPIO에 액세스하려고합니다.mpc8xxx_gpio.c 장치 드라이버 사용 방법

커널을 linux-2.6.28.9으로 업그레이드하고 mpc8xxx_gpio.c을 지원하도록 설정했습니다. 부팅시 두 개의 gpio 컨트롤러를 성공적으로 감지합니다.

이제 내 질문은 어떻게 그것을 gpio 핀과 통신하는 데 사용할 것인가? mpc8xxx_gpio.c 파일의 코드를 수정하여 gpios으로하고 싶거나 커널에 제공된 gpio API (gpio_request()/gpio_free())를 사용할 수 있습니다. 또한 표준 커널 API를 시도하지만 실패합니다.

[ 617.075329] sample_driver: unable to request GPIO_PG1 
[ 617.080418] sample_driver: unable to request GPIO_PG2 
[ 617.085470] sample_driver: unable to request GPIO_PG3 
[ 617.090522] sample_driver: unable to request GPIO_PG4 
[ 617.095574] sample_driver: unable to request GPIO_PG5 
[ 617.100625] sample_driver: unable to request GPIO_PG6 
[ 617.105676] sample_driver: unable to request GPIO_PG7 
[ 617.110727] sample_driver: unable to request GPIO_PG8 
[ 617.115779] sample_driver: unable to request GPIO_PG9 
[ 617.120830] sample_driver: unable to request GPIO_PG10 
[ 617.125968] sample_driver: unable to request GPIO_PG11 
[ 617.131106] sample_driver: unable to request GPIO_PG12 
[ 617.136245] sample_driver: unable to request GPIO_PG13 
[ 617.141383] sample_driver: unable to request GPIO_PG14 
[ 617.146521] sample_driver: unable to request GPIO_PG15 
[ 617.151660] sample_driver: unable to request GPIO_PG16 
[ 617.156798] sample_driver: unable to request GPIO_PG17 
[ 617.161936] sample_driver: unable to request GPIO_PG18 
[ 617.167074] sample_driver: unable to request GPIO_PG19 
[ 617.172213] sample_driver: unable to request GPIO_PG20 
[ 617.177351] sample_driver: unable to request GPIO_PG21 
[ 617.182489] sample_driver: unable to request GPIO_PG22 
[ 617.187628] sample_driver: unable to request GPIO_PG23 
[ 617.192767] sample_driver: unable to request GPIO_PG24 
[ 617.197905] sample_driver: unable to request GPIO_PG25 
[ 617.203042] sample_driver: unable to request GPIO_PG26 
[ 617.208182] sample_driver: unable to request GPIO_PG27 
[ 617.213319] sample_driver: unable to request GPIO_PG28 
[ 617.218458] sample_driver: unable to request GPIO_PG29 
[ 617.223597] sample_driver: unable to request GPIO_PG30 
[ 617.228735] sample_driver: unable to request GPIO_PG31 
[ 617.233873] sample_driver: unable to request GPIO_PG32 

누군가가 나에게 샘플 코드 또는 뭔가를 제공 할 수 있습니다 :

#include <linux/module.h> 
#include <linux/errno.h> /* error codes */ 
#include <linux/gpio.h> 

static __init int sample_module_init(void) 
{ 
    int ret; 

    int i; 
    for (i=1; i<32; i++) { 
    ret = gpio_request(i, "Sample Driver"); 
    if (ret) { 
     printk(KERN_WARNING "sample_driver: unable to request GPIO_PG%d\n", i); 
     //return ret; 
    } 
    } 

    return 0; 
} 

static __exit void sample_module_exit(void) 
{ 
    gpio_free(9); 
} 

MODULE_LICENSE("GPL"); 

module_init(sample_module_init); 
module_exit(sample_module_exit); 

그것은 다음과 같은 O/P를 제공 : 여기 내 코드입니다. 사실 GPIO 핀 번호를 설정하려고합니다. 9는 보드상의 LED에 연결되어 있기 때문에 액티브 로우가된다.

답변

0

커널 소스에서 Documentation/gpio.txt을 조사한 적이 있습니까? 다른 질문에서

+0

예, 확인했습니다. –

1

는 :

# ls /sys/class/gpio/ -la 
drwxr-xr-x 4 root  root   0 Jan 1 00:00 . 
drwxr-xr-x 24 root  root   0 Jan 1 00:00 .. 
--w------- 1 root  root   4096 Jan 1 00:10 export 
drwxr-xr-x 3 root  root   0 Jan 1 00:00 gpiochip192 
drwxr-xr-x 3 root  root   0 Jan 1 00:00 gpiochip224 
--w------- 1 root  root   4096 Jan 1 00:00 unexport 

당신은 GPIO 핀의 두 블록이있다. 하나의 블록은 192에서 시작하고 다른 블록은 224에서 시작합니다. 위의 코드에서 플랫폼에 존재하지 않는 GPIO 0-31을 요청하려고합니다.

gpiochip* 디렉토리의 ngpio 파일을 보면 각 블록에 얼마나 많은 GPIO가 있는지 알 수 있습니다.

관련 문제