/*
 * sensor_power - handle sensor power up/down.
 *
 * @enable: If it is true, power up. If is not, power down.
 */
static int sensor_power(struct sensor_info *info, bool enable)
{
	struct v4l2_subdev *sd = &info->sd;
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct device *cdev = &client->dev;
	const struct exynos_fimc_is_sensor_platform_data *pdata = cdev->platform_data;
	int ret = 0;

	if (enable) {
		if (is_powerup(sd))
			return 0;

		if (pdata->clk_on) {
			pdata->clk_on(cdev, FLITE_ID_C);
		} else {
			sensor_err("failed to clk_on\n");
			return -1;
		}
		info->power = true;
	} else {
		if (!is_powerup(sd))
			return 0;

		if (pdata->clk_off) {
			pdata->clk_off(cdev, FLITE_ID_C);
		} else {
			sensor_err("failed to clk_off\n");
			return -1;
		}
		info->power = false;
	}

	return ret;
}
/*
 * m5mols_sensor_power - handle sensor power up/down.
 *
 * @enable: If it is true, power up. If is not, power down.
 */
static int m5mols_sensor_power(struct m5mols_info *info, bool enable)
{
	struct v4l2_subdev *sd = &info->sd;
	struct i2c_client *c = v4l2_get_subdevdata(sd);
	int ret;

	if (enable) {
		if (is_powerup(sd))
			return 0;

		/* power-on additional power */
		if (info->set_power) {
			ret = info->set_power(&c->dev, 1);
			if (ret)
				return ret;
		}

		ret = regulator_bulk_enable(ARRAY_SIZE(supplies), supplies);
		if (ret)
			return ret;

		gpio_set_value(info->pdata->gpio_rst, info->pdata->enable_rst);
		usleep_range(1000, 1000);

		info->power = true;
	} else {
		if (!is_powerup(sd))
			return 0;

		ret = regulator_bulk_disable(ARRAY_SIZE(supplies), supplies);
		if (ret)
			return ret;

		/* power-off additional power */
		if (info->set_power) {
			ret = info->set_power(&c->dev, 0);
			if (ret)
				return ret;
		}

		info->power = false;

		gpio_set_value(info->pdata->gpio_rst, !info->pdata->enable_rst);
		usleep_range(1000, 1000);
	}

	return ret;
}
static void m5mols_irq_work(struct work_struct *work)
{
	struct m5mols_info *info = container_of(work, struct m5mols_info, work);
	struct v4l2_subdev *sd = &info->sd;
	u32 reg;
	int ret;
	if (is_powerup(sd)) {
		ret = i2c_r8_system(sd, CAT0_INT_FACTOR, &reg);
		if (!ret) {
			switch (reg & 0x0f) {
			case (1 << INT_BIT_AF):
				/* Except returning zero at just that upper
				 * statments, not entering in this parenthesis.
				 * The return value is below:
				 * 0x0 : AF Fail
				 * 0x2 : AF Success
				 * 0x4 : Idle Status
				 * 0x5 : Busy Status */
				ret = i2c_r8_lens(sd, CATA_AF_STATUS, &reg);
				if (!ret && (reg == 0x02))
					info->is_focus = true;
				else
					info->is_focus = false;
				printk("%s = AF %02x, focus %d\n",
						__func__, reg, info->is_focus);
				break;
			case (1 << INT_BIT_CAPTURE):
				printk("%s = CAPTURE\n", __func__);
				if (!info->captured) {
					wake_up_interruptible(&info->cap_wait);
					info->captured = true;
				}
				break;
			case (1 << INT_BIT_ZOOM):
			case (1 << INT_BIT_FRAME_SYNC):
			case (1 << INT_BIT_FD):
			case (1 << INT_BIT_LENS_INIT):
			case (1 << INT_BIT_SOUND):
				printk("%s = Nothing : 0x%08x\n", __func__, reg);
				break;
			case (1 << INT_BIT_MODE):
			default:
				break;
			}
		}
	}
}