sys/class 下文件节点创建实例

1 创建读版本号节点  

 firmware_class = class_create(THIS_MODULE, "ms-touchscreen-msg20xx");

    if (IS_ERR(firmware_class))
        pr_err("Failed to create class(firmware)!\n");
    firmware_cmd_dev = device_create(firmware_class, NULL, 0, NULL, "device");
    if (IS_ERR(firmware_cmd_dev))
        pr_err("Failed to create device(firmware_cmd_dev)!\n");
    if (device_create_file(firmware_cmd_dev, &dev_attr_version) < 0)

        pr_err("Failed to create device file(%s)!\n", dev_attr_version.attr.name);


static ssize_t firmware_version_show(struct device *dev,
                                     struct device_attribute *attr, char *buf)
{
    _msg_GetVersion();
    if(fw_version == NULL)
    {   
        fw_version = kzalloc(sizeof(*fw_version)*8, GFP_KERNEL);
    }
    sprintf(fw_version, "%04d%04d", curr_ic_major, curr_ic_minor);


    TPD_DEBUG_UPDATE("*** firmware_version_show fw_version = %s***\n", fw_version);
    return sprintf(buf, "%s\n", fw_version);
}


static ssize_t firmware_version_store(struct device *dev,
                                      struct device_attribute *attr, const char *buf, size_t size)

    _msg_GetVersion();
    if(fw_version == NULL)
    {   
        fw_version = kzalloc(sizeof(*fw_version)*8, GFP_KERNEL);
    }
    sprintf(fw_version, "%04d%04d", curr_ic_major, curr_ic_minor);
    TPD_DEBUG_UPDATE("*** fw_version = %s ***\n", fw_version);


#ifdef CONFIG_ENABLE_FIRMWARE_DATA_LOG
restore_firmware_mode_to_debug_mode();
#endif //CONFIG_ENABLE_FIRMWARE_DATA_LOG

    if(buf != NULL)
        TPD_DEBUG_UPDATE("buf = %c ***\n", buf[0]);


    return size;
}


static DEVICE_ATTR(version,0664, firmware_version_show, firmware_version_store);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值