学习设备树之(十一)Backlight

本文介绍了一线触控LCD背光控制在Tiny4412开发板上的驱动移植过程,包括设备树配置及代码实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开发板:tiny4412SDK + S702 + 4GB Flash
要移植的内核版本:Linux-4.4.0 (支持device tree)
u-boot版本:友善之臂自带的 U-Boot 2010.12
busybox版本:busybox 1.25

目标:
由于 tiny4412 的lcd背光控制采用的一线触控,并不开源,因此移植友善自带的linux3.5 内核中的背光相关部分驱动程序。

原理图:
这里写图片描述

设备树:

        backlight_demo@139D0000{
                compatible         = "tiny4412,backlight_demo";
                reg = <0x139D0000  0x14>;
                tiny4412,backlight = <&gpx1 2 GPIO_ACTIVE_HIGH>;
                pinctrl-names = "backlight_out","backlight_in";
                pinctrl-0 = <&backlight_out>;
                pinctrl-1 = <&backlight_in>;
                interrupts = <0 40 0>;
                clocks = <&clock CLK_PWM>;
                clock-names = "timers";
        };
&pinctrl_1 {
        backlight_out: backlight_out{
                samsung,pins = "gpx1-2";
                samsung,pin-function = <1>;
                samsung,pin-pud = <0>;
                samsung,pin-drv = <0>;
        };
         backlight_in: backlight_in{
                samsung,pins = "gpx1-2";
                samsung,pin-function = <0>;
                samsung,pin-pud = <0>;
                samsung,pin-drv = <0>;
        };
};

代码:

//参考友善自带的 Tiny4412_1wire_host.c                                                                                 
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/export.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/pwm.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/time.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
/*
    PWM 时钟频率 100M
    100M / 250 / 4 = 100000
    1/100000 = 10us
*/

static int              major;
static struct   cdev    backlight_cdev;
static struct   class   *cls;
static struct pinctrl   *pctrl;
static struct pinctrl_state *pstate_in;
static struct pinctrl_state *pstate_out;
static int              one_write_pin;

struct TIMER_BASE
{
    unsigned int TCFG0;
    unsigned int TCFG1;
    unsigned int TCON;
    unsigned int TCNTB0;
    unsigned int TCMPB0;
    unsigned int TCNTO0;
    unsigned int TCNTB1;
    unsigned int TCMPB1;
    unsigned int TCNTO1;
    unsigned int TCNTB2;
    unsigned int TCMPB2;
    unsigned int TCNTO2;
    unsigned int TCNTB3;
    unsigned int TCMPB3;
    unsigned int TCNTO3;
    unsigned int TCNTB4;
    unsigned int TCBTO4;
    unsigned int TINT_CSTAT;
};

volatile static struct TIMER_BASE *timer = NULL;

static volatile unsigned int io_bit_count;
static volatile unsigned int io_data;

enum
{
    IDLE,
    START,
    REQUEST,
    WAITING,
    RESPONSE,
    STOPING,
} one_wire_status = IDLE;

static inline void stop_timer_for_1wire(void)
{
    unsigned long tcon;
    tcon = timer->TCON;
    tcon &= ~(1 << 16);
    timer->TCON = tcon;
}

static irqreturn_t timer_for_1wire_interrupt(int irq, void *dev_id)
{
    unsigned int tint;
    tint = timer->TINT_CSTAT;
    tint |= 0x100;
    timer->TINT_CSTAT = tint;
    //printk("timer_for_1wire_interrupt\n");
    io_bit_count--;

    switch (one_wire_status)
    {
        case START:

            if (io_bit_count == 0)
            {
                io_bit_count = 16;
                one_wire_status = REQUEST;
            }

            break;
        case REQUEST:
            gpio_set_value(one_write_pin, io_data & (1U << 31));
            io_data <<= 1;

            if (io_bit_count == 0)
            {
                io_bit_count = 2;
                one_wire_status = WAITING;
            }

            break;
        case WAITING:

            if (io_bit_count == 0)
            {
                io_bit_count = 32;
                one_wire_status = RESPONSE;
            }

            if (io_bit_count == 1)
            {
                pinctrl_select_state(pctrl, pstate_in);
                gpio_set_value(one_write_pin, 1);
            }

            break;
        case RESPONSE:
            io_data = (io_data << 1) | gpio_get_value(one_write_pin);

            if (io_bit_count == 0)
            {
                io_bit_count = 2;
                one_wire_status = STOPING;
                gpio_set_value(one_write_pin, 1);
                pinctrl_select_state(pctrl, pstate_out);
                //one_wire_session_complete(one_wire_request, io_data);
            }

            break;
        case STOPING:

            if (io_bit_count == 0)
            {
                one_wire_status = IDLE;
                stop_timer_for_1wire();
            }

            break;
        default:
            stop_timer_for_1wire();
    }

    return IRQ_HANDLED;
}


