Exemplo n.º 1
0
static void *read_thread_handler(void *data)
{
	ssize_t rdlen;
	char buff[1024];
	struct cavan_cache *cache = data;

	while (1) {
		rdlen = cavan_cache_read_line(cache, buff, sizeof(buff), 0, 20000);
		if (rdlen <= 0) {
			if (rdlen < 0) {
				pr_red_info("cavan_cache_read");
				break;
			} else {
				rdlen = cavan_cache_read(cache, buff, sizeof(buff) - 1, 0, 0);
				if (rdlen <= 0) {
					break;
				}
			}
		}

		buff[rdlen] = 0;

#if __WORDSIZE == 64
		pr_green_info("buff[%ld] = %s", rdlen, buff);
#else
		pr_green_info("buff[%d] = %s", rdlen, buff);
#endif

		// msleep(500);
	}

	pr_red_info("Read thread exit!");
	return NULL;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int ret;
	int stream;
	float volume;

	assert(argc > 1);

	stream = getStreamByName(argv[1]);
	if (stream < 0) {
		pr_red_info("getStreamByName");
		return stream;
	}

	if (argc > 2) {
		volume = atoi(argv[2]);

		ret = setStreamVolume(stream, volume / 100);
		if (ret < 0) {
			pr_red_info("setStreamVolume");
		} else {
			pr_green_info("setStreamVolume");
		}
	} else {
		ret = getStreamVolume(stream, &volume);
		if (ret < 0) {
			pr_red_info("getStreamVolume");
		} else {
			pr_green_info("volume = %f", volume);
		}
	}

	return 0;
}
Exemplo n.º 3
0
bool cavan_touch_device_matcher(struct cavan_event_matcher *matcher, void *data)
{
	int ret;
	uint8_t abs_bitmask[ABS_BITMASK_SIZE];
	uint8_t key_bitmask[KEY_BITMASK_SIZE];

	ret = cavan_event_get_abs_bitmask(matcher->fd, abs_bitmask);
	if (ret < 0)
	{
		pr_error_info("cavan_event_get_abs_bitmask");
		return false;
	}

	if (cavan_multi_touch_device_match(abs_bitmask))
	{
		pr_green_info("Deivce %s mutil touch screen", matcher->devname);
		return true;
	}

	ret = cavan_event_get_key_bitmask(matcher->fd, key_bitmask);
	if (ret < 0)
	{
		pr_error_info("cavan_event_get_key_bitmask");
		return false;
	}

	return cavan_single_touch_device_match(abs_bitmask, key_bitmask);
}
Exemplo n.º 4
0
int cavan_inotify_register_watch(struct cavan_inotify_descriptor *desc, const char *pathname, uint32_t mask, void *data)
{
	int wd;
	struct cavan_inotify_watch *p;

	if (desc->watch_count >= NELEM(desc->watchs))
	{
		error_msg("Too match watch");
		return -EFAULT;
	}

	if (pathname == NULL || *pathname == 0)
	{
		error_msg("pathname == NULL || *pathname == 0");
		return -EINVAL;
	}

	wd = inotify_add_watch(desc->fd, pathname, mask);
	if (wd < 0)
	{
		print_error("inotify_add_watch");
		return wd;
	}

	for (p = desc->watchs; p->wd >= 0; p++);

	p->wd = wd;
	p->data = data;
	text_copy(p->pathname, pathname);
	desc->watch_count++;

	pr_green_info("Add watch: %s", pathname);

	return 0;
}
Exemplo n.º 5
0
static int swan_virtual_keypad_probe(struct platform_device *pdev)
{
	int ret;
	struct device_attribute *p;

	pr_pos_info();

	vk_input = input_allocate_device();
	if (vk_input == NULL)
	{
		pr_red_info("input_allocate_device");
		return -ENOMEM;
	}

	vk_input->name = SWAN_VK_DEVICE_NAME;
	swan_virtual_keypad_setup_events(vk_input);

	ret = input_register_device(vk_input);
	if (ret < 0)
	{
		pr_red_info("input_register_device");
		goto out_input_free_device;
	}

	ret = misc_register(&swan_vk_misc);
	if (ret < 0)
	{
		pr_red_info("misc_register failed");
		goto out_input_unregister_device;
	}

	for (p = vk_attrs + ARRAY_SIZE(vk_attrs) - 1; p >= vk_attrs; p--)
	{
		ret = device_create_file(&pdev->dev, p);
		if (ret < 0)
		{
			pr_red_info("device_create_file");

			while (--p >= vk_attrs)
			{
				device_remove_file(&pdev->dev, p);
			}

			goto out_misc_deregister;
		}
	}

	pr_green_info("Swan Virtual Keypad is OK");

	return 0;

out_misc_deregister:
	misc_deregister(&swan_vk_misc);
out_input_unregister_device:
	input_unregister_device(vk_input);
out_input_free_device:
	input_free_device(vk_input);

	return ret;
}
Exemplo n.º 6
0
bool huamobile_touch_device_matcher(int fd, const char *name, void *data)
{
	int ret;
	uint8_t abs_bitmask[ABS_BITMASK_SIZE];
	uint8_t key_bitmask[KEY_BITMASK_SIZE];

	pr_pos_info();

	ret = huamobile_event_get_abs_bitmask(fd, abs_bitmask);
	if (ret < 0)
	{
		pr_error_info("huamobile_event_get_abs_bitmask");
		return false;
	}

	if (huamobile_multi_touch_device_match(abs_bitmask))
	{
		pr_green_info("Deivce %s mutil touch screen", name);
		return true;
	}

	ret = huamobile_event_get_key_bitmask(fd, key_bitmask);
	if (ret < 0)
	{
		pr_error_info("huamobile_event_get_key_bitmask");
		return false;
	}

	return huamobile_single_touch_device_match(abs_bitmask, key_bitmask);
}
Exemplo n.º 7
0
int cavan_sensor_device_probe(struct cavan_input_device *dev)
{
	int ret;
	struct input_dev *input = dev->input;
	struct cavan_sensor_device *sensor = (struct cavan_sensor_device *) dev;

	switch (dev->type)
	{
	case CAVAN_INPUT_DEVICE_TYPE_ACCELEROMETER:
	case CAVAN_INPUT_DEVICE_TYPE_MAGNETIC_FIELD:
	case CAVAN_INPUT_DEVICE_TYPE_ORIENTATION:
	case CAVAN_INPUT_DEVICE_TYPE_GYROSCOPE:
	case CAVAN_INPUT_DEVICE_TYPE_GRAVITY:
	case CAVAN_INPUT_DEVICE_TYPE_ROTATION_VECTOR:
	case CAVAN_INPUT_DEVICE_TYPE_LINEAR_ACCELERATION:
		if (sensor->axis_count < 2)
		{
			sensor->axis_count = 3;
		}

		input_set_abs_params(input, ABS_X, 0, sensor->resolution, dev->fuzz, dev->flat);
		input_set_abs_params(input, ABS_Y, 0, sensor->resolution, dev->fuzz, dev->flat);
		input_set_abs_params(input, ABS_Z, 0, sensor->resolution, dev->fuzz, dev->flat);
		break;

	case CAVAN_INPUT_DEVICE_TYPE_LIGHT:
	case CAVAN_INPUT_DEVICE_TYPE_PRESSURE:
	case CAVAN_INPUT_DEVICE_TYPE_TEMPERATURE:
	case CAVAN_INPUT_DEVICE_TYPE_PROXIMITY:
		sensor->axis_count = 1;
		input_set_abs_params(input, ABS_MISC, 0, sensor->resolution, dev->fuzz, dev->flat);
		break;

	default:
		pr_red_info("Invalid sensor type %d", dev->type);
		return -EINVAL;
	}

	set_bit(EV_ABS, input->evbit);

	ret = sysfs_create_files(&dev->misc_dev.dev->kobj, cavan_sensor_device_attributes);
	if (ret < 0)
	{
		pr_red_info("sysfs_create_files");
		return ret;
	}

	dev->remove = cavan_sensor_device_remove;
	dev->ioctl = cavan_sensor_device_ioctl;

	pr_green_info("cavan sensor %s probe complete", dev->name);

	return 0;
}
Exemplo n.º 8
0
Arquivo: xml.c Projeto: FuangCao/cavan
struct cavan_xml_tag *cavan_xml_tag_alloc(const char *name, const char *content, int flags)
{
	struct cavan_xml_tag *tag;

#if CONFIG_CAVAN_XML_DEBUG
	pr_green_info("tag: name = %s", name);
#endif

