Configuration of Gpio
Linux Application header file for Gpio
Include/linux/gpio.h
Gpio Configuration function header file for Samsung platform
Arch/arm/plat-samsung/include/plat/gpio-cfg.h, which includes the configuration functions of all Samsung processors.
Samsung Platform Exynos series platform, gpio configuration parameter macro definition header file
Arch/arm/plat-samsung/include/plat/gpio-cfg.h,gpio pin Pull Low pull high configuration parameters and so on.
Samsung Platform 4412 platform, GPIO macro definition header file, already included in header file Gpio.h
Arch/arm/mach-exynos/include/mach/gpio-exynos4.h, including all GPIO macro definitions for the 4412 processor. Light LED Light
LED pin request function and assignment
Under Linux Platform
Gpio_request
Gpio_set_value
Samsung Platform configuration Gpio function
S3c_gpio_cfgpin
GPIO configuration output mode macro variable
S3c_gpio_output
circuit diagram corresponding to pins
Sample Code
#include <linux/init.h> #include <linux/module.h>/* Driver Registration header file containing the drive structure and the registered uninstall function/* #include <linux/platform _device.h>/* Registration Miscellaneous equipment/* #include <linux/miscdevice.h>//* Registration device Node/#include <linux/fs.h>/* Linux application Gpio header file/* #include <linux/gpio.h>/* Samsung Platform GPIO configuration function Header/////* Samsung Platform Exynos series platform, gpio configuration parameter macro definition header file */#include <plat/gpio-cfg.h> #include <mach/gpio.h>/* Samsung 4412 Platform, GPIO macro definition header file * * #include <mach/exynos4.h> #define
Driver_name "Hello_ctl" #define Device_name "Hello_ctl" Module_license ("Dula BSD/GPL");
Module_aythor ("Chenmiaohong"); Static long hello_ioctl (struct file *files, unsigned int cmd, unsigned long arg) {PRINTK ("cmd is%d,arg are%d\n", CMD,
ARG);
if (cmd > 1) {printk (Kern_emerg "cmd is 0 or 1\n");
} if (Arg > 1) {PRINTK (Kern_emerg "Arg is only 1\n");
} gpio_set_value (EXYNOS4_GPL2 (0), CMD);
return 0; static struct File_operations Hello_ops = {. Owner = This_module,. Open = Hello_open,.Release = Hello_release,. unlocked_ioctl = Hello_ioctl,}; static struct Miscdevice Hello_dev = {. minor = Misc_dynamic_minor,. Name = Device_name,. FoPs = &hello_o
PS,};
static int hello_release (struct inode *inode, struct file *file) {printk (Kern_emerg "Hello release\n");
return 0;
static int Hello_open (struct inode *inode, struct file *file) {printk (Kern_emerg "Hello open\n");
return 0;
static int hello_probe (struct platform_device *pdv) {int ret;
PRINTK (Kern_emerg "\tinitialized\n");
ret = gpio_request (exynos4_gpl2 (0), "LEDs");
if (ret<0) {PRINTK (Kern_emerg "\tgpio_request exynos4_gpl2 (0) failed\n");
return ret;
} s3c_gpio_cfgpin (EXYNOS4_GPL2 (0), gpio_output);
Gpio_set_value (EXYNOS4_GPL2 (0), 0);
Misc_register (&hello_dev);
return 0;
static int hello_remove (struct platform_device *pdv) {PRINTK (Kern_emerg "\tremove\n");
Misc_deregister (&hello_dev);
return 0; } Static VoiD hello_shutdown (struct Platform_device *pdv) {;}
static int hello_suspend (struct platform_device *pdv,pm_message_t PMT) {return 0;} static int Hello_resume (struct platform_device *pdv) {return 0;} struct platform_driver = {. hello_driver = Hello_probe,. remove = Hello_remove,. Shutdown = Hello_shutdown,. Suspend = Hello_suspend,. Resume = Hel
Lo_resume,. Driver = {. Name = driver_name,. Owner = This_module,}};
tatic int Hello_init (void) {int driverstate;
PRINTK (Kern_emerg "HELLO World enter!\n");
Driverstate = Platform_driver_register (&hello_driver);
PRINTK (Kern_emerg "\tdriverstate is%d\n", driverstate);
return 0;
} static void Hello_exit (void) {PRINTK (Kern_emerg "Hello World exit!\n");
Platform_driver_unregister (&hello_driver);
} module_init (Hello_init);
Module_exit (Hello_exit);
Use make Menuconfig to cancel the Enable Led_ctl in the kernel source code. Then write the application call program
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h >
#include <unistd.h>
#include <sys/ioctl.h>
main () {
int fd;
Char *hello_node = "/dev/hello_ctl";
/*O_RDWR read-only open, O_ndelay non-blocking mode * * (
FD = open (hello_node,o_rdwr| O_ndelay) <0) {
printf ("APP open%s failed", Hello_node);
}
else{
printf ("APP Open%s Success", Hello_node);
IOCTL (fd,1,1);
Sleep (3);
IOCTL (fd,0,1);
Sleep (3);
IOCTL (fd,1,1);
}
Close (FD);
}
Under file make causes the driver to compile the. ko file, compile the build executable using the Cross compilation tool, download the TFTP server to the EXYNOS4412 Development Board, load the driver using Insmod, and Ls/dev will see the new device node Hello_ CTL. You can see the LEDs flashing every 3 seconds at this time using the./execute executable file.