static ssize_t attr_flash_sync_enable_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct lm3561_drv_data *data = dev_get_drvdata(dev);
	int result;
	u8 reg_cfg1;

	result = lm3561_get_reg_data(data, LM3561_REG_CFG_1, &reg_cfg1);
	if (result)
		return result;
	reg_cfg1 &= LM3561_CFG1_STROBE_INPUT_MASK;

	return snprintf(buf, PAGE_SIZE, "%hu\n", reg_cfg1 ? 1 : 0);
}
static int lm3561_get_flash_current(struct lm3561_drv_data *data,
				    unsigned long *get_current)
{
	u8 leds = 1, reg_current;
	int result;

	result = lm3561_get_reg_data(data,
				     LM3561_REG_FLASH_BRIGHT,
				     &reg_current);
	if (result)
		return result;

	*get_current = ((reg_current & 0x0f) + 1)
		* lm3561_limits.flash_current_min * leds;

	return result;
}
static int lm3561_get_flash_duration(struct lm3561_drv_data *data,
				    unsigned long *flash_duration)
{
	u8 reg_duration;
	int result;

	result = lm3561_get_reg_data(data,
				     LM3561_REG_FLASH_DURATION,
				     &reg_duration);
	if (result != 0)
		return result;

	*flash_duration = ((reg_duration & LM3561_FLASH_DURATION_MASK) + 1)
		* lm3561_limits.flash_duration_min;

	return result;

}
static int lm3561_get_torch_current(struct lm3561_drv_data *data,
				    unsigned long *get_current)
{
	u8 leds = 1, reg_current;
	int result;

	result = lm3561_get_reg_data(data,
				     LM3561_REG_TORCH_BRIGHT,
				     &reg_current);
	if (result)
		return result;

	*get_current = ((reg_current & LM3561_TORCH_BRIGHT_MASK)
		* lm3561_limits.torch_current_step * leds
		+ lm3561_limits.torch_current_min * leds);

	return result;
}
static ssize_t attr_flash_enable_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct lm3561_drv_data *data = dev_get_drvdata(dev);
	u8 value;
	int result;

	result = lm3561_get_reg_data(data, LM3561_REG_ENABLE, &value);

	if (result)
		return result;

	/* Get flash enable */
	value &= LM3561_ENABLE_EN_MASK;
	value = (value == LM3561_ENABLE_EN_FLASH_MODE) ? 1 : 0;

	return snprintf(buf, PAGE_SIZE, "%u\n", value);
}
static ssize_t attr_flash_sync_enable_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct lm3561_drv_data *data = dev_get_drvdata(dev);
	int result;
	u8 reg_cfg1;

	result = pm_runtime_get_sync(&data->client->dev);
	if (result < 0)
		return result;
	result = lm3561_get_reg_data(data, LM3561_REG_CFG_1, &reg_cfg1);
	pm_runtime_mark_last_busy(&data->client->dev);
	pm_runtime_put_autosuspend(&data->client->dev);
	if (result)
		return result;
	reg_cfg1 &= LM3561_CFG1_STROBE_INPUT_MASK;

	return snprintf(buf, PAGE_SIZE, "%hu\n", reg_cfg1 ? 1 : 0);
}
static ssize_t attr_flash_enable_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct lm3561_drv_data *data = dev_get_drvdata(dev);
	u8 value;
	int result;

	result = pm_runtime_get_sync(&data->client->dev);
	if (result < 0)
		return result;
	result = lm3561_get_reg_data(data, LM3561_REG_ENABLE, &value);
	pm_runtime_mark_last_busy(&data->client->dev);
	pm_runtime_put_autosuspend(&data->client->dev);
	if (result)
		return result;

	/* Get flash enable */
	value &= LM3561_ENABLE_EN_MASK;
	value = (value == LM3561_ENABLE_EN_FLASH_MODE) ? 1 : 0;

	return snprintf(buf, PAGE_SIZE, "%u\n", value);
}
static int lm3561_check_status(struct lm3561_drv_data *data, u8 *return_status)
{
	u8 status = 0;
	int error;

	*return_status = 0;

	/* set Tx2/GPIO2 Control as flash interrupt input */
	error = lm3561_set_reg_data(data,
				LM3561_REG_GPIO,
				LM3561_GPIO_CTRL_MASK,
				LM3561_GPIO_CTRL_FLASH);
	if (error)
		return error;

	error = lm3561_get_reg_data(data, LM3561_REG_FLAG, &status);
	if (error)
		return error;

	*return_status &= status;

	return error;
}