GPIO driver for DM6441

Publisher:工号待定Latest update time:2015-10-09 Source: eefocusKeywords:dm6441 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This is the first driver I developed after entering the embedded industry.

Platform: Ti    dm6441      linu2.6.18

GPIO is the simplest and most commonly used resource in embedded systems, such as lighting up LEDs, controlling buzzers, outputting high and low levels, detecting buttons, etc.
Due to hardware resource reasons, DM6441 is not a pure GPIO pin. GPIO pins and some other standard interfaces reuse the same pins, such as SPI and GPIO reuse, I2C and GPIO reuse, etc. Whether to use GPIO or other interfaces, you need to set the two registers
PINMUX0 and PINMUX1 during initialization (see DM6441 chip p72), and the software settings are in the directory of Montavista linux-2.6.18_pro500/arch/arm/mach-davinci in mux_cfg.c and the corresponding include/asm/arch-davinci/mux.h. From the data sheet, we know that gpio5, 6, 7 are gpio functions by default.

Analysis of mux_cfg.c

The first parameter explanation of MUX_CFG()
   is the description (corresponding to the data sheet p72), the second is pinmux0 or 1, and the third is the register offset. The last one is related to debugging. The
   second to last is the value you need to set for the corresponding bit of the pinmux register, the third to last is the value of all 1s for the corresponding bits of the pinmux (mask value), and
   the fourth to last is the offset value of the corresponding bit of the pinmux. If you want to change the mode of the pin, set the corresponding pin to 0, and then set other functions to 1.
  (This is my understanding, refer to the I2C and GPIO43_44 settings below).
#include
#include

#include

#include
#include

#ifdef CONFIG_DAVINCI_MUX

struct pin_config __initdata_or_module davinci_dm644x_pins[] = {

MUX_CFG("HDIREN",    0,    16,     1,    1,   1)
MUX_CFG("ATAEN",    0,    17,     1,    1,   1)

MUX_CFG("MSTK",     1,    9,      1,    0,   0)

MUX_CFG("I2C",     1,    7,      1,    1,   0)

MUX_CFG("MCBSP",    1,    10,     1,    1,   0)

MUX_CFG("PWM0",     1,    4,      1,    1,   0)

MUX_CFG("PWM1",     1,    5,      1,    1,   0)

MUX_CFG("PWM2",     1,    6,      1,    1,   0)

MUX_CFG("VLINQEN",    0,    15,     1,    1,   0)
MUX_CFG("VLINQWD",    0,    12,     3,    3,   0)   //pinmux is represented by 2 bits     , so 0x11=3   3 bits is 111=7

MUX_CFG("EMACEN",    0,    31,     1,    1,   1)

MUX_CFG("GPIO3V",    0,    31,     1,    0,   1)

MUX_CFG("GPIO0",    0,    24,     1,    0,   1)
MUX_CFG("GPIO3",    0,    25,     1,    0,   0)
MUX_CFG("GPIO43_44",    1,    7,      1,    0,   0)
MUX_CFG( "GPIO46_47",    0,    22,     1,    0,   1)

MUX_CFG("RGB666",    0,    22,     1,    1,   1)

MUX_CFG("LOEEN",    0,    24,     1,    1,   1)
MUX_CFG("LFLDEN",    ​​0,    25,     1,    1,   0)
};

The interface provided in the kernel is in gpio.c in the linux-2.6.18_pro500/arch/arm/mach-davinci directory. This is a register-level driver. For related operations on this file,
see http://blog.csdn.net/langxing0508/archive/2008/12/25/3604043.aspx   A Brief Analysis of gpio.c in Da Vinci DM644X Platform (ARM9, Linux-2.6.10) BSP.
Well said, thanks here.

Below is my gpio driver
 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include

#include
#include
#include
#include
//#include
#define DEVICE_NAME "dm644x_gpios"   
#define GPIO_MAJOR 199
 

#define ZX_GPIO5          5    
#define ZX_GPIO6          6    
#define ZX_GPIO7          7    
 
static int davinci_dm644x_gpio_open(struct inode *inode, struct file *file)
{
 printk("open gpio,here is driver/n"); 
 const char *tag = NULL;
 int gpio5_value;
 int gpio6_value;
 int gpio7_value;

//  gpio_request(ZX_GPIO6, tag);
//  gpio_set_value(ZX_GPIO6, 0);
//  __gpio_set(ZX_GPIO6, 0);
//  printk("%s/n", tag);
 gpio_direction_output(ZX_GPIO5, 0);
 gpio_direction_output( ZX_GPIO6, 0);
 gpio_direction_output(ZX_GPIO7, 0);
 gpio5_value = gpio_get_value(ZX_GPIO5);
 gpio6_value = gpio_get_value(ZX_GPIO6);
 gpio7_value = gpio_get_value(ZX_GPIO7);

 printk("gpio5_value = %d, gpio6_value =%d, gpio7_value = %d/n", gpio5_value, gpio6_value, gpio7_value);
 return 0;
}
 
static int gpio_release(struct inode *inode,struct file *filp)
{
 return 0;
}