static const unsigned char crc8_tab[] =
{
    0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
    0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
    0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
    0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
    0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
    0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
    0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
    0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
    0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
    0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
    0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
    0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
    0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
    0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
    0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
    0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
    0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
    0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
    0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
    0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
    0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
    0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
    0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
    0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
    0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
    0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
    0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
    0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
    0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
    0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
    0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
    0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3,
};

#define crc8_init(crc) ((crc) = 0XACU)
#define crc8(crc, v) ( (crc) = crc8_tab[(crc) ^(v)])

static void start_one_wire_session(unsigned char req)
{
    unsigned int tcon;
    printk("backlight_write\n");
    one_wire_status = START;
    gpio_set_value(one_write_pin, 1);
    pinctrl_select_state(pctrl, pstate_out);
    // IDLE to START
    {
        unsigned char crc;
        crc8_init(crc);
        crc8(crc, req);
        io_data = (req << 8) + crc;
        io_data <<= 16;
    }
    io_bit_count = 1;
    pinctrl_select_state(pctrl, pstate_out);
    timer->TCNTB3 = 650;
    //init tranfer and start timer
    tcon = timer->TCON;
    tcon &= ~(0xF << 16);
    tcon |= (1 << 17);
    timer->TCON = tcon;
    tcon |= (1 << 16);
    tcon |= (1 << 19);
    tcon &= ~(1 << 17);
    timer->TCON = tcon;
    timer->TINT_CSTAT |= 0x08;
    gpio_set_value(one_write_pin, 0);
}

static ssize_t backlight_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
{
    unsigned char reg, ret;
    ret = copy_from_user(&reg, buf, 1);

    if (ret < 0)
    {
        printk("%s copy_from_user error\n", __func__);
    }

    if (reg > 127)
        { reg = 127; }

    start_one_wire_session(reg + 0x80);
    return 1;
}


static int backlight_open(struct inode *inode, struct file *file)
{
    printk("backlight_open\n");
    return 0;
}

static int backlight_release(struct inode *inode, struct file *file)
{
    printk("backlight_exit\n");
    return 0;
}

static struct file_operations backlight_fops =
{
    .owner              = THIS_MODULE,
    .open               = backlight_open,
    .release            = backlight_release,
    .write              = backlight_write,
};
static struct device *dev;
static struct clk *base_clk;
static struct resource *res = NULL, *irq = NULL;
static int backlight_probe(struct platform_device *pdev)
{
    int ret;
    dev_t devid;
    dev = &pdev->dev;
    printk("enter %s\n", __func__);
    pctrl = devm_pinctrl_get(dev);

    if (pctrl == NULL)
    {
        printk("devm_pinctrl_get error\n");
        return -EINVAL;
    }

    pstate_in  = pinctrl_lookup_state(pctrl, "backlight_in");
    pstate_out = pinctrl_lookup_state(pctrl, "backlight_out");

    if (pstate_in == NULL || pstate_out == NULL)
    {
        printk("pinctrl_lookup_state error\n");
        return -EINVAL;
    }

    one_write_pin = of_get_named_gpio(dev->of_node, "tiny4412,backlight", 0);

    if (!one_write_pin)
    {
        printk("of_get_named_gpio error\n");
        return -EINVAL;
    }

    devm_gpio_request_one(dev, one_write_pin, GPIOF_OUT_INIT_HIGH, "one_write");
    //pinctrl_select_state(pctrl, pstate);
    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

    if (res == NULL)
    {
        printk("platform_get_resource error\n");
        return -EINVAL;
    }

    base_clk = devm_clk_get(&pdev->dev, "timers");

    if (IS_ERR(base_clk))
    {
        dev_err(dev, "failed to get timer base clk\n");
        return PTR_ERR(base_clk);
    }

    ret = clk_prepare_enable(base_clk);

    if (ret < 0)
    {
        dev_err(dev, "failed to enable base clock\n");
        return ret;
    }

    timer = devm_ioremap_resource(&pdev->dev, res);

    if (timer == NULL)
    {
        printk("devm_ioremap_resource error\n");
        return -EINVAL;
    }

    printk("timer: %x\n", (unsigned int)timer);
    timer->TCFG0  = 0xf00;
    timer->TCFG1  = 0x10004;
    irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

    if (irq == NULL)
    {
        printk("platform_get_resource irq error\n");
        return -EINVAL;
    }

    ret = devm_request_irq(dev, irq->start, timer_for_1wire_interrupt , IRQF_TIMER, "backlight", NULL);

    if (ret)
    {
        dev_err(dev, "unable to request irq\n");
        return -EINVAL;
    }

    start_one_wire_session(0x60);

    if (alloc_chrdev_region(&devid, 0, 1, "backlight") < 0)
    {
        printk("%s ERROR\n", __func__);
        return -EINVAL;
    }

    major = MAJOR(devid);
    cdev_init(&backlight_cdev, &backlight_fops);
    cdev_add(&backlight_cdev, devid, 1);
    cls = class_create(THIS_MODULE, "backlight_demo");
    device_create(cls, NULL, MKDEV(major, 0), NULL, "backlight");
    return 0;
}