	tag = malloc(sizeof(*tag));
	if (tag == NULL) {
		pr_error_info("malloc");
		return NULL;
	}

	tag->flags = 0;

	if (name && (flags & CAVAN_XML_FLAG_NAME_ALLOC)) {
		name = strdup(name);
		if (name == NULL) {
			goto out_free_tag;
		}

		tag->flags |= CAVAN_XML_FLAG_NAME_ALLOC;
	}

	if (content && (flags & CAVAN_XML_FLAG_CONTENT_ALLOC)) {
		content = strdup(content);
		if (content == NULL) {
			goto out_free_name;
		}

		tag->flags |= CAVAN_XML_FLAG_CONTENT_ALLOC;
	}

	tag->name = name;
	tag->content = content;
	tag->child = NULL;
	tag->next = NULL;
	tag->attr = NULL;

	return tag;

out_free_name:
	if ((flags & CAVAN_XML_FLAG_NAME_ALLOC)) {
		free((char *) name);
	}
out_free_tag:
	free(tag);
	return NULL;
}
Exemplo n.º 9
0
int swan_ts_test_client_fd(int fd, u16 addr)
{
	int ret;

	println("Test client %d = 0x%04x", addr, addr);

	ret = ioctl(fd, SWAN_TS_IOCTL_TEST_CLIENT, &addr);
	if (ret < 0) {
		pr_red_info("Failed");
	} else {
		pr_green_info("OK");
	}

	return ret;
}
Exemplo n.º 10
0
Arquivo: xml.c Projeto: FuangCao/cavan
struct cavan_xml_attribute *cavan_xml_attribute_alloc(const char *name, const char *value, int flags)
{
	struct cavan_xml_attribute *attr;

#if CONFIG_CAVAN_XML_DEBUG
	pr_green_info("attr: name = %s, value = %s", name, value);
#endif

	attr = malloc(sizeof(*attr));
	if (attr == NULL) {
		pr_error_info("malloc");
		return NULL;
	}

	attr->flags = 0;

	if (name && (flags & CAVAN_XML_FLAG_NAME_ALLOC)) {
		name = strdup(name);
		if (name == NULL) {
			goto out_free_attr;
		}

		attr->flags |= CAVAN_XML_FLAG_NAME_ALLOC;
	}

	if (value && (flags & CAVAN_XML_FLAG_VALUE_ALLOC)) {
		value = strdup(value);
		if (value == NULL) {
			goto out_free_name;
		}

		attr->flags |= CAVAN_XML_FLAG_VALUE_ALLOC;
	}

	attr->name = name;
	attr->value = value;
	attr->next = NULL;

	return attr;

out_free_name:
	if ((flags & CAVAN_XML_FLAG_NAME_ALLOC)) {
		free((char *) name);
	}
out_free_attr:
	free(attr);
	return NULL;
}
Exemplo n.º 11
0
static int cy8c242_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    int ret;
    struct cavan_input_chip *chip;

    pr_pos_info();

    chip = kzalloc(sizeof(*chip), GFP_KERNEL);
    if (chip == NULL) {
        pr_red_info("kzalloc");
        return -ENOMEM;
    }

    i2c_set_clientdata(client, chip);
    cavan_input_chip_set_bus_data(chip, client);

    chip->irq = client->irq;
    chip->irq_flags = IRQF_TRIGGER_FALLING;
    chip->name = "CY8C242";
    chip->devmask = 1 << CAVAN_INPUT_DEVICE_TYPE_TOUCHSCREEN | 1 << CAVAN_INPUT_DEVICE_TYPE_PROXIMITY;

    chip->set_power = cy8c242_set_power;
    chip->set_active = cy8c242_set_active;
    chip->readid = cy8c242_readid;
    chip->probe = cy8c242_input_chip_probe;
    chip->remove = cy8c242_input_chip_remove;

    chip->read_data = cavan_input_read_data_i2c;
    chip->write_data = cavan_input_write_data_i2c;
    chip->read_register = cavan_input_read_register_i2c_smbus;
    chip->write_register = cavan_input_write_register_i2c_smbus;
    chip->firmware_upgrade = cy8c242_firmware_upgrade;
    chip->read_firmware_id = cy8c242_read_firmware_id;

    ret = cavan_input_chip_register(chip, &client->dev);
    if (ret < 0) {
        pr_red_info("cavan_input_chip_register");
        goto out_kfree_chip;
    }

    pr_green_info("CY8C242 Probe Complete");

    return 0;

