欢迎来到天天文库
浏览记录
ID:47102403
大小:81.64 KB
页数:26页
时间:2019-08-03
《android button light 流程分析(一) — driver》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、androidbuttonlight流程分析(一)—driver一、led-classled-class是buttonlightdriver的核心层,代码位于drivers/leds/目录下,提供了一些数据结构和接口,其中创建了一个leds设备类,用于管理系统所有的led,代码如下:[cpp]viewplaincopyprint?1.static int __init leds_init(void) 2.{ 3. leds_class = class_create(THIS_MODULE, "l
2、eds"); 4. if (IS_ERR(leds_class)) 5. return PTR_ERR(leds_class); 6. leds_class->suspend = led_suspend; 7. leds_class->resume = led_resume; 8. return 0; 9.} 10. 11.static void __exit leds_exit(void) 12.{ 13. class_destroy(le
3、ds_class); 14.} 15. 16.subsys_initcall(leds_init); 17.module_exit(leds_exit); staticint__initleds_init(void){leds_class=class_create(THIS_MODULE,"leds");if(IS_ERR(leds_class))returnPTR_ERR(leds_class);leds_class->suspend=led_suspend;leds_class->resum
4、e=led_resume;return0;}staticvoid__exitleds_exit(void){class_destroy(leds_class);}subsys_initcall(leds_init);module_exit(leds_exit);创建成功后我们可以在/sys/class目录下面看到leds目录,并注册了统一的休眠和唤醒函数:[cpp]viewplaincopyprint?1./** 2. * led_classdev_suspend - suspend an led_cla
5、ssdev. 3. * @led_cdev: the led_classdev to suspend. 4. */ 5.void led_classdev_suspend(struct led_classdev *led_cdev) 6.{ 7. led_cdev->flags
6、= LED_SUSPENDED; 8. led_cdev->brightness_set(led_cdev, 0); 1.} 2.EXPORT_SYMBOL_GPL(led_classdev_suspen
7、d); 3. 4./** 5. * led_classdev_resume - resume an led_classdev. 6. * @led_cdev: the led_classdev to resume. 7. */ 8.void led_classdev_resume(struct led_classdev *led_cdev) 9.{ 10. led_cdev->brightness_set(led_cdev, led_cdev->brightness); 11. l
8、ed_cdev->flags &= ~LED_SUSPENDED; 12.} 13.EXPORT_SYMBOL_GPL(led_classdev_resume); 14. 15.static int led_suspend(struct device *dev, pm_message_t state) 16.{ 17. struct led_classdev *led_cdev = dev_get_drvdata(dev); 18. 19. if (led_cdev->flag
9、s & LED_CORE_SUSPENDRESUME) 20. led_classdev_suspend(led_cdev); 21. 22. return 0; 23.} 24. 25.static int led_resume(struct device *dev) 26.{ 27. struct led_classdev *led_cdev = dev_get_drvdata(d
此文档下载收益归作者所有