static int backlight_remove(struct platform_device *pdev)
{
    printk("enter %s\n", __func__);
    device_destroy(cls, MKDEV(major, 0));
    class_destroy(cls);
    cdev_del(&backlight_cdev);
    unregister_chrdev_region(MKDEV(major, 0), 1);
    devm_pinctrl_put(pctrl);
    devm_free_irq(dev, irq->start, NULL);
    clk_disable_unprepare(base_clk);
    devm_gpio_free(dev, one_write_pin);
    return 0;
}

static const struct of_device_id backlight_dt_ids[] =
{
    { .compatible = "tiny4412,backlight_demo", },
    {},
};

MODULE_DEVICE_TABLE(of, backlight_dt_ids);

static struct platform_driver backlight_driver =
{
    .driver        = {
        .name      = "backlight_demo",
        .of_match_table    = of_match_ptr(backlight_dt_ids),
    },
    .probe         = backlight_probe,
    .remove        = backlight_remove,
};

static int backlight_init(void)
{
    int ret;
    printk("enter %s\n", __func__);
    ret = platform_driver_register(&backlight_driver);

    if (ret)
    {
        printk(KERN_ERR "backlight demo: probe faid backlight: %d\n", ret);
    }

    return ret;
}

static void backlight_exit(void)
{
    printk("enter %s\n", __func__);
    platform_driver_unregister(&backlight_driver);
}

