static int lp855x_parse_dt(struct device *dev,
		struct lp855x *lp,
		const struct i2c_device_id **id)
{
	int i, rc;
	const char *str;
	struct device_node *node, *temp;
	u32 tmp_data;
	lp->pdata->bl_enable_valid = true;

	rc = of_property_read_string(dev->of_node,
		"linux,name", &lp->pdata->name);
	if (rc) {
		dev_err(dev, "Failure reading name, rc = %d\n", rc);
		lp->pdata->name = "lcd-backlight";
	}
	rc = of_property_read_string(dev->of_node, "linux,default-trigger",
		&str);
	if (!rc) {
		lp->pdata->default_trigger = str;
	} else {
		dev_err(dev, "Failure reading default-trigger, rc = %d\n", rc);
		lp->pdata->default_trigger = "none";
	}
	rc = of_property_read_string(dev->of_node, "mode", &str);
	if (!rc) {
		lp->mode = (strncmp(str, "pwm based", strlen(str)) == 0) ?
			PWM_BASED : REGISTER_BASED;
	} else {
		dev_err(dev, "Failure reading mode, rc = %d\n", rc);
		lp->mode = REGISTER_BASED;
	}
	rc = of_property_read_string(dev->of_node, "chip_name", &str);
	if (!rc) {
		*id = lp855x_get_i2c_device_id(str);
	} else {
		dev_err(dev, "Failure reading chip_name, rc = %d\n", rc);
		*id = lp855x_get_i2c_device_id("lp8556");
	}
	switch ((*id)->driver_data) {
	default:
	case LP8550:
		lp->pdata->device_control = (lp->mode == PWM_BASED) ?
			PWM_CONFIG(LP8550) : I2C_CONFIG(LP8550);
		break;
	case LP8551:
		lp->pdata->device_control = (lp->mode == PWM_BASED) ?
			PWM_CONFIG(LP8551) : I2C_CONFIG(LP8551);
		break;
	case LP8552:
		lp->pdata->device_control = (lp->mode == PWM_BASED) ?
			PWM_CONFIG(LP8552) : I2C_CONFIG(LP8552);
		break;
	case LP8553:
		lp->pdata->device_control = (lp->mode == PWM_BASED) ?
			PWM_CONFIG(LP8553) : I2C_CONFIG(LP8553);
		break;
	case LP8556:
		rc = of_property_read_string(dev->of_node, "config", &str);
		if (!rc) {
			if (strncmp(str, "combined1", strlen(str)) == 0)
				lp->pdata->device_control = LP8556_COMB1_CONFIG;
			else if (strncmp(str, "combined2", strlen(str)) == 0)
				lp->pdata->device_control = LP8556_COMB2_CONFIG;
			else
				lp->pdata->device_control = I2C_CONFIG(LP8556);
		} else {
			lp->pdata->device_control = (lp->mode == PWM_BASED) ?
				PWM_CONFIG(LP8556) : I2C_CONFIG(LP8556);
			if (of_property_read_bool(dev->of_node, "fast_ctrl"))
				lp->pdata->device_control |= (LP8556_FAST_CTRL);
		}
		break;
	case LP8557:
		rc = of_property_read_u32(dev->of_node,
			"dev-ctrl", &tmp_data);
		if (rc) {
			dev_err(dev, "Failure reading dev-ctrl, rc = %d\n", rc);
			lp->pdata->device_control = (lp->mode == PWM_BASED) ?
				PWM_CONFIG(LP8557) : I2C_CONFIG(LP8557);
		} else {
			lp->pdata->device_control = (u8)tmp_data;
		}
		rc = of_property_read_u32(dev->of_node,
			"pwm-period", &lp->pdata->period_ns);
		if (rc) {
			dev_err(dev,
				"Failure reading pwm-period, rc = %d\n",
				rc);
			lp->pdata->period_ns = (lp->mode == PWM_BASED) ? 80 : 0;
		}
		lp->pdata->bl_enable_valid = false;
		break;
	}
	rc = of_property_read_u32(dev->of_node,
		"max_br", &lp->pdata->max_brightness);
	if (rc) {
		dev_err(dev, "Failure reading max_br, rc = %d\n", rc);
		lp->pdata->max_brightness = MAX_BRT;
	}
	if (lp->pdata->max_brightness > MAX_BRT)
		lp->pdata->max_brightness = MAX_BRT;

	rc = of_property_read_u32(dev->of_node,
			"init_br", &lp->pdata->initial_brightness);
	if (rc) {
		dev_err(dev, "Failure reading init_br, rc = %d\n", rc);
		lp->pdata->initial_brightness = INITIAL_BRT;
	}

	if (lp->pdata->initial_brightness > lp->pdata->max_brightness)
		lp->pdata->initial_brightness = lp->pdata->max_brightness;

	rc = of_property_read_u32(dev->of_node, "slope_reg", &tmp_data);
	if (!rc) {
		lp->pdata->slope_reg = tmp_data;
	} else {
		dev_err(dev,
			"Failure reading cfg3_reg, rc = %d\n",
			rc);
		lp->pdata->slope_reg = 0x5e;
	}
	if (lp->pdata->bl_enable_valid) {
		lp->pdata->gpio_bl_enable = of_get_named_gpio(dev->of_node,
			"bl_enable", 0);
		if (!gpio_is_valid(lp->pdata->gpio_bl_enable)) {
			dev_err(dev, "%s can't get gpio\n", __func__);
			return -ENODEV;
		}
	}

	node = dev->of_node;
	if (node == NULL)
		return -ENODEV;

	lp->pdata->load_new_rom_data = 0;
	temp = NULL;
	lp->pdata->size_program = of_get_child_count(node);

	if (!lp->pdata->size_program)
		return 0;
	lp->pdata->rom_data = kzalloc(
		sizeof(struct lp855x_rom_data) * lp->pdata->size_program,
		GFP_KERNEL);
	if (!lp->pdata->rom_data) {
		dev_err(dev, "Unable to allocate memory\n");
		return 0;
	}
	i = 0;
	for_each_child_of_node(node, temp) {
		rc = of_property_read_u32(temp, "addr", &tmp_data);
		if (rc) {
			dev_err(dev,
				"Failure reading addr, rc = %d\n",
				rc);
			continue;
		}
		lp->pdata->rom_data[i].addr = tmp_data;
		rc = of_property_read_u32(temp, "data", &tmp_data);
		if (rc) {
			dev_err(dev,
				"Failure reading data, rc = %d\n",
				rc);
			continue;
		}
		lp->pdata->rom_data[i].val = tmp_data;
		++i;
	}
static int lp855x_parse_dt(struct device *dev,
		struct lp855x_platform_data *pdata,
		const struct i2c_device_id **id)
{
	int i, rc;
	const char *str;
	struct device_node *node, *temp;
	unsigned tmp_data;

	rc = of_property_read_string(dev->of_node, "linux,name", &pdata->name);
	if (rc) {
		dev_err(dev, "Failure reading name, rc = %d\n", rc);
		pdata->name = "lcd-backlight";
	}
	rc = of_property_read_string(dev->of_node, "linux,default-trigger",
		&str);
	if (!rc) {
		pdata->default_trigger = str;
	} else {
		dev_err(dev, "Failure reading default-trigger, rc = %d\n", rc);
		pdata->default_trigger = "none";
	}
	rc = of_property_read_string(dev->of_node, "mode", &str);
	if (!rc) {
		pdata->mode = (strncmp(str, "pwm based", strlen(str)) == 0) ?
			PWM_BASED : REGISTER_BASED;
	} else {
		dev_err(dev, "Failure reading mode, rc = %d\n", rc);
		pdata->mode = REGISTER_BASED;
	}
	rc = of_property_read_string(dev->of_node, "chip_name", &str);
	if (!rc) {
		*id = lp855x_get_i2c_device_id(str);
	} else {
		dev_err(dev, "Failure reading chip_name, rc = %d\n", rc);
		*id = lp855x_get_i2c_device_id("lp8556");
	}
	switch ((*id)->driver_data) {
	default:
	case LP8550:
		pdata->device_control = (pdata->mode == PWM_BASED) ?
			PWM_CONFIG(LP8550) : I2C_CONFIG(LP8550);
		break;
	case LP8551:
		pdata->device_control = (pdata->mode == PWM_BASED) ?
			PWM_CONFIG(LP8551) : I2C_CONFIG(LP8551);
		break;
	case LP8552:
		pdata->device_control = (pdata->mode == PWM_BASED) ?
			PWM_CONFIG(LP8552) : I2C_CONFIG(LP8552);
		break;
	case LP8553:
		pdata->device_control = (pdata->mode == PWM_BASED) ?
			PWM_CONFIG(LP8553) : I2C_CONFIG(LP8553);
		break;
	case LP8556:
		rc = of_property_read_string(dev->of_node, "config", &str);
		if (!rc) {
			if (strncmp(str, "combined1", strlen(str)) == 0)
				pdata->device_control = LP8556_COMB1_CONFIG;
			else if (strncmp(str, "combined2", strlen(str)) == 0)
				pdata->device_control = LP8556_COMB2_CONFIG;
			else
				pdata->device_control = I2C_CONFIG(LP8556);
		} else {
			pdata->device_control = (pdata->mode == PWM_BASED) ?
				PWM_CONFIG(LP8556) : I2C_CONFIG(LP8556);
		}
		break;
	}
	rc = of_property_read_u32(dev->of_node,
		"max_br", &pdata->max_brightness);
	if (rc) {
		dev_err(dev, "Failure reading max_br, rc = %d\n", rc);
		pdata->max_brightness = MAX_BRT;
	}
	if (pdata->max_brightness > MAX_BRT)
		pdata->max_brightness = MAX_BRT;
	rc = of_property_read_u32(dev->of_node,
		"init_br", &pdata->initial_brightness);
	if (rc) {
		dev_err(dev, "Failure reading init_br, rc = %d\n", rc);
		pdata->initial_brightness = INITIAL_BRT;
	}
	if (pdata->initial_brightness > pdata->max_brightness)
		pdata->initial_brightness = pdata->max_brightness;
	rc = of_property_read_u32(dev->of_node, "cfg3_reg", &tmp_data);
	if (!rc) {
		pdata->cfg3 = tmp_data;
	} else {
		dev_err(dev, "Failure reading cfg3_reg, rc = %d\n", rc);
		pdata->cfg3 = 0x5e;
	}
	pdata->gpio_bl_enable = of_get_named_gpio(dev->of_node, "bl_enable", 0);
	if (!gpio_is_valid(pdata->gpio_bl_enable)) {
		dev_err(dev, "%s can't get gpio\n", __func__);
		return -ENODEV;
	}
	node = dev->of_node;
	if (node == NULL)
		return -ENODEV;

	pdata->load_new_rom_data = 0;
	pdata->size_program = 0;
	temp = NULL;
	while ((temp = of_get_next_child(node, temp)))
		++pdata->size_program;

	if (!pdata->size_program)
		return 0;
	pdata->rom_data = kzalloc(
		sizeof(struct lp855x_rom_data) * pdata->size_program,
		GFP_KERNEL);
	if (!pdata->rom_data) {
		dev_err(dev, "Unable to allocate memory\n");
		return 0;
	}
	i = 0;
	for_each_child_of_node(node, temp) {
		rc = of_property_read_u32(temp, "addr", &tmp_data);
		if (rc) {
			dev_err(dev, "Failure reading addr, rc = %d\n", rc);
			continue;
		}
		pdata->rom_data[i].addr = tmp_data;
		rc = of_property_read_u32(temp, "data", &tmp_data);
		if (rc) {
			dev_err(dev, "Failure reading data, rc = %d\n", rc);
			continue;
		}
		pdata->rom_data[i].val = tmp_data;
		++i;
	}