[page]
static int davinci_dm644x_gpio_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
  //   const char *tag;
    int    gpio5_value1;
     int    gpio5_value2;
    int    gpio6_value1;
       int    gpio6_value2;
    int    gpio7_value1;
       int    gpio7_value2 ;
       switch(cmd)
       {
       case 0:      //gpio = 0
    
      
      
           gpio_direction_output(ZX_GPIO5, 0); 
      gpio_direction_output(ZX_GPIO6, 0);
      gpio_direction_output(ZX_GPIO7, 0);
      gpio5_value1 = gpio_get_value(ZX_GPIO5);
      gpio6_value1 = gpio_get_value(ZX _GPIO6);
      gpio7_value1 = gpio_get_value(ZX_GPIO7);
       printk("gpio5_value1 = %d, gpio6_value1 = %d, gpio7_value1 = %d/n", gpio5_value1, gpio6_value1,gpio7_value1);
         //     }
 
              break;
       case 1:             //gpio = 1
              // if(0==arg)
              //{
          //  gpio_request(ZX_GPIO5, tag);
          //  printk("cmd = 1, ZX_GPIO5= %d/n", ZX_GPIO5);
            gpio_direction_output(ZX_GPIO5, 1); 
       gpio_direction_output(ZX_GPIO6, 1);
       gpio_direction_output(ZX_GPIO7, 1);
       gpio5_value2 = gpio_get_value(ZX_GPIO5);
       gpio6_value2 = gpio_get_value(ZX_GPIO6);
       gpio7_value2 = gpio_get_value(ZX_GPIO7);
      printk("gpio5_value2 = %d, gpio6_value2 =%d, gpio7_value2=%d/n", gpio5_value2, gpio6_value2, gpio7_value2);
              //}
             
              break;
       default:
              return -EINVAL;
       }
}
 

static const struct file_operations davinci_dm644x_gpio_fileops = {
       .owner    = THIS_MODULE,
       .open     = davinci_dm644x_gpio_open,
       .ioctl    = davinci_dm644x_gpio_ioctl,
    .release = gpio_release
};
 
static int __init davinci_dm644x_gpio_init(void)
{
       int ret;
 
       ret = register_chrdev(GPIO_MAJOR, DEVICE_NAME, &davinci_dm644x_gpio_fileops);
       if(ret < 0)
       {
              printk(DEVICE_NAME "register falid!/n");
              return ret;
       }
 
       printk (DEVICE_NAME" initialized/n" );
 
       return ret;
}
 
static void __exit davinci_dm644x_gpio_exit(void)
{
       unregister_chrdev(GPIO_MAJOR, DEVICE_NAME);
}
 
module_init(davinci_dm644x_gpio_init);
module_exit(davinci_dm644x_gpio_exit);
 
MODULE_AUTHOR("xxx <>") ;
MODULE_DESCRIPTION("Davinci DM644x gpio driver");
MODULE_LICENSE("GPL");

Below is the application

#include
#include
#include
#include
 
#define      on      (1)
#define      off     (0)
 
int main(void)
{
      
       int gpio_number = 0;
       int fd;
 


       fd = open("/dev/dm644x_gpios", 0);
       if (fd < 0)
       {
             perror("open device /dev/dm644x_gpios");
             exit(1);
       }
   
   printf("open gpio, here is app/n "); 
   sleep(1);
   printf("gpio_number = %d/n", gpio_number);
   sleep(1);   
    while (1) {   
       ioctl(fd, 1, 0);
    sleep(5);     
    ioctl(fd, 0, gpio_number);
    sleep(5);
        
       close(fd);
       return 0;
}


Below is the Makefile.
#
# Makefile for the skeleton device drivers.
#

KDIR=/root/work/linux-2.6.18_pro500           # Kernel directory
PWD := $(shell pwd)               # refers to the directory where the source program of the kernel module to be compiled is located. $(PWD) refers to the same directory as the Makefile, that is, the current directory.


ifeq ($(KERNELRELEASE), )

modules:
 $(MAKE) -C $(KDIR) M=$(PWD) modules              #Compile module rules,
 arm_v5t_le-gcc -o gpio_test app.c                #Compile application
 cp -f *.ko gpio_test /nfsroot/dm644x/filesys     #Copy the compiled driver and application to the file system of the spanner
 #scp char-reg.ko  zlh@192.168.1.160:/home/zlh/opt/filesystem
modules_install:
 $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:                                                               #Delete all generated files
 rm -rf gpio_test *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

else
 #obj-m += skeleton_dev_class.o
 obj-m += gpio_driver.o       #The name of the module you want to compile. This must correspond to the name of the C program file in the $(PWD) directory. If the C program file is world.c, then you must change it to obj-m = world.o. You can also
               #Obj-m = hello.o
               #Hello-objs = hello1.o, hello2.o    Compile multiple files to generate hello.o
endif


Just make it directly.     If it doesn't work, make ARCH=arm CROSS_COMPILE=arm_v5t_le-    plus the compiler tool

HyperTerminal operation:
insmod   gpio_drive.ko
mknod   /dev/dm644x_gpios   c   199   0
./gpio_test 

Keywords:dm6441 Reference address:GPIO driver for DM6441

Previous article:S3C2440 RTC bare metal program
Next article:ARM builds FTP server

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号