module_init(backlight_init);
module_exit(backlight_exit);
MODULE_LICENSE("GPL");
/** *my first driver * */ #include <linux/types.h> #include <linux/kernel.h> #include <linux/delay.h> #include <linux/ide.h> #include <linux/init.h> #include <linux/module.h> #include <linux/errno.h> #include <linux/gpio.h> #include <linux/cdev.h> #include <linux/device.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> #define LED_MAJOR 200 //主设备号 #define LED_NAME "LED" //驱动名称 #define NEWCHRLED_NAME "newchrled" #define NEWCHRLED_COUNT 1 struct newchrled_dev { struct cdev cdev; struct class *class;/*类:为了自动创建节点*/ struct device *device;/*设备:为了自动创建节点*/ dev_t devid; //设备号 int major; //主设备号 int minor; //次设备号 }; struct newchrled_dev newchrled; //led设备 #if 0 backlight { compatible = "pwm-backlight"; pwms = <&pwm1 0 5000000>; brightness-levels = <0 4 8 16 32 64 128 255>; default-brightness-level = <7>; status = "okay"; }; #endif static int __init dtsof_init(void) { int ret = 0; // /*1、找到backlight节点,/路径是:/backlight /*/ struct device_node *bl_nd = NULL;/*节点*/ struct property *comppro = NULL; const char **str = NULL; u32 def_value = 0; /*内核动态申请内存*/ u32 *brival; u32 elemsize = 0; bl_nd = of_find_node_by_path("/backlight"); if (bl_nd == NULL){ /*失败*/ ret = -EINVAL; goto fail_findnd; } /*2、获取属性*/ comppro = of_find_property(bl_nd,"compatible",NULL); if (comppro == NULL){ /*失败*/ ret = -EINVAL; goto fail_findpro; }else{ printk("compatible = %s",(char*)comppro->value); } ret = of_property_read_string(bl_nd,"status",str); if (ret < 0){ goto fail_rs; } /*3、获取数字属性值*/ ret = of_property_read_u32(bl_nd,"default-brightness-level",&def_value); if (ret<0){ goto fail_read32; }else{ printk("default-brightness-level = %d \r\n",def_value); } /*4、获取数组类型的属性*/ elemsize = of_property_count_elems_of_size(bl_nd,"brightness-levels",sizeof(u32)); if (elemsize<0){ ret = -ENAVAIL; goto fail_readele; }else{ printk("brightness-levels = %d \r\n",ret); } /*申请内存*/ brival = kmalloc(elemsize * sizeof(u32),GFP_KERNEL); if(!brival){ ret = -EINVAL; goto fail_mem; } /*获取数组*/ ret = of_property_read_u32_array(bl_nd,"brightness-levels",brival,elemsize); if (ret<0){ ret = -EINVAL; goto fail_read32array; } else { u8 i = 0; for (i = 0; i < elemsize; i++){ printk("brightness-levels[%d] = %d \r\n",i,*(brival+i)); } } kfree(brival); return 0; fail_read32: fail_findnd: fail_findpro: fail_rs: fail_readele: fail_mem: fail_read32array: return ret; } static void __exit dtsof_exit(void) { } //模块加载函数 module_init(dtsof_init); //模块卸载 module_exit(dtsof_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("qhy"); 解释详细
最新发布
03-30
<think>好的,我现在需要帮用户分析他提供的这个Linux内核模块代码。首先,用户可能刚接触内核驱动开发,所以我要尽量详细地解释代码结构和功能,同时指出可能的问题和注意事项。 首先看代码结构,这是一个简单的字符设备驱动,但用户提供的注释是“my first driver”,所以可能还在学习阶段。代码中包含了各种头文件,比如linux/module.h、linux/cdev.h等,这些都是编写内核模块必需的。模块的初始化和退出函数分别是dtsof_init和dtsof_exit,这里可能涉及设备树(Device Tree)的操作,因为函数名里有dtsof,可能是指Device Tree Source的操作。 接下来看结构体newchrled_dev,里面包含了字符设备cdev、设备号、类、设备等,这是标准的字符设备驱动结构,用于自动创建设备节点。不过,在代码中虽然定义了结构体变量newchrled,但实际初始化部分似乎没有完成,比如cdev的初始化、设备号的注册,这可能是个问题,用户可能还没写完这部分代码。 然后看dtsof_init函数,它的主要操作是解析设备树中的backlight节点。首先通过of_find_node_by_path找到路径为/backlight的节点。如果找不到,返回错误。接着获取compatible属性的值,打印出来。这里用了of_find_property,然后访问value字段,但需要注意的是,compatible属性可能有多个字符串,这里直接强制转换为char*可能有问题,特别是如果属性值不是以NULL结尾的话。不过内核中的属性通常是这样存储的,所以可能没问题,但需要确认。 然后尝试读取status属性的字符串,但用户代码里用了of_property_read_string,传入的str参数是const char **类型,但用户代码里str没有被初始化,这可能造成内核崩溃,因为函数会尝试将读取的字符串指针赋值给*str,但str本身没有分配内存,这里应该传入一个指针变量的地址,例如定义一个const char *status_str; 然后传&status_str。这里存在严重问题,需要指出。 接下来读取default-brightness-level的u32值,并打印。这部分看起来正确。然后获取brightness-levels数组的元素数量,这里用了of_property_count_elems_of_size,正确。然后申请内存,读取数组内容,并逐个打印。这部分处理正确,但需要注意内存分配失败的情况,用户代码里确实检查了brival是否为NULL,处理了错误。 在错误处理部分,goto标签的顺序可能有问题,比如fail_read32可能跳过了某些释放资源的步骤。此外,在失败的情况下,可能需要释放已分配的内存或释放设备树节点,但代码里没有这些操作,可能存在资源泄漏。例如,bl_nd是通过of_find_node_by_path获取的,应该用of_node_put释放,但代码中没有,这会导致节点引用计数泄漏。 模块退出函数dtsof_exit是空的,这意味着模块卸载时没有清理资源,比如注销设备号、销毁类等,这会导致模块无法正确卸载,可能出现资源残留。 另外,整个驱动虽然涉及设备树解析,但并没有实际注册字符设备或创建设备节点,所以用户可能只完成了部分功能,或者这个模块只是用来演示设备树解析的过程,而不是完整的驱动。需要指出这一点,说明当前代码的功能和缺失的部分。 此外,代码中的#if 0块注释了一个设备树节点,可能是示例,但被注释掉了,用户可能需要注意这部分内容是否相关。 最后,模块的许可证声明正确,符合GPL,这是必须的,否则无法加载到内核中。 总结需要向用户解释代码的结构,指出各个部分的作用,特别是设备树解析的过程,同时指出代码中的错误和遗漏,比如status字符串读取的问题、资源泄漏、模块退出函数未实现等,帮助用户理解并改进代码。</think>以下是对这段Linux内核模块代码的详细解析: ### 一、代码结构分析 #### 1. 头文件部分 包含标准Linux驱动开发头文件,如: - `module.h`:模块加载/卸载 - `cdev.h``:字符设备操作 - `of*.h`:设备树(Device Tree)操作接口 #### 2. 设备定义 ```c struct newchrled_dev { struct cdev cdev; // 字符设备 struct class *class; // 设备类 struct device *device; // 设备节点 dev_t devid; // 设备号 int major; // 主设备号 int minor; // 次设备号 }; ``` 此结构体用于管理字符设备信息,但当前代码未完整初始化该结构体。 #### 3. 设备树解析函数 `dtsof_init()` ##### (1) 查找设备树节点 $$ \text{of\_find\_node\_by\_path("/backlight")} $$ 通过路径查找设备树中的`backlight`节点,对应设备树中: ```dts backlight { compatible = "pwm-backlight"; // ... }; ``` ##### (2) 属性解析操作 | 属性操作函数 | 作用 | 数学表达式表示 | |----------------------------------|--------------------------|-------------------------| | `of_find_property()` | 查找节点属性 | $P = \text{find}(nd, prop)$ | | `of_property_read_string()` | 读取字符串属性 | $S = \text{read}(nd, prop)$ | | `of_property_read_u32()` | 读取32位整数属性 | $n = \int prop \, dnd$ | | `of_property_read_u32_array()` | 读取32位整数数组属性 | $\vec{v} = \text{read}(nd, prop, len)$ | #### 4. 模块加载/卸载 - `module_init(dtsof_init)`:内核模块加载时自动执行初始化 - `module_exit(dtsof_exit)`:卸载时执行清理(当前为空实现) ### 二、关键问题说明 #### 1. 设备树解析问题 - **字符串读取缺陷**: ```c const char **str = NULL; // 未初始化指针 of_property_read_string(bl_nd,"status",str); ``` 应改为: ```c const char *status_str; of_property_read_string(bl_nd, "status", &status_str); ``` - **内存泄漏风险**: 未调用`of_node_put(bl_nd)`释放节点引用计数,应添加: ```c if (bl_nd) of_node_put(bl_nd); ``` #### 2. 驱动框架缺失 - 未实现字符设备注册 (`cdev_init`, `cdev_add`) - 未创建设备节点 (`device_create`) - 未处理设备操作函数集 (`file_operations`) #### 3. 资源清理问题 `dtsof_exit()`函数为空实现,需要添加: ```c static void __exit dtsof_exit(void) { device_destroy(newchrled.class, newchrled.devid); class_destroy(newchrled.class); cdev_del(&newchrled.cdev); unregister_chrdev_region(newchrled.devid, NEWCHRLED_COUNT); } ``` ### 三、执行流程示意图 ``` 模块加载 │ ├─→ dtsof_init() │ │ │ ├─查找设备树节点 │ ├─解析compatible属性 │ ├─读取status字符串 │ ├─获取default-brightness-level │ └─解析brightness-levels数组 │ 模块卸载 └─→ dtsof_exit() (当前无操作) ``` ### 四、改进建议 1. 添加字符设备注册逻辑 2. 实现`file_operations`操作集 3. 完善错误处理链: ```c fail_read32array: kfree(brival); fail_readele: of_node_put(bl_nd); // ... ``` 4. 添加`MODULE_DESCRIPTION`等元信息 该代码当前实现了设备树解析的基础功能,但尚未构成完整驱动,后续需要结合硬件操作完善设备控制逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值