Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e35e33c authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mauro Carvalho Chehab
Browse files

[media] adv7180: Consolidate video mode setting



We have basically the same code to set the video standard in init_device()
and adv7180_s_std(). Factor this out into a common helper function.

Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Acked-by: default avatarFederico Vaga <federico.vaga@gmail.com>
Acked-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent d5d51a82
Loading
Loading
Loading
Loading
+32 −35
Original line number Original line Diff line number Diff line
@@ -302,37 +302,54 @@ static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
	return ret;
	return ret;
}
}


static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
static int adv7180_program_std(struct adv7180_state *state)
{
{
	struct adv7180_state *state = to_state(sd);
	int ret;
	int ret = mutex_lock_interruptible(&state->mutex);
	if (ret)
		return ret;


	/* all standards -> autodetect */
	if (state->autodetect) {
	if (std == V4L2_STD_ALL) {
		ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
		ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
				    ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
				    ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
				    | state->input);
				    | state->input);
		if (ret < 0)
		if (ret < 0)
			goto out;
			return ret;


		__adv7180_status(state, NULL, &state->curr_norm);
		__adv7180_status(state, NULL, &state->curr_norm);
		state->autodetect = true;
	} else {
	} else {
		ret = v4l2_std_to_adv7180(std);
		ret = v4l2_std_to_adv7180(state->curr_norm);
		if (ret < 0)
		if (ret < 0)
			goto out;
			return ret;


		ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
		ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
				    ret | state->input);
				    ret | state->input);
		if (ret < 0)
			return ret;
	}

	return 0;
}

static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
{
	struct adv7180_state *state = to_state(sd);
	int ret = mutex_lock_interruptible(&state->mutex);

	if (ret)
		return ret;

	/* all standards -> autodetect */
	if (std == V4L2_STD_ALL) {
		state->autodetect = true;
	} else {
		/* Make sure we can support this std */
		ret = v4l2_std_to_adv7180(std);
		if (ret < 0)
		if (ret < 0)
			goto out;
			goto out;


		state->curr_norm = std;
		state->curr_norm = std;
		state->autodetect = false;
		state->autodetect = false;
	}
	}
	ret = 0;

	ret = adv7180_program_std(state);
out:
out:
	mutex_unlock(&state->mutex);
	mutex_unlock(&state->mutex);
	return ret;
	return ret;
@@ -546,30 +563,10 @@ static int init_device(struct adv7180_state *state)
	adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
	adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
	usleep_range(2000, 10000);
	usleep_range(2000, 10000);


	/* Initialize adv7180 */
	ret = adv7180_program_std(state);
	/* Enable autodetection */
	if (ret)
	if (state->autodetect) {
		ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
				ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
					      | state->input);
		if (ret < 0)
			goto out_unlock;

		ret = adv7180_write(state, ADV7180_REG_AUTODETECT_ENABLE,
					      ADV7180_AUTODETECT_DEFAULT);
		if (ret < 0)
			goto out_unlock;
	} else {
		ret = v4l2_std_to_adv7180(state->curr_norm);
		if (ret < 0)
			goto out_unlock;

		ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
					      ret | state->input);
		if (ret < 0)
		goto out_unlock;
		goto out_unlock;


	}
	/* ITU-R BT.656-4 compatible */
	/* ITU-R BT.656-4 compatible */
	ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
	ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
			ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);
			ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);