Linux设备模型之led子系统

时代不同了,连led都成子系统了,针对内核提供的通用模型,分析一下,好久没写文章了也!

代码位于drivers/leds下,看一下Makefile 模型文件主要是:

# LED Core

obj-$(CONFIG_NEW_LEDS)            += led-core.o

obj-$(CONFIG_LEDS_CLASS)        += led-class.o

obj-$(CONFIG_LEDS_TRIGGERS)        += led-triggers.o

直接看led-core文件吧,这个文件无比个性,主体内容四行

DECLARE_RWSEM(leds_list_lock);
EXPORT_SYMBOL_GPL(leds_list_lock);
LIST_HEAD(leds_list);                                         //链接所有led的全局链表
EXPORT_SYMBOL_GPL(leds_list);

再来看下led-class.c函数,这里先来介绍一下描述led的核心结构体

struct led_classdev {
    const char        *name;                                                                                   //名字
    int             brightness;                                                                                     //亮度值,也可以用来表示开关特性
    int             max_brightness;                                                                           //允许的最大亮度值
    int             flags;                                                                                               //标志

    /* Lower 16 bits reflect status */
#define LED_SUSPENDED        (1 << 0)
    /* Upper 16 bits reflect control information */
#define LED_CORE_SUSPENDRESUME    (1 << 16)

    /* Set LED brightness level */
    /* Must not sleep, use a workqueue if needed */
    void        (*brightness_set)(struct led_classdev *led_cdev,                 //核心回调函数,当设置/sys/class/leds/下的led接口里的brightness属性文件时,会回调该函数
                      enum led_brightness brightness);
    /* Get LED brightness level */
    enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);         //核心回调函数,当获得led当前值时会调用

    /* Activate hardware accelerated blink, delays are in
     * miliseconds and if none is provided then a sensible default
     * should be chosen. The call can adjust the timings if it can't
     * match the values specified exactly. */
    int        (*blink_set)(struct led_classdev *led_cdev,
                     unsigned long *delay_on,
                     unsigned long *delay_off);

    struct device        *dev;                                                                                  //嵌入的标准设备模型
    struct list_head     node;            /* LED Device list */                                //上面提到的全局led设备的挂接点
    const char        *default_trigger;    /* Trigger to use */

#ifdef CONFIG_LEDS_TRIGGERS
    /* Protects the trigger data below */
    struct rw_semaphore     trigger_lock;    

    struct led_trigger    *trigger;
    struct list_head     trig_list;
    void            *trigger_data;
#endif
};


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/22708.html