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);