Commit 5525fd86 authored by Bingbu Cao's avatar Bingbu Cao Committed by Mauro Carvalho Chehab
Browse files

media: ov5675: Support device probe in non-zero ACPI D state



Tell ACPI device PM code that the driver supports the device being in
non-zero ACPI D state when the driver's probe function is entered.

Also do identification on the first access of the device, whether in probe
or when starting streaming.

Signed-off-by: default avatarBingbu Cao <bingbu.cao@intel.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 56ca3be8
Loading
Loading
Loading
Loading
+46 −25
Original line number Diff line number Diff line
@@ -493,6 +493,9 @@ struct ov5675 {

	/* Streaming on/off */
	bool streaming;

	/* True if the device has been identified */
	bool identified;
};

static u64 to_pixel_rate(u32 f_index)
@@ -808,12 +811,41 @@ static void ov5675_update_pad_format(const struct ov5675_mode *mode,
	fmt->field = V4L2_FIELD_NONE;
}

static int ov5675_identify_module(struct ov5675 *ov5675)
{
	struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
	int ret;
	u32 val;

	if (ov5675->identified)
		return 0;

	ret = ov5675_read_reg(ov5675, OV5675_REG_CHIP_ID,
			      OV5675_REG_VALUE_24BIT, &val);
	if (ret)
		return ret;

	if (val != OV5675_CHIP_ID) {
		dev_err(&client->dev, "chip id mismatch: %x!=%x",
			OV5675_CHIP_ID, val);
		return -ENXIO;
	}

	ov5675->identified = true;

	return 0;
}

static int ov5675_start_streaming(struct ov5675 *ov5675)
{
	struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
	const struct ov5675_reg_list *reg_list;
	int link_freq_index, ret;

	ret = ov5675_identify_module(ov5675);
	if (ret)
		return ret;

	link_freq_index = ov5675->cur_mode->link_freq_index;
	reg_list = &link_freq_configs[link_freq_index].reg_list;
	ret = ov5675_write_reg_list(ov5675, reg_list);
@@ -1048,26 +1080,6 @@ static const struct v4l2_subdev_internal_ops ov5675_internal_ops = {
	.open = ov5675_open,
};

static int ov5675_identify_module(struct ov5675 *ov5675)
{
	struct i2c_client *client = v4l2_get_subdevdata(&ov5675->sd);
	int ret;
	u32 val;

	ret = ov5675_read_reg(ov5675, OV5675_REG_CHIP_ID,
			      OV5675_REG_VALUE_24BIT, &val);
	if (ret)
		return ret;

	if (val != OV5675_CHIP_ID) {
		dev_err(&client->dev, "chip id mismatch: %x!=%x",
			OV5675_CHIP_ID, val);
		return -ENXIO;
	}

	return 0;
}

static int ov5675_check_hwcfg(struct device *dev)
{
	struct fwnode_handle *ep;
@@ -1154,6 +1166,7 @@ static int ov5675_remove(struct i2c_client *client)
static int ov5675_probe(struct i2c_client *client)
{
	struct ov5675 *ov5675;
	bool full_power;
	int ret;

	ret = ov5675_check_hwcfg(&client->dev);
@@ -1168,11 +1181,15 @@ static int ov5675_probe(struct i2c_client *client)
		return -ENOMEM;

	v4l2_i2c_subdev_init(&ov5675->sd, client, &ov5675_subdev_ops);

	full_power = acpi_dev_state_d0(&client->dev);
	if (full_power) {
		ret = ov5675_identify_module(ov5675);
		if (ret) {
			dev_err(&client->dev, "failed to find sensor: %d", ret);
			return ret;
		}
	}

	mutex_init(&ov5675->mutex);
	ov5675->cur_mode = &supported_modes[0];
@@ -1204,6 +1221,9 @@ static int ov5675_probe(struct i2c_client *client)
	 * Device is already turned on by i2c-core with ACPI domain PM.
	 * Enable runtime PM and turn off the device.
	 */

	/* Set the device's state to active if it's in D0 state. */
	if (full_power)
		pm_runtime_set_active(&client->dev);
	pm_runtime_enable(&client->dev);
	pm_runtime_idle(&client->dev);
@@ -1241,6 +1261,7 @@ static struct i2c_driver ov5675_i2c_driver = {
	},
	.probe_new = ov5675_probe,
	.remove = ov5675_remove,
	.flags = I2C_DRV_ACPI_WAIVE_D0_PROBE,
};

module_i2c_driver(ov5675_i2c_driver);