Android system:led class Node add

Source: Internet
Author: User

One, the code:

Leds_4412.c

#include <linux/kernel.h>#include<linux/module.h>#include<linux/miscdevice.h>#include<linux/device.h>#include<linux/fs.h>#include<linux/types.h>#include<linux/moduleparam.h>#include<linux/slab.h>#include<linux/ioctl.h>#include<linux/cdev.h>#include<linux/delay.h>#include<linux/gpio.h>#include<mach/gpio.h>#include<plat/gpio-cfg.h>#include<linux/leds.h>structLed_desc {intGpio; Char*name;};Static structLed_desc led_gpios[] ={{EXYNOS4212_GPM4 (0),"led1"}, {exynos4212_gpm4 (1),"Led2"}, {exynos4212_gpm4 (2),"led3"}, {exynos4212_gpm4 (3),"led4"},};structled_classdev_4412 {structLed_classdev Cdev; intGpio;};Static structled_classdev_4412 *Led_devs;Static voidbrightness_set_4412 (structLed_classdev *Led_cdev,enumled_brightness Brightness) {    structled_classdev_4412 *dev = (structled_classdev_4412 *) Led_cdev; Led_cdev->brightness =brightness; if(Brightness! =led_off) gpio_set_value (Dev->gpio,0); ElseGpio_set_value (Dev->gpio,1);}Static intLeds_init (void){    inti; intret; /*1. Alloc Led_classdev*/Led_devs= Kzalloc (sizeof(structled_classdev_4412) *sizeof(Led_gpios)/sizeof(led_gpios[0]), Gfp_kernel); if(Led_devs = =NULL) {PRINTK ("No memory for device\n"); return-Enomem; }         for(i =0; I <sizeof(Led_gpios)/sizeof(led_gpios[0]); i++) {S3c_gpio_cfgpin (Led_gpios[i].gpio, s3c_gpio_output); Gpio_set_value (Led_gpios[i].gpio,1); /*2. Set*/led_devs[i].cdev.max_brightness=Led_full; Led_devs[i].cdev.brightness_set=brightness_set_4412; Led_devs[i].cdev.flags=Led_core_suspendresume; Led_devs[i].cdev.brightness=Led_off; Led_devs[i].cdev.name=Led_gpios[i].name; //Led_devs[i].cdev.default_trigger = "Timer";Led_devs[i].gpio =Led_gpios[i].gpio; /*3. Led_classdev_register*/ret= Led_classdev_register (NULL, &Led_devs[i].cdev); if(ret) {i--;  while(I >=0) {Led_classdev_unregister (&Led_devs[i].cdev); I--;            } kfree (Led_devs); return-EIO; }    }        return 0;}Static voidLeds_exit (void){    inti;  for(i =0; I <sizeof(Led_gpios)/sizeof(led_gpios[0]); i++) {Led_classdev_unregister (&Led_devs[i].cdev); } kfree (Led_devs);} Module_init (Leds_init); Module_exit (Leds_exit); Module_license ("GPL"); Module_author ("Sheldon");

Second, the compilation test:

Put the leds_4412.c in the drivers/leds.
Modify Drivers/leds/makefile:
Obj-y + = LEDS_4412.O

Reconfigure the kernel
Make Menuconfig

Config_leds_class
Config_leds_triggers
Config_leds_trigger_timer

Device Drivers
LED Support
[*] LED Class Support
[*] LED Trigger Support
<*> LED Timer Trigger

Recompile kernel: Make zimage

Android system:led class Node add

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.