out_kfree_chip:
    kfree(chip);
    return ret;
}
Exemplo n.º 12
0
static int swan_ts_calication_main(int argc, char *argv[])
{
	int ret;

	ret = swan_ts_calibration(argc > 1 ? argv[1] : NULL);
	if (ret < 0)
	{
		pr_red_info("Failed");
	}
	else
	{
		pr_green_info("OK");
	}

	return ret;
}
Exemplo n.º 13
0
static int cy8c242_change_power_mode(struct cavan_input_chip *chip, u8 mode, int retry)
{
    pr_bold_info("CY8C242 change power mode => %s", cy8c242_power_mode_tostring(mode));

    while (chip->write_register(chip, CY8C242_REG_POWER_MODE, mode) < 0 && retry--) {
        msleep(10);
    }

    if (retry < 0) {
        pr_red_info("Failed");
    } else {
        pr_green_info("OK");
    }

    return retry;
}
Exemplo n.º 14
0
static int bl86x8_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int ret;
	struct hua_input_chip *chip;

	pr_pos_info();

	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
	if (chip == NULL)
	{
		pr_red_info("kzalloc");
		return -ENOMEM;
	}

	i2c_set_clientdata(client, chip);
	hua_input_chip_set_bus_data(chip, client);

	chip->irq = client->irq;
	chip->irq_flags = IRQF_TRIGGER_FALLING;
	chip->name = "BL86X8";
	chip->devmask = 1 << HUA_INPUT_DEVICE_TYPE_TOUCHSCREEN | 1 << HUA_INPUT_DEVICE_TYPE_PROXIMITY;

	chip->set_power = bl86x8_set_power;
	chip->readid = bl86x8_readid;
	chip->probe = bl86x8_input_chip_probe;
	chip->remove = bl86x8_input_chip_remove;

	chip->read_data = hua_input_read_data_i2c;
	chip->write_data = hua_input_write_data_i2c;
	chip->read_register = hua_input_read_register_i2c_smbus;
	chip->write_register = hua_input_write_register_i2c_smbus;

	ret = hua_input_chip_register(chip, &client->dev);
	if (ret < 0)
	{
		pr_red_info("hua_input_chip_register");
		goto out_kfree_chip;
	}

	pr_green_info("BL86X8 Probe Complete");

	return 0;

out_kfree_chip:
	kfree(chip);
	return ret;
}
Exemplo n.º 15
0
void show_eth_header(struct ethhdr *ethhdr)
{
	char buff[20];

	memset(buff, 0, sizeof(buff));

	pr_green_info("Ethhdr Header");
	pr_std_info("dest_mac = %s",
				mac_address_tostring((const char *)ethhdr->h_dest,
									 sizeof(ethhdr->h_dest),
									 (const char *)buff));
	pr_std_info("src_mac = %s",
				mac_address_tostring((const char *)ethhdr->h_source,
									 sizeof(ethhdr->h_source),
									 (const char *)buff));
	pr_std_info("protocol_type = %x", ntohs(ethhdr->h_proto));
	pr_std_info("");
}
Exemplo n.º 16
0
static ssize_t swan_virtual_keypad_command_store(struct device *dev, struct device_attribute *attr, const char *buff, size_t count)
{
	const struct swan_virtual_key *p, *end_p;
	static unsigned int old_code;

	pr_pos_info();

	for (p = swan_vk_table, end_p = swan_vk_table + ARRAY_SIZE(swan_vk_table); p < end_p && strlhcmp(p->name, buff); p++);

	if (p < end_p)
	{
		old_code = p->code;
	}

	pr_green_info("keycode = %d", old_code);
	swan_vk_touch(vk_input, old_code);

	return count;
}
Exemplo n.º 17
0
int odexCheck2(const char *pathname)
{
	int fd;
	int ret;

	fd = open(pathname, O_RDONLY);
	if (fd < 0) {
		pr_red_info("open file %s failed", pathname);
		return fd;
	}

	ret = odexCheck(fd);
	if (ret < 0) {
		pr_red_info("%s failed", pathname);
	} else {
		pr_green_info("%s passed", pathname);
	}

	close(fd);

	return ret;
}
Exemplo n.º 18
0
static int ft5406_firmware_upgrade_main(int argc, char *argv[])
{
	int ret;
	const char *cfgpath, *devpath;

	assert(argc > 1);

	cfgpath = argv[1];
	devpath = argc > 2 ? argv[2] : NULL;

	ret = ft5406_firmware_upgrade(devpath, cfgpath);
	if (ret < 0)
	{
		pr_red_info("Failed");
	}
	else
	{
		pr_green_info("OK");
	}

	return ret;
}
Exemplo n.º 19
0
static int tcp_keypad_probe(struct platform_device *pdev)
{
	int ret;

	pr_pos_info();

	vk_input = input_allocate_device();
	if (vk_input == NULL) {
		pr_red_info("input_allocate_device");
		return -ENOMEM;
	}

	vk_input->name = TCP_KEYPAD_INPUT_NAME;
	tcp_keypad_setup_events(vk_input);

	ret = input_register_device(vk_input);
	if (ret < 0) {
		pr_red_info("input_register_device");
		goto out_input_free_device;
	}

	ret = misc_register(&tcp_keypad_misc);
	if (ret < 0) {
		pr_red_info("misc_register failed");
		goto out_input_unregister_device;
	}

	pr_green_info("Swan Virtual Keypad is OK");

	return 0;

out_input_unregister_device:
	input_unregister_device(vk_input);
out_input_free_device:
	input_free_device(vk_input);

	return ret;
}
Exemplo n.º 20
0
static int swan_ts_write_registers_main(int argc, char *argv[])
{
	int i;
	int ret;
	char *buff;
	u16 offset;
	u16 count;

	assert(argc > 2);

	offset = text2value_unsigned(argv[1], NULL, 10);
	count = argc - 2;

	buff = malloc(count);

	for (i = 0; i < count; i++)
	{
		buff[i] = text2value_unsigned(argv[i + 2], NULL, 10);
	}

	println("offset = %d, count = %d", offset, count);
	println("The data is:");
	print_mem((u8 *) buff, count);

	ret = swan_ts_write_registers(NULL, offset, buff, count);
	if (ret < 0)
	{
		pr_red_info("Failed");
	}
	else
	{
		pr_green_info("OK");
	}

	free(buff);

	return ret;
}
Exemplo n.º 21
0
static int mksdcard(const char *sd_device)
{
	int ret;

	umount_device(sd_device, MNT_DETACH);

	ret = system_command("sfdisk %s -uM << EOF\n64,,L\nEOF", sd_device);
	if (ret < 0) {
		pr_err_info("system_command");
		return ret;
	}

	sleep(1);

	ret = system_command("mkfs.vfat %s1 -n sdcard", sd_device);
	if (ret < 0) {
		pr_err_info("system_command");
		return ret;
	}

	pr_green_info("mksdcard Success");

	return 0;
}
Exemplo n.º 22
0
static struct cavan_input_device *cavan_input_device_create(uint8_t *key_bitmask, uint8_t *abs_bitmask, uint8_t *rel_bitmask)
{
#if CAVAN_INPUT_SUPPORT_GSENSOR
	if (cavan_gsensor_device_match(abs_bitmask)) {
		pr_green_info("G-Sensor Matched");
		return cavan_gsensor_create();
	}
#endif

