aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/i2c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2015-01-23 10:52:27 -0500
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2015-02-02 08:46:33 -0500
commit3e35e33c086ca81e0576ad1ace22ca058d071b2c (patch)
tree8b644494f03eba09b1c65eaad878a523d89edb90 /drivers/media/i2c
parentd5d51a827bb86103d4874a864f72674b281408ac (diff)
[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: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Federico Vaga <federico.vaga@gmail.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/i2c')
-rw-r--r--drivers/media/i2c/adv7180.c67
1 files changed, 32 insertions, 35 deletions
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 5193596b68ff..363d8d98914c 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -302,37 +302,54 @@ static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
302 return ret; 302 return ret;
303} 303}
304 304
305static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 305static int adv7180_program_std(struct adv7180_state *state)
306{ 306{
307 struct adv7180_state *state = to_state(sd); 307 int ret;
308 int ret = mutex_lock_interruptible(&state->mutex);
309 if (ret)
310 return ret;
311 308
312 /* all standards -> autodetect */ 309 if (state->autodetect) {
313 if (std == V4L2_STD_ALL) {
314 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, 310 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
315 ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM 311 ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
316 | state->input); 312 | state->input);
317 if (ret < 0) 313 if (ret < 0)
318 goto out; 314 return ret;
319 315
320 __adv7180_status(state, NULL, &state->curr_norm); 316 __adv7180_status(state, NULL, &state->curr_norm);
321 state->autodetect = true;
322 } else { 317 } else {
323 ret = v4l2_std_to_adv7180(std); 318 ret = v4l2_std_to_adv7180(state->curr_norm);
324 if (ret < 0) 319 if (ret < 0)
325 goto out; 320 return ret;
326 321
327 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, 322 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
328 ret | state->input); 323 ret | state->input);
329 if (ret < 0) 324 if (ret < 0)
325 return ret;
326 }
327
328 return 0;
329}
330
331static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
332{
333 struct adv7180_state *state = to_state(sd);
334 int ret = mutex_lock_interruptible(&state->mutex);
335
336 if (ret)
337 return ret;
338
339 /* all standards -> autodetect */
340 if (std == V4L2_STD_ALL) {
341 state->autodetect = true;
342 } else {
343 /* Make sure we can support this std */
344 ret = v4l2_std_to_adv7180(std);
345 if (ret < 0)
330 goto out; 346 goto out;
331 347
332 state->curr_norm = std; 348 state->curr_norm = std;
333 state->autodetect = false; 349 state->autodetect = false;
334 } 350 }
335 ret = 0; 351
352 ret = adv7180_program_std(state);
336out: 353out:
337 mutex_unlock(&state->mutex); 354 mutex_unlock(&state->mutex);
338 return ret; 355 return ret;
@@ -546,30 +563,10 @@ static int init_device(struct adv7180_state *state)
546 adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); 563 adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
547 usleep_range(2000, 10000); 564 usleep_range(2000, 10000);
548 565
549 /* Initialize adv7180 */ 566 ret = adv7180_program_std(state);
550 /* Enable autodetection */ 567 if (ret)
551 if (state->autodetect) { 568 goto out_unlock;
552 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
553 ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
554 | state->input);
555 if (ret < 0)
556 goto out_unlock;
557
558 ret = adv7180_write(state, ADV7180_REG_AUTODETECT_ENABLE,
559 ADV7180_AUTODETECT_DEFAULT);
560 if (ret < 0)
561 goto out_unlock;
562 } else {
563 ret = v4l2_std_to_adv7180(state->curr_norm);
564 if (ret < 0)
565 goto out_unlock;
566
567 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
568 ret | state->input);
569 if (ret < 0)
570 goto out_unlock;
571 569
572 }
573 /* ITU-R BT.656-4 compatible */ 570 /* ITU-R BT.656-4 compatible */
574 ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL, 571 ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
575 ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS); 572 ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);