Reprinted please indicate the source: http://blog.csdn.net/lihaoweiV Li haowei's csdn blog
Simple LED driver on Samsung smdkc210 Development Board
Steps:
1. the lighting and removal of LED lights are controlled by gpio. We can find from the schematics diagram of the smdkc210 board that the gpio port corresponding to led4 is gpx1_4, for more information, see my other led-driven article "I/O ".
Gpfcon and gpfdat registers in ports
2. Add necessary header files
3. Implement the module framework, such as init, exit, and license.
4. Write the led_on and led_off functions.
4.1 apply for port gpx1_4
4.2 set gpx1con [4] to output. In the preceding two steps, use the gpio_request_one function.
4.3 set gpx1dat [4] to 0 (on) 1 (off)
5. Write makefile
**************************************** ** Led_test.c ************************************* *********************************
# Include <Linux/init. h>
# Include <Linux/module. h>
# Include <Linux/delay. h> // when setting the value of the GPX port, you need to wait for a while to make the output stable. Therefore, the mdelay function is used.
# Include <Linux/gpio. h> // The function for applying for the gpio port, and the gpio port address defined by Samsung.
Static int led_on (void)
{
Int err;
Err = gpio_request_one (exynos4_gpx1 (4), gpiof_out_init_high, "gpx1 ");
If (ERR ){
Printk (kern_alert "failed to request gpx1 for LED control \ n ");
Return err;
}
Mdelay (100 );
Gpio_set_value (exynos4_gpx1 (4), 0 );
Mdelay (100 );
Gpio_free (exynos4_gpx1 (4 ));
Return 0;
}
Static int led_off (void)
{
Int err;
Err = gpio_request_one (exynos4_gpx1 (4), gpiof_out_init_high, "gpx1 ");
If (ERR ){
Printk (kern_alert "failed to request gpx1 for LED control \ n ");
Return err;
}
Mdelay (100 );
Gpio_set_value (exynos4_gpx1 (4), 1 );
Mdelay (100 );
Gpio_free (exynos4_gpx1 (4 ));
Return 0;
}
Static int led_init (void)
{
Printk (kern_alert "LED is on \ n ");
Led_on (); // enable led4
Return 0;
}
Static void led_exit (void)
{
Printk (kern_alert "LED is off \ n ");
Led_off (); // disable led4
}
Module_init (led_init );
Module_exit (led_exit );
Module_author ("Alvin Lee ");
Module_license ("GPL ");
**************************************** * Makefile ************************************* *********************************
OBJ-M: = led_test.o
Kdir: =/home2/alvinlee/v310_2/Android-kernel-Samsung-Dev
PWD: = $ (shell PWD)
Default:
$ (Make)-C $ (kdir) subdirs = $ (PWD) Modules
Clean:
Rm-RF *. Ko
Rm-RF *. Mod .*
Rm-RF. *. cmd
Rm-RF *. o