	if (cavan_touchpad_device_match(key_bitmask, abs_bitmask)) {
		pr_green_info("Touch Pad Matched");
		return cavan_touchpad_device_create();
	}

	if (cavan_multi_touch_device_match(abs_bitmask)) {
		pr_green_info("Muti Touch Panel Matched");
		return cavan_multi_touch_device_create();
	}

	if (cavan_single_touch_device_match(abs_bitmask, key_bitmask)) {
		pr_green_info("Single Touch Panel Matched");
		return cavan_single_touch_device_create();
	}

	if (cavan_mouse_device_match(key_bitmask, rel_bitmask)) {
		pr_green_info("Mouse Matched");
		return cavan_mouse_create();
	}

	if (cavan_keypad_device_match(key_bitmask)) {
		pr_green_info("Keypad Matched");
		return cavan_keypad_create();
	}

	return NULL;
}
Exemplo n.º 23
0
int bootimg_pack(struct bootimg_pack_option *option)
{
	int fd;
	int ret;
	int image_count;
	struct bootimg_header hdr;
	struct bootimg_image images[4];
	struct bootimg_image *p, *p_end;
	struct cavan_sha_context context;

	if (option->kernel == NULL || option->ramdisk == NULL)
	{
        pr_red_info("no kernel or ramdisk image specified");
		return -EINVAL;
	}

	fd = open(option->output, O_WRONLY | O_CREAT | O_TRUNC, 0777);
	if (fd < 0)
	{
		pr_error_info("open file `%s' failed", option->output);
		return fd;
	}

	ret = lseek(fd, sizeof(hdr), SEEK_SET);
	if (ret < 0)
	{
		pr_red_info("cavan_file_seek_page_align");
		goto out_close_fd;
	}

	cavan_sha1_context_init(&context);

	ret = cavan_sha_init(&context);
	if (ret < 0)
	{
		pr_red_info("cavan_sha_init");
		goto out_close_fd;
	}

	memset(&hdr, 0, sizeof(hdr));
	memcpy(hdr.magic, BOOT_MAGIC, sizeof(hdr.magic));

	if (option->config)
	{
		ret = bootimg_parse_config_file(&hdr, option->config);
		if (ret < 0)
		{
			pr_red_info("bootimg_parse_config_file");
			goto out_close_fd;
		}
	}
	else
	{
		memcpy(hdr.unused, option->unused, sizeof(hdr.unused));

		hdr.page_size = option->page_size;
		hdr.kernel_addr = option->kernel_addr ?: option->base + option->kernel_offset;
		hdr.ramdisk_addr = option->ramdisk_addr ?: option->base + option->ramdisk_offset;
		hdr.second_addr = option->second_addr ?: option->base + option->second_offset;
		hdr.tags_addr = option->tags_addr ?: option->base + option->tags_offset;

		if (option->name)
		{
			strncpy((char *) hdr.name, option->name, sizeof(hdr.name));
		}

		if (option->cmdline)
		{
			bootimg_copy_cmdline(&hdr, option->cmdline);
		}
	}

	images[0].name = option->kernel;
	images[0].size_addr = &hdr.kernel_size;

	images[1].name = option->ramdisk;
	images[1].size_addr = &hdr.ramdisk_size;

	images[2].name = option->second;
	images[2].size_addr = &hdr.second_size;

	image_count = 3;

	if (option->dt)
	{
		images[image_count].name = option->dt;
		images[image_count++].size_addr = &hdr.dt_size;
	}

	for (p = images, p_end = p + image_count; p < p_end; p++)
	{
		if (p->name)
		{
			println("write image %s", p->name);

			ret = bootimg_write_image(fd, p->name, p->size_addr, hdr.page_size, &context);
			if (ret < 0)
			{
				pr_red_info("bootimg_write_image");
				goto out_close_fd;
			}
		}
		else
		{
			*p->size_addr = 0;
		}

		cavan_sha_update(&context, p->size_addr, sizeof(unsigned));
	}

	if (option->remain)
	{
		println("write remain image %s", option->remain);

		ret = file_copy3(option->remain, fd);
		if (ret < 0)
		{
			pr_red_info("file_copy3");
			goto out_close_fd;
		}
	}

	if (option->check_all)
	{
		cavan_sha_update(&context, &hdr.tags_addr, sizeof(hdr.tags_addr));
		cavan_sha_update(&context, &hdr.page_size, sizeof(hdr.page_size));
		cavan_sha_update(&context, hdr.unused, sizeof(hdr.unused));
		cavan_sha_update(&context, hdr.name, sizeof(hdr.name));
		cavan_sha_update(&context, hdr.cmdline, sizeof(hdr.cmdline));

		if (hdr.extra_cmdline[0])
		{
			cavan_sha_update(&context, hdr.extra_cmdline, sizeof(hdr.extra_cmdline));
		}
	}

	cavan_sha_finish(&context, (u8 *) hdr.id);

	bootimg_header_dump(&hdr);

	ret = ffile_writeto(fd, &hdr, sizeof(hdr), 0);
	if (ret < 0)
	{
		pr_red_info("ffile_writeto");
		goto out_close_fd;
	}

	pr_green_info("pack %s successfull", option->output);

out_close_fd:
	close(fd);
	return ret;
}
Exemplo n.º 24
0
static int write2emmc(int pkg_fd, int img_count, int retry_count, enum swan_image_type *skip_types, size_t skip_img_count)
{
	int ret;
	int img_fd;
	u32 tmp_crc32;
	struct swan_image_info img_info;

	while (img_count) {
		int retry;

		ret = read_image_info(pkg_fd, &img_info);
		if (ret < 0) {
			pr_err_info("read_image_info");
			return ret;
		}

		if (array_has_element(img_info.type, (int *) skip_types, skip_img_count)) {
			ret = lseek(pkg_fd, img_info.length, SEEK_CUR);
			if (ret < 0) {
				pr_err_info("lseek");
				return ret;
			}

			pr_warn_info("skipping image \"%s\" ...", swan_image_type_tostring(img_info.type));
			continue;
		}

		img_fd = open_dest_device(&img_info);
		if (img_fd < 0) {
			pr_err_info("open_dest_device");
			return ret;
		}

		retry = retry_count;

		while (retry--) {
			off_t pkg_pointer_bak;

			ret = get_file_pointer(pkg_fd, &pkg_pointer_bak);
			if (ret < 0) {
				pr_err_info("can't backup file pointer");
				goto out_close_img;
			}

			ret = read_simple_image(pkg_fd, img_fd, img_info.length, img_info.offset);
			if (ret < 0) {
				pr_err_info("get_image");
				goto out_close_img;
			}

			ret = lseek(img_fd, img_info.offset, SEEK_SET);
			if (ret < 0) {
				pr_err_info("lseek");
				goto out_close_img;
			}

			fsync(img_fd);

			println("check image crc32 checksum");

			tmp_crc32 = 0;

			ret = ffile_ncrc32(img_fd, img_info.length, &tmp_crc32);
			if (ret < 0) {
				pr_err_info("ffile_ncrc32");
				goto out_close_img;
			}

			println("img_crc32 = 0x%08x, tmp_crc32 = 0x%08x", img_info.crc32, tmp_crc32);

			if (img_info.crc32 ^ tmp_crc32) {
				pr_err_info("image crc32 checksum is not match, retry = %d", retry);
			} else {
				pr_green_info("image crc32 checksum is match");
				break;
			}

			ret = lseek(pkg_fd, pkg_pointer_bak, SEEK_SET);
			if (ret < 0) {
				pr_err_info("recovery package file pointer");
				goto out_close_img;
			}
		}

		if (retry < 0) {
			ret = -EIO;
			goto out_close_img;
		}

		close(img_fd);
		img_count--;
	}

	return 0;

out_close_img:
	close(img_fd);

	return ret;
}
Exemplo n.º 25
0
Arquivo: xml.c Projeto: FuangCao/cavan
static int cavan_xml_document_get_next_token(struct cavan_xml_parser *parser, bool verbose)
{
	char c;
	int ret;
	int lineno;
	char *p, *p_end;
	char *head, *tail, *value;
	struct cavan_xml_attribute *attr;

	parser->prev_token = parser->token;

	if (parser->next_token != CAVAN_XML_TOKEN_NONE) {
		parser->token = parser->next_token;
		parser->next_token = CAVAN_XML_TOKEN_NONE;
		return 0;
	}

	lineno = parser->lineno;;
	parser->name = NULL;
	parser->attr = NULL;
	parser->content = NULL;
	parser->comment = NULL;
	parser->token = CAVAN_XML_TOKEN_NONE;

	p = parser->pos;
	p_end = parser->pos_end;
	head = tail = p;

	while (p < p_end) {
		switch (*p) {
		case 0:
		case '\\':
			break;

		case '\n':
			lineno++;
#if CONFIG_CAVAN_XML_DEBUG
			pr_green_info("lineno = %d", lineno);
#endif
		case ' ':
		case '\t':
		case '\f':
		case '\r':
			p++;

			if (parser->token == CAVAN_XML_TOKEN_NONE) {
				head = p;
			} else {
				if (byte_is_space_or_lf(*head)) {
					head = p;
				}

				*tail = 0;
			}

			tail = p;
			break;

		case '<':
			if (parser->token != CAVAN_XML_TOKEN_NONE) {
				if (verbose) {
					pr_parser_error_info(lineno, "token = %d", parser->token);
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			switch (p[1]) {
			case '/':
				p++;
				parser->token = CAVAN_XML_TOKEN_TAG_END;
				break;

			case '?':
				p++;
				parser->token = CAVAN_XML_TOKEN_TAG_ATTR;
				break;

			case '!':
				if (text_lhcmp("--", p + 2) == 0) {
					p += 4;
					parser->comment = p;
					ret = cavan_xml_document_parse_comment(&p, p_end);
					if (ret < 0) {
						if (verbose) {
							pr_parser_error_info(lineno, "cavan_xml_document_parse_comment");
						}

						ret = -EFAULT;
						goto out_cavan_xml_token_error;
					}

					parser->token = CAVAN_XML_TOKEN_COMMENT;
					parser->pos = p + 1;
					parser->lineno = lineno + ret;
					return 0;
				}
			default:
				parser->token = CAVAN_XML_TOKEN_TAG_BEGIN;
			}

			if (byte_is_named(*++p) == false) {
				if (verbose) {
					pr_parser_error_info(lineno, "tag name is empty");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			parser->name = p;

			p = text_skip_name(p, p_end);
			if (parser->name == p) {
				if (verbose) {
					pr_parser_error_info(lineno, "tag name is empty");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			head = tail = p;
			break;

		case '?':
			if (parser->token == CAVAN_XML_TOKEN_NONE) {
				if (verbose) {
					pr_parser_error_info(lineno, "invalid '?'");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			parser->token = CAVAN_XML_TOKEN_TAG_ATTR;
			goto label_tag_single;

		case '/':
			if (parser->token == CAVAN_XML_TOKEN_NONE) {
				if (verbose) {
					pr_parser_error_info(lineno, "invalid '/'");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			parser->token = CAVAN_XML_TOKEN_TAG_SINGLE;

label_tag_single:
			if (*++p != '>') {
				if (verbose) {
					pr_parser_error_info(lineno, "need '>' by has '%c'", *p);
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			goto label_tag_end;

		case '>':
			if (parser->token == CAVAN_XML_TOKEN_NONE) {
				if (verbose) {
					pr_parser_error_info(lineno, "invalid '>'");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

label_tag_end:
			*tail = 0;
			if (cavan_xml_tag_is_content(parser->name)) {
				*tail = '>';
				parser->token = CAVAN_XML_TOKEN_COTENT;
			} else {
				parser->pos = ++p;
				parser->lineno = lineno;
			}
			return 0;

		case '=':
			p = text_skip_space_and_lf(p + 1, p_end);
			c = *p;
			if (c != '"' && c != '\'') {
				if (verbose) {
					pr_parser_error_info(lineno, "need a '\"' or '");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			value = ++p;

			ret = cavan_xml_attribute_parse_value(c, &p, p_end);
			if (ret < 0) {
				if (verbose) {
					pr_parser_error_info(lineno, "cavan_xml_attribute_parse_value");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			lineno += ret;
			*tail = 0;

			if (cavan_xml_attribute_set(&parser->attr, head, value, 0) == false) {
				if (verbose) {
					pr_parser_error_info(lineno, "cavan_xml_attribute_alloc");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			head = tail = ++p;
			break;

		default:
			if (parser->token == CAVAN_XML_TOKEN_NONE) {
				if (verbose) {
					pr_parser_error_info(lineno, "invalid content");
				}

				ret = -EFAULT;
				goto out_cavan_xml_token_error;
			}

			tail++, p++;
		}
	}

	ret = 0;
	parser->token = CAVAN_XML_TOKEN_EOF;

out_cavan_xml_token_error:
	attr = parser->attr;
	while (attr) {
		struct cavan_xml_attribute *next = attr->next;
		cavan_xml_attribute_free(attr);
		attr = next;
	}

	return ret;
}
Exemplo n.º 26
0
Arquivo: xml.c Projeto: FuangCao/cavan
static struct cavan_xml_document *cavan_xml_document_parse_base(char *content, size_t size)
{
	int ret;
	struct cavan_xml_parser parser;
	struct general_stack stack;
	struct cavan_xml_document *doc;
	struct cavan_xml_tag *tag, *parent, **pparent;

	ret = general_stack_init_fd(&stack, 10);
	if (ret < 0) {
		pr_red_info("general_stack_init_fd");
		return NULL;
	}

	doc = cavan_xml_document_alloc();
	if (doc == NULL) {
		pr_red_info("cavan_xml_document_alloc");
		goto out_general_stack_free;
	}

	parser.lineno = 1;
	parser.pos = content;
	parser.pos_end = content + size;
	parser.prev_token = parser.next_token = parser.token = CAVAN_XML_TOKEN_NONE;

	while (1) {
		ret = cavan_xml_document_get_next_token(&parser, true);
		if (ret < 0) {
			goto out_cavan_xml_document_free;
		}
#if CONFIG_CAVAN_XML_DEBUG
		pr_green_info("token = %d", parser.token);
#endif
		switch (parser.token) {
		case CAVAN_XML_TOKEN_COMMENT:
		case CAVAN_XML_TOKEN_NONE:
			break;

		case CAVAN_XML_TOKEN_EOF:
			goto out_parse_complete;

		case CAVAN_XML_TOKEN_TAG_ATTR:
			tag = cavan_xml_tag_create(&doc->attr, parser.name, CAVAN_XML_FLAG_UNIQUE);
			if (tag == NULL) {
				pr_red_info("cavan_xml_tag_create");
				goto out_cavan_xml_document_free;
			}

			cavan_xml_attribute_extend(&tag->attr, parser.attr);
			break;

		case CAVAN_XML_TOKEN_TAG_BEGIN:
		case CAVAN_XML_TOKEN_TAG_SINGLE:
			parent = general_stack_get_top_fd(&stack);
			if (parent) {
				if (parent->content) {
					pr_parser_error_info(parser.lineno, "tag %s has content %s", parent->name, parent->content);
					goto out_cavan_xml_document_free;
				}

				pparent = &parent->child;
			} else {
				pparent = &doc->tag;
			}

			tag = cavan_xml_tag_create(pparent, parser.name, 0);
			if (tag == NULL) {
				pr_red_info("cavan_xml_tag_alloc");
				goto out_cavan_xml_document_free;
			}

			cavan_xml_attribute_extend(&tag->attr, parser.attr);

			if (parser.token == CAVAN_XML_TOKEN_TAG_BEGIN) {
				ret = cavan_xml_document_get_next_token(&parser, false);
				if (ret < 0 || parser.token == CAVAN_XML_TOKEN_COTENT) {
					int lineno;
					size_t length;
					char *pos, *p;
					char buff[512];

					pos = parser.pos;
					length = snprintf(buff, sizeof(buff), "</%s>", tag->name);

					p = mem_kmp_find(pos, buff, parser.pos_end - pos, length);
					if (p == NULL) {
						pr_parser_error_info(parser.lineno, "tag %s is not pair", tag->name);
						goto out_cavan_xml_document_free;
					}

					*p = 0;

					for (lineno = 0; pos < p; pos++) {
						if (*pos == '\n') {
							lineno++;
						}
					}

					if (lineno) {
						tag->flags |= CAVAN_XML_FLAG_CONTENT_MULTI_LINE;
						parser.lineno += lineno;
					}

					cavan_xml_tag_set_content(tag, parser.pos, 0);
					parser.pos = p + length;
				} else {
					general_stack_push_fd(&stack, tag);
					parser.next_token = parser.token;
				}
			}
			break;

		case CAVAN_XML_TOKEN_TAG_END:
			tag = general_stack_pop_fd(&stack);
			if (tag == NULL || strcmp(parser.name, tag->name)) {
				pr_parser_error_info(parser.lineno, "tag (%s <> %s) is not pair", tag ? tag->name : "null", parser.name);
				goto out_cavan_xml_document_free;
			}
			break;

		default:
			pr_red_info("unknown token %d", parser.token);
			goto out_cavan_xml_document_free;
		}
	}

out_parse_complete:
	if (general_stack_get_top_fd(&stack)) {
		pr_red_info("tag stack not empty");
		goto out_cavan_xml_document_free;
	}

	doc->content = content;
	general_stack_free(&stack);

	return doc;

out_cavan_xml_document_free:
	cavan_xml_document_free(doc);
out_general_stack_free:
	general_stack_free(&stack);
	return NULL;
}
Exemplo n.º 27
0
static int cy8c242_firmware_write_data(struct cavan_input_chip *chip, struct cavan_firmware *fw)
{
    int ret;
    u32 delay;
    u8 datas[32];
    ssize_t rdlen;
    char buff[512], *line, *line_end;

    pr_pos_info();

    while (1) {
        rdlen = cavan_firmware_read_line(fw, buff, sizeof(buff), 0, 5000);
        if (rdlen < 0) {
            pr_red_info("cavan_firmware_read_line");
            return rdlen;
        }

        if (rdlen == 0) {
            pr_green_info("Firmware upgrade successfully");
            break;
        }

        for (line = buff, line_end = line + rdlen; line < line_end && BYTE_IS_SPACE(*line); line++);

        if (line_end - line == 0) {
            continue;
        }

        switch (line[0]) {
        case 'w':
        case 'W':
            ret = cy8c242_firmware2data(line + 2, line_end, datas);
            ret = chip->master_send(chip, datas + 1, ret - 1);
            if (ret < 0) {
                pr_red_info("master_send");
                return ret;
            }
            break;

        case 'r':
        case 'R':
            ret = chip->master_recv(chip, datas, 3);
            if (ret < 0) {
                pr_red_info("master_recv");
                return ret;
            }

            if (datas[2] != 0x20) {
                pr_red_info("datas[2] = 0x%02x", datas[2]);
                return -EFAULT;
            }
            break;

        case '[':
            ret = sscanf(line, "[delay=%d]", &delay);
            if (ret == 1) {
                msleep(delay);
            } else {
                pr_bold_info("unknown delay");
            }
            break;

        case '#':
            pr_green_info("Comment Line");
            break;

        default:
            pr_red_info("unknown char 0x%02x at line %s", line[0], line);
        }
    }

    return 0;
}
Exemplo n.º 28
0
static int ftp_client_receive_file(struct network_client *client, const char *ip, u16 port)
{
	int ret;
	int sockfd, data_sockfd;
	ssize_t rdlen;
	char buff[1024], *p;
	struct sockaddr_in addr;
	socklen_t addrlen;

	sockfd = inet_create_tcp_service(port);
	if (sockfd < 0)
	{
		pr_red_info("inet_create_tcp_service");
		return sockfd;
	}

	p = text_copy(buff, "PORT ");
	p = text_replace_char2(ip, p, '.', ',');
	p += sprintf(p, ",%d,%d\r\n", port >> 8, port & 0xFF);

	rdlen = ftp_client_send_command(client, buff, p - buff, buff, sizeof(buff));
	if (rdlen < 0)
	{
		pr_red_info("ftp_client_send_command");
		return rdlen;
	}

	rdlen = ftp_client_send_command(client, "LIST\r\n", 0, buff, sizeof(buff));
	if (rdlen < 0)
	{
		pr_red_info("ftp_client_send_command");
		return rdlen;
	}

	data_sockfd = inet_accept(sockfd, &addr, &addrlen);
	if (data_sockfd < 0)
	{
		pr_red_info("inet_accept");
		ret = data_sockfd;
		goto out_close_sockfd;
	}

	while (1)
	{
		rdlen = inet_recv(data_sockfd, buff, sizeof(buff));
		if (rdlen < 0)
		{
			pr_red_info("inet_recv");
			ret = rdlen;
			goto out_close_data_link;
		}

		if (rdlen == 0)
		{
			pr_green_info("data receive complete");
			break;
		}

#if FTP_DEBUG
		print_ntext(buff, rdlen);
#endif
	}

	ret = 0;

out_close_data_link:
	shutdown(data_sockfd, SHUT_RDWR);
	inet_close_tcp_socket(data_sockfd);
out_close_sockfd:
	inet_close_tcp_socket(sockfd);

	return ret;
}
Exemplo n.º 29
0
static int __devinit HC548_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    struct HC548_touchscreen_data *data;
    struct input_dev *input_dev;
    u8 buf,buf1;
    int error;
#ifdef ENABLE_UPGRADE
    int times = 0;
#endif

    pr_pos_info();

    data = kzalloc(sizeof(struct HC548_touchscreen_data), GFP_KERNEL);
    if(data == NULL)
    {
        pr_red_info("HC548 kzalloc touchscreen_data failed!\n");
        error = -ENOMEM;
        goto exit_alloc_data_failed;
    }

    input_dev = input_allocate_device();
    if(input_dev == NULL)
    {
        pr_red_info("HC548 input allocate device failed!\n");
        error = -ENOMEM;
        goto exit_input_dev_alloc_failed;
    }

    data->input_dev = input_dev;
    input_set_drvdata(input_dev, data);

    input_dev->name = HC5XX_NAME;
    input_dev->id.bustype = BUS_I2C;
    input_dev->dev.parent = &client->dev;
    input_dev->open = HC548_input_open;
    input_dev->close = HC548_input_close;

    input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
//	input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
    input_dev->propbit[0] = BIT(INPUT_PROP_DIRECT);

    input_dev->absbit[0] =  BIT_MASK(ABS_MT_TRACKING_ID) |
                            BIT_MASK(ABS_MT_POSITION_X) | BIT_MASK(ABS_MT_POSITION_Y)|
                            BIT_MASK(ABS_MT_TOUCH_MAJOR);// | BIT_MASK(ABS_MT_WIDTH_MAJOR);

    input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, HC548_MAX_X, 0 , 0);
    input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, HC548_MAX_Y, 0 , 0);
    input_set_abs_params(input_dev,ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
//	input_set_abs_params(input_dev,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
    input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 5, 0, 0);

#ifdef KEY_MAP_INIT
    HC548_key_map_init(input_dev);
#endif

    error = input_register_device(input_dev);
    if(error < 0)
    {
        pr_red_info("HC548 input_register_device failed!\n");
        goto err_unregister_device;
    }

    data->ts_wq = create_singlethread_workqueue("kworkqueue_ts");
    if (!data->ts_wq) {
        dev_err(&client->dev, "Could not create workqueue\n");
        goto error_wq_create;
    }
    flush_workqueue(data->ts_wq);

    INIT_WORK(&data->work, HC548_poscheck);
    data->client = client;
    i2c_set_clientdata(client,data);
    this_client = client;

    /*  configure rest pin */
#if 0
    data->reset = RK30_PIN0_PB6;//RK2928_PIN1_PB1; //INVALID_GPIO;//S5PV210_GPH2(5);
    if (data->reset != INVALID_GPIO) {
        error = gpio_request(data->reset, NULL);
        if (error < 0) {
            pr_red_info("Unable to request GPIO pin %d to act as reset\n",data->reset);
            goto exit_rst_gpio_request_failed;
        }
    }
    HC548_hard_reset(data);
#endif

    hc_register_read(0x00, &buf, 1);
    if(buf == 0x86)
        pr_green_info("HC548: I2C communication is OK, TP chip ID is %x\n",buf);
    else
        pr_red_info("HC548: I2C ERROR!! TP chip ID is %x\n",buf);

#ifdef ENABLE_UPGRADE
    pr_green_info("HC548: HC548_fw_data[0] is %x\n",HC548_fw_data[0]);
    if(HC548_fw_data[0] == 0xff)   //debug_control,if data is 0xff,TP drive always upgrade
    {
        while(1)
        {
            int ret = 0;
            ret = HC548_upgrade(client);
            if(ret < 0) {
                times ++;
                printk("times = %d\n",times);
            } else {
                times = 0;
                break;
            }
            if(times >= 10)
                break;
        }
    } else {
        __u8 buf;
        //i2c_smbus_read_i2c_block_data(client,0x75,1,&buf);
        hc_register_read(0x75, &buf, 1);
        hc_register_read(0x73, &buf1, 1);
        if((buf < HC548_fw_data[0]) || ((buf == HC548_fw_data[0]) && (buf1 < HC548_fw_data[1])))
//	if(buf < HC548_fw_data[0])
        {
            while(1)
            {
                int ret = 0;
                ret = HC548_upgrade(client);
                if(ret < 0) {
                    times ++;
                    printk("times = %d\n",times);
                } else {
                    times = 0;
                    break;
                }
                if(times >= 10)
                    break;
            }
        }
    }
    printk("====CTP download times = %d\n",times);
#endif

    /* configure interrupt pin */
#if 0
    data->irq = RK30_PIN1_PB7;//RK2928_PIN1_PB3;//RK2928_PIN1_PB0;
//S5PV210_GPH2(4);
    error = gpio_request(data->irq, "touch_irq_key");
    if (error < 0) {
        pr_red_info("Unable to request GPIO pin %d. error %d.\n", data->irq, error);
        goto exit_irq_gpio_request_failed;
    }
    error = gpio_direction_input(data->irq);
    if (error < 0) {
        pr_red_info("Failed to configure input direction for GPIO %d, error %d\n", data->irq, error);
        goto err_free_irq_gpio;
    }
#endif
    client->irq = IRQ_PORT;//gpio_to_irq(data->irq);
    if (client->irq < 0) {
        error = client->irq;
        pr_red_info( "Unable to get irq number for GPIO %d, error %d\n", data->irq, error);
        goto err_free_irq;
    }

//	error = request_threaded_irq(client->irq, NULL, HC548_interrupt, IRQF_TRIGGER_RISING, client->dev.driver->name, data);
    error = request_threaded_irq(client->irq, NULL, HC548_interrupt, IRQF_TRIGGER_FALLING, client->dev.driver->name, data);
    if(error)
    {
        pr_red_info("HC548 failed to register irq!\n");
        goto exit_irq_request_failed;
    }
#ifdef CONFIG_HC8600_SLEEP_KEEP_POWER
    INIT_WORK(&data->resume_work, ts_work_resume);
#endif
    pr_green_info("HC548_probe ok!\n");

    return 0;

exit_irq_request_failed:
    cancel_work_sync(&data->work);
err_free_irq:
    free_irq(client->irq, data);
//err_free_irq_gpio:
//    if (data->irq)
//       gpio_free(data->irq);
//exit_irq_gpio_request_failed:
//    HC548_hard_reset(data);
//    if (data->reset)
//       gpio_free(data->reset);
exit_rst_gpio_request_failed:
    destroy_workqueue(data->ts_wq);
    i2c_set_clientdata(client,NULL);
    this_client = NULL;
error_wq_create:
    input_unregister_device(input_dev);
err_unregister_device:
    input_free_device(input_dev);
exit_input_dev_alloc_failed:
    kfree(data);
exit_alloc_data_failed:
    return error;
}
Exemplo n.º 30
0
int hua_ts_device_probe(struct hua_input_device *dev)
{
	int ret;
	struct hua_ts_device *ts = (struct hua_ts_device *) dev;
	struct hua_input_chip *chip = dev->chip;
	struct hua_input_core *core = chip->core;
	struct input_dev *input = dev->input;
	const struct hua_ts_touch_key *key, *key_end;
	const char *name;

	ret = hua_input_add_kobject(&core->prop_kobj, "board_properties");
	if (ret < 0 && ret != -EEXIST)
	{
		pr_red_info("hua_input_add_kobject");
		return ret;
	}

	name = kasprintf(GFP_KERNEL, "virtualkeys.%s", input->name);
	if (name == NULL)
	{
		ret = -ENOMEM;
		pr_red_info("kasprintf");
		goto out_hua_input_remove_kobject;
	}

	hua_ts_board_properties_attr.attr.name = name;

	ret = hua_input_create_sysfs_files(dev, &core->prop_kobj, &hua_ts_board_properties_attr, 1);
	if (ret < 0)
	{
		pr_red_info("hua_input_add_kobject");
		goto out_kfree_name;
	}

	ret = sysfs_create_files(&dev->misc_dev.dev->kobj, hua_ts_device_attributes);
	if (ret < 0)
	{
		pr_red_info("sysfs_create_files");
		goto out_hua_input_remove_sysfs_files;
	}

#ifdef CONFIG_HAS_EARLYSUSPEND
	ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	ts->early_suspend.suspend = hua_ts_suspend;
	ts->early_suspend.resume = hua_ts_resume;
	register_early_suspend(&ts->early_suspend);
#elif defined(CONFIG_FB) && defined(CONFIG_HUAMOBILE_USE_FB_NOTIFILER)
	ts->fb_notifier.notifier_call = hua_ts_fb_notifier_call;
	ret = fb_register_client(&ts->fb_notifier);
	if (ret < 0)
	{
		pr_red_info("fb_register_client");
	}
#else
	ts->pm_notifier.notifier_call = hua_ts_pm_notifier_call;
	ret = register_pm_notifier(&ts->pm_notifier);
	if (ret < 0)
	{
		pr_red_info("register_pm_notifier");
	}
#endif

	set_bit(INPUT_PROP_DIRECT, input->propbit);

	set_bit(EV_KEY, input->evbit);
	set_bit(BTN_TOUCH, input->keybit);

	if (ts->keys && ts->key_count)
	{
		for (key = ts->keys, key_end = key + ts->key_count; key < key_end; key++)
		{
			set_bit(key->code, input->keybit);
		}
	}

	set_bit(EV_ABS, input->evbit);
	input_set_abs_params(input, ABS_MT_POSITION_X, ts->xmin, ts->xmax, dev->fuzz, dev->flat);
	input_set_abs_params(input, ABS_MT_POSITION_Y, ts->ymin, ts->ymax, 0, 0);
	input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, ts->point_count - 1, 0, 0);

	input->open = hua_ts_device_open;
	dev->remove = hua_ts_device_remove;

	ts->touch_count = 0;

	pr_green_info("huamobile touch screen %s probe complete", dev->name);

	return 0;

out_hua_input_remove_sysfs_files:
	hua_input_remove_sysfs_files(&core->prop_kobj, &hua_ts_board_properties_attr, 1);
out_kfree_name:
	kfree(name);
out_hua_input_remove_kobject:
	hua_input_remove_kobject(&core->prop_kobj);
	return ret;
}