aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c19
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c99
-rw-r--r--drivers/media/video/cx88/cx88-cards.c7
-rw-r--r--drivers/media/video/cx88/cx88-video.c27
-rw-r--r--drivers/media/video/cx88/cx88.h6
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c2
-rw-r--r--drivers/media/video/mx2_camera.c2
-rw-r--r--drivers/media/video/s5p-fimc/fimc-capture.c51
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c54
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.h24
-rw-r--r--drivers/media/video/s5p-fimc/regs-fimc.h3
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c2
-rw-r--r--drivers/media/video/soc_camera.c4
-rw-r--r--drivers/media/video/wm8775.c104
14 files changed, 182 insertions, 222 deletions
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index dfb198d0415b..f16461844c5c 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -1989,8 +1989,23 @@ static int cx25840_probe(struct i2c_client *client,
1989 v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops, 1989 v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops,
1990 V4L2_CID_HUE, -128, 127, 1, 0); 1990 V4L2_CID_HUE, -128, 127, 1, 0);
1991 if (!is_cx2583x(state)) { 1991 if (!is_cx2583x(state)) {
1992 default_volume = 228 - cx25840_read(client, 0x8d4); 1992 default_volume = cx25840_read(client, 0x8d4);
1993 default_volume = ((default_volume / 2) + 23) << 9; 1993 /*
1994 * Enforce the legacy PVR-350/MSP3400 to PVR-150/CX25843 volume
1995 * scale mapping limits to avoid -ERANGE errors when
1996 * initializing the volume control
1997 */
1998 if (default_volume > 228) {
1999 /* Bottom out at -96 dB, v4l2 vol range 0x2e00-0x2fff */
2000 default_volume = 228;
2001 cx25840_write(client, 0x8d4, 228);
2002 }
2003 else if (default_volume < 20) {
2004 /* Top out at + 8 dB, v4l2 vol range 0xfe00-0xffff */
2005 default_volume = 20;
2006 cx25840_write(client, 0x8d4, 20);
2007 }
2008 default_volume = (((228 - default_volume) >> 1) + 23) << 9;
1994 2009
1995 state->volume = v4l2_ctrl_new_std(&state->hdl, 2010 state->volume = v4l2_ctrl_new_std(&state->hdl,
1996 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 2011 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME,
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 4aaa47c0eabf..54b7fcd469a8 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -40,7 +40,6 @@
40#include <sound/control.h> 40#include <sound/control.h>
41#include <sound/initval.h> 41#include <sound/initval.h>
42#include <sound/tlv.h> 42#include <sound/tlv.h>
43#include <media/wm8775.h>
44 43
45#include "cx88.h" 44#include "cx88.h"
46#include "cx88-reg.h" 45#include "cx88-reg.h"
@@ -587,47 +586,26 @@ static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol,
587 int left, right, v, b; 586 int left, right, v, b;
588 int changed = 0; 587 int changed = 0;
589 u32 old; 588 u32 old;
590 struct v4l2_control client_ctl;
591
592 /* Pass volume & balance onto any WM8775 */
593 if (value->value.integer.value[0] >= value->value.integer.value[1]) {
594 v = value->value.integer.value[0] << 10;
595 b = value->value.integer.value[0] ?
596 (0x8000 * value->value.integer.value[1]) / value->value.integer.value[0] :
597 0x8000;
598 } else {
599 v = value->value.integer.value[1] << 10;
600 b = value->value.integer.value[1] ?
601 0xffff - (0x8000 * value->value.integer.value[0]) / value->value.integer.value[1] :
602 0x8000;
603 }
604 client_ctl.value = v;
605 client_ctl.id = V4L2_CID_AUDIO_VOLUME;
606 call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
607
608 client_ctl.value = b;
609 client_ctl.id = V4L2_CID_AUDIO_BALANCE;
610 call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
611 589
612 left = value->value.integer.value[0] & 0x3f; 590 left = value->value.integer.value[0] & 0x3f;
613 right = value->value.integer.value[1] & 0x3f; 591 right = value->value.integer.value[1] & 0x3f;
614 b = right - left; 592 b = right - left;
615 if (b < 0) { 593 if (b < 0) {
616 v = 0x3f - left; 594 v = 0x3f - left;
617 b = (-b) | 0x40; 595 b = (-b) | 0x40;
618 } else { 596 } else {
619 v = 0x3f - right; 597 v = 0x3f - right;
620 } 598 }
621 /* Do we really know this will always be called with IRQs on? */ 599 /* Do we really know this will always be called with IRQs on? */
622 spin_lock_irq(&chip->reg_lock); 600 spin_lock_irq(&chip->reg_lock);
623 old = cx_read(AUD_VOL_CTL); 601 old = cx_read(AUD_VOL_CTL);
624 if (v != (old & 0x3f)) { 602 if (v != (old & 0x3f)) {
625 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, (old & ~0x3f) | v); 603 cx_write(AUD_VOL_CTL, (old & ~0x3f) | v);
626 changed = 1; 604 changed = 1;
627 } 605 }
628 if ((cx_read(AUD_BAL_CTL) & 0x7f) != b) { 606 if (cx_read(AUD_BAL_CTL) != b) {
629 cx_write(AUD_BAL_CTL, b); 607 cx_write(AUD_BAL_CTL, b);
630 changed = 1; 608 changed = 1;
631 } 609 }
632 spin_unlock_irq(&chip->reg_lock); 610 spin_unlock_irq(&chip->reg_lock);
633 611
@@ -640,7 +618,7 @@ static const struct snd_kcontrol_new snd_cx88_volume = {
640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 618 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
641 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 619 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
642 SNDRV_CTL_ELEM_ACCESS_TLV_READ, 620 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
643 .name = "Analog-TV Volume", 621 .name = "Playback Volume",
644 .info = snd_cx88_volume_info, 622 .info = snd_cx88_volume_info,
645 .get = snd_cx88_volume_get, 623 .get = snd_cx88_volume_get,
646 .put = snd_cx88_volume_put, 624 .put = snd_cx88_volume_put,
@@ -671,14 +649,7 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
671 vol = cx_read(AUD_VOL_CTL); 649 vol = cx_read(AUD_VOL_CTL);
672 if (value->value.integer.value[0] != !(vol & bit)) { 650 if (value->value.integer.value[0] != !(vol & bit)) {
673 vol ^= bit; 651 vol ^= bit;
674 cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol); 652 cx_write(AUD_VOL_CTL, vol);
675 /* Pass mute onto any WM8775 */
676 if ((1<<6) == bit) {
677 struct v4l2_control client_ctl;
678 client_ctl.value = 0 != (vol & bit);
679 client_ctl.id = V4L2_CID_AUDIO_MUTE;
680 call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
681 }
682 ret = 1; 653 ret = 1;
683 } 654 }
684 spin_unlock_irq(&chip->reg_lock); 655 spin_unlock_irq(&chip->reg_lock);
@@ -687,7 +658,7 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
687 658
688static const struct snd_kcontrol_new snd_cx88_dac_switch = { 659static const struct snd_kcontrol_new snd_cx88_dac_switch = {
689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
690 .name = "Audio-Out Switch", 661 .name = "Playback Switch",
691 .info = snd_ctl_boolean_mono_info, 662 .info = snd_ctl_boolean_mono_info,
692 .get = snd_cx88_switch_get, 663 .get = snd_cx88_switch_get,
693 .put = snd_cx88_switch_put, 664 .put = snd_cx88_switch_put,
@@ -696,49 +667,13 @@ static const struct snd_kcontrol_new snd_cx88_dac_switch = {
696 667
697static const struct snd_kcontrol_new snd_cx88_source_switch = { 668static const struct snd_kcontrol_new snd_cx88_source_switch = {
698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 669 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
699 .name = "Analog-TV Switch", 670 .name = "Capture Switch",
700 .info = snd_ctl_boolean_mono_info, 671 .info = snd_ctl_boolean_mono_info,
701 .get = snd_cx88_switch_get, 672 .get = snd_cx88_switch_get,
702 .put = snd_cx88_switch_put, 673 .put = snd_cx88_switch_put,
703 .private_value = (1<<6), 674 .private_value = (1<<6),
704}; 675};
705 676
706static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_value *value)
708{
709 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
710 struct cx88_core *core = chip->core;
711 struct v4l2_control client_ctl;
712
713 client_ctl.id = V4L2_CID_AUDIO_LOUDNESS;
714 call_hw(core, WM8775_GID, core, g_ctrl, &client_ctl);
715 value->value.integer.value[0] = client_ctl.value ? 1 : 0;
716
717 return 0;
718}
719
720static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol,
721 struct snd_ctl_elem_value *value)
722{
723 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
724 struct cx88_core *core = chip->core;
725 struct v4l2_control client_ctl;
726
727 client_ctl.value = 0 != value->value.integer.value[0];
728 client_ctl.id = V4L2_CID_AUDIO_LOUDNESS;
729 call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
730
731 return 0;
732}
733
734static struct snd_kcontrol_new snd_cx88_alc_switch = {
735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
736 .name = "Line-In ALC Switch",
737 .info = snd_ctl_boolean_mono_info,
738 .get = snd_cx88_alc_get,
739 .put = snd_cx88_alc_put,
740};
741
742/**************************************************************************** 677/****************************************************************************
743 Basic Flow for Sound Devices 678 Basic Flow for Sound Devices
744 ****************************************************************************/ 679 ****************************************************************************/
@@ -860,7 +795,6 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
860{ 795{
861 struct snd_card *card; 796 struct snd_card *card;
862 snd_cx88_card_t *chip; 797 snd_cx88_card_t *chip;
863 struct v4l2_subdev *sd;
864 int err; 798 int err;
865 799
866 if (devno >= SNDRV_CARDS) 800 if (devno >= SNDRV_CARDS)
@@ -896,15 +830,6 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
896 if (err < 0) 830 if (err < 0)
897 goto error; 831 goto error;
898 832
899 /* If there's a wm8775 then add a Line-In ALC switch */
900 list_for_each_entry(sd, &chip->core->v4l2_dev.subdevs, list) {
901 if (WM8775_GID == sd->grp_id) {
902 snd_ctl_add(card, snd_ctl_new1(&snd_cx88_alc_switch,
903 chip));
904 break;
905 }
906 }
907
908 strcpy (card->driver, "CX88x"); 833 strcpy (card->driver, "CX88x");
909 sprintf(card->shortname, "Conexant CX%x", pci->device); 834 sprintf(card->shortname, "Conexant CX%x", pci->device);
910 sprintf(card->longname, "%s at %#llx", 835 sprintf(card->longname, "%s at %#llx",
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 9b9e169cce90..0ccc2afd7266 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1007,15 +1007,22 @@ static const struct cx88_board cx88_boards[] = {
1007 .radio_type = UNSET, 1007 .radio_type = UNSET,
1008 .tuner_addr = ADDR_UNSET, 1008 .tuner_addr = ADDR_UNSET,
1009 .radio_addr = ADDR_UNSET, 1009 .radio_addr = ADDR_UNSET,
1010 .audio_chip = V4L2_IDENT_WM8775,
1010 .input = {{ 1011 .input = {{
1011 .type = CX88_VMUX_DVB, 1012 .type = CX88_VMUX_DVB,
1012 .vmux = 0, 1013 .vmux = 0,
1014 /* 2: Line-In */
1015 .audioroute = 2,
1013 },{ 1016 },{
1014 .type = CX88_VMUX_COMPOSITE1, 1017 .type = CX88_VMUX_COMPOSITE1,
1015 .vmux = 1, 1018 .vmux = 1,
1019 /* 2: Line-In */
1020 .audioroute = 2,
1016 },{ 1021 },{
1017 .type = CX88_VMUX_SVIDEO, 1022 .type = CX88_VMUX_SVIDEO,
1018 .vmux = 2, 1023 .vmux = 2,
1024 /* 2: Line-In */
1025 .audioroute = 2,
1019 }}, 1026 }},
1020 .mpeg = CX88_MPEG_DVB, 1027 .mpeg = CX88_MPEG_DVB,
1021 }, 1028 },
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 62cea9549404..d9249e5a04c9 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -40,7 +40,6 @@
40#include "cx88.h" 40#include "cx88.h"
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h> 42#include <media/v4l2-ioctl.h>
43#include <media/wm8775.h>
44 43
45MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards"); 44MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
46MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 45MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
@@ -977,7 +976,6 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
977 const struct cx88_ctrl *c = NULL; 976 const struct cx88_ctrl *c = NULL;
978 u32 value,mask; 977 u32 value,mask;
979 int i; 978 int i;
980 struct v4l2_control client_ctl;
981 979
982 for (i = 0; i < CX8800_CTLS; i++) { 980 for (i = 0; i < CX8800_CTLS; i++) {
983 if (cx8800_ctls[i].v.id == ctl->id) { 981 if (cx8800_ctls[i].v.id == ctl->id) {
@@ -991,27 +989,6 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
991 ctl->value = c->v.minimum; 989 ctl->value = c->v.minimum;
992 if (ctl->value > c->v.maximum) 990 if (ctl->value > c->v.maximum)
993 ctl->value = c->v.maximum; 991 ctl->value = c->v.maximum;
994
995 /* Pass changes onto any WM8775 */
996 client_ctl.id = ctl->id;
997 switch (ctl->id) {
998 case V4L2_CID_AUDIO_MUTE:
999 client_ctl.value = ctl->value;
1000 break;
1001 case V4L2_CID_AUDIO_VOLUME:
1002 client_ctl.value = (ctl->value) ?
1003 (0x90 + ctl->value) << 8 : 0;
1004 break;
1005 case V4L2_CID_AUDIO_BALANCE:
1006 client_ctl.value = ctl->value << 9;
1007 break;
1008 default:
1009 client_ctl.id = 0;
1010 break;
1011 }
1012 if (client_ctl.id)
1013 call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
1014
1015 mask=c->mask; 992 mask=c->mask;
1016 switch (ctl->id) { 993 switch (ctl->id) {
1017 case V4L2_CID_AUDIO_BALANCE: 994 case V4L2_CID_AUDIO_BALANCE:
@@ -1558,9 +1535,7 @@ static int radio_queryctrl (struct file *file, void *priv,
1558 if (c->id < V4L2_CID_BASE || 1535 if (c->id < V4L2_CID_BASE ||
1559 c->id >= V4L2_CID_LASTP1) 1536 c->id >= V4L2_CID_LASTP1)
1560 return -EINVAL; 1537 return -EINVAL;
1561 if (c->id == V4L2_CID_AUDIO_MUTE || 1538 if (c->id == V4L2_CID_AUDIO_MUTE) {
1562 c->id == V4L2_CID_AUDIO_VOLUME ||
1563 c->id == V4L2_CID_AUDIO_BALANCE) {
1564 for (i = 0; i < CX8800_CTLS; i++) { 1539 for (i = 0; i < CX8800_CTLS; i++) {
1565 if (cx8800_ctls[i].v.id == c->id) 1540 if (cx8800_ctls[i].v.id == c->id)
1566 break; 1541 break;
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index e8c732e7ae4f..c9981e77416a 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -398,19 +398,17 @@ static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
398 return container_of(v4l2_dev, struct cx88_core, v4l2_dev); 398 return container_of(v4l2_dev, struct cx88_core, v4l2_dev);
399} 399}
400 400
401#define call_hw(core, grpid, o, f, args...) \ 401#define call_all(core, o, f, args...) \
402 do { \ 402 do { \
403 if (!core->i2c_rc) { \ 403 if (!core->i2c_rc) { \
404 if (core->gate_ctrl) \ 404 if (core->gate_ctrl) \
405 core->gate_ctrl(core, 1); \ 405 core->gate_ctrl(core, 1); \
406 v4l2_device_call_all(&core->v4l2_dev, grpid, o, f, ##args); \ 406 v4l2_device_call_all(&core->v4l2_dev, 0, o, f, ##args); \
407 if (core->gate_ctrl) \ 407 if (core->gate_ctrl) \
408 core->gate_ctrl(core, 0); \ 408 core->gate_ctrl(core, 0); \
409 } \ 409 } \
410 } while (0) 410 } while (0)
411 411
412#define call_all(core, o, f, args...) call_hw(core, 0, o, f, ##args)
413
414struct cx8800_dev; 412struct cx8800_dev;
415struct cx8802_dev; 413struct cx8802_dev;
416 414
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 908e3bc88303..2c3007280032 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -2377,7 +2377,7 @@ static const struct v4l2_file_operations radio_fops = {
2377 .owner = THIS_MODULE, 2377 .owner = THIS_MODULE,
2378 .open = em28xx_v4l2_open, 2378 .open = em28xx_v4l2_open,
2379 .release = em28xx_v4l2_close, 2379 .release = em28xx_v4l2_close,
2380 .ioctl = video_ioctl2, 2380 .unlocked_ioctl = video_ioctl2,
2381}; 2381};
2382 2382
2383static const struct v4l2_ioctl_ops radio_ioctl_ops = { 2383static const struct v4l2_ioctl_ops radio_ioctl_ops = {
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 072bd2d1cfad..13565cba237d 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -807,8 +807,6 @@ static int mx2_camera_set_bus_param(struct soc_camera_device *icd,
807 807
808 if (common_flags & SOCAM_PCLK_SAMPLE_RISING) 808 if (common_flags & SOCAM_PCLK_SAMPLE_RISING)
809 csicr1 |= CSICR1_REDGE; 809 csicr1 |= CSICR1_REDGE;
810 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
811 csicr1 |= CSICR1_INV_PCLK;
812 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH) 810 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH)
813 csicr1 |= CSICR1_SOF_POL; 811 csicr1 |= CSICR1_SOF_POL;
814 if (common_flags & SOCAM_HSYNC_ACTIVE_HIGH) 812 if (common_flags & SOCAM_HSYNC_ACTIVE_HIGH)
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c
index 1b93207c89e8..2f500809f53d 100644
--- a/drivers/media/video/s5p-fimc/fimc-capture.c
+++ b/drivers/media/video/s5p-fimc/fimc-capture.c
@@ -522,6 +522,7 @@ static int fimc_cap_streamon(struct file *file, void *priv,
522 INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q); 522 INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q);
523 fimc->vid_cap.active_buf_cnt = 0; 523 fimc->vid_cap.active_buf_cnt = 0;
524 fimc->vid_cap.frame_count = 0; 524 fimc->vid_cap.frame_count = 0;
525 fimc->vid_cap.buf_index = fimc_hw_get_frame_index(fimc);
525 526
526 set_bit(ST_CAPT_PEND, &fimc->state); 527 set_bit(ST_CAPT_PEND, &fimc->state);
527 ret = videobuf_streamon(&fimc->vid_cap.vbq); 528 ret = videobuf_streamon(&fimc->vid_cap.vbq);
@@ -652,6 +653,50 @@ static int fimc_cap_s_ctrl(struct file *file, void *priv,
652 return ret; 653 return ret;
653} 654}
654 655
656static int fimc_cap_cropcap(struct file *file, void *fh,
657 struct v4l2_cropcap *cr)
658{
659 struct fimc_frame *f;
660 struct fimc_ctx *ctx = fh;
661 struct fimc_dev *fimc = ctx->fimc_dev;
662
663 if (cr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
664 return -EINVAL;
665
666 if (mutex_lock_interruptible(&fimc->lock))
667 return -ERESTARTSYS;
668
669 f = &ctx->s_frame;
670 cr->bounds.left = 0;
671 cr->bounds.top = 0;
672 cr->bounds.width = f->o_width;
673 cr->bounds.height = f->o_height;
674 cr->defrect = cr->bounds;
675
676 mutex_unlock(&fimc->lock);
677 return 0;
678}
679
680static int fimc_cap_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
681{
682 struct fimc_frame *f;
683 struct fimc_ctx *ctx = file->private_data;
684 struct fimc_dev *fimc = ctx->fimc_dev;
685
686
687 if (mutex_lock_interruptible(&fimc->lock))
688 return -ERESTARTSYS;
689
690 f = &ctx->s_frame;
691 cr->c.left = f->offs_h;
692 cr->c.top = f->offs_v;
693 cr->c.width = f->width;
694 cr->c.height = f->height;
695
696 mutex_unlock(&fimc->lock);
697 return 0;
698}
699
655static int fimc_cap_s_crop(struct file *file, void *fh, 700static int fimc_cap_s_crop(struct file *file, void *fh,
656 struct v4l2_crop *cr) 701 struct v4l2_crop *cr)
657{ 702{
@@ -716,9 +761,9 @@ static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = {
716 .vidioc_g_ctrl = fimc_vidioc_g_ctrl, 761 .vidioc_g_ctrl = fimc_vidioc_g_ctrl,
717 .vidioc_s_ctrl = fimc_cap_s_ctrl, 762 .vidioc_s_ctrl = fimc_cap_s_ctrl,
718 763
719 .vidioc_g_crop = fimc_vidioc_g_crop, 764 .vidioc_g_crop = fimc_cap_g_crop,
720 .vidioc_s_crop = fimc_cap_s_crop, 765 .vidioc_s_crop = fimc_cap_s_crop,
721 .vidioc_cropcap = fimc_vidioc_cropcap, 766 .vidioc_cropcap = fimc_cap_cropcap,
722 767
723 .vidioc_enum_input = fimc_cap_enum_input, 768 .vidioc_enum_input = fimc_cap_enum_input,
724 .vidioc_s_input = fimc_cap_s_input, 769 .vidioc_s_input = fimc_cap_s_input,
@@ -785,7 +830,7 @@ int fimc_register_capture_device(struct fimc_dev *fimc)
785 videobuf_queue_dma_contig_init(&vid_cap->vbq, &fimc_qops, 830 videobuf_queue_dma_contig_init(&vid_cap->vbq, &fimc_qops,
786 vid_cap->v4l2_dev.dev, &fimc->irqlock, 831 vid_cap->v4l2_dev.dev, &fimc->irqlock,
787 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 832 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
788 sizeof(struct fimc_vid_buffer), (void *)ctx); 833 sizeof(struct fimc_vid_buffer), (void *)ctx, NULL);
789 834
790 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1); 835 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
791 if (ret) { 836 if (ret) {
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
index 2e7c547894b6..bb99f2d805d3 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.c
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -50,8 +50,8 @@ static struct fimc_fmt fimc_formats[] = {
50 .planes_cnt = 1, 50 .planes_cnt = 1,
51 .flags = FMT_FLAGS_M2M, 51 .flags = FMT_FLAGS_M2M,
52 }, { 52 }, {
53 .name = "XRGB-8-8-8-8, 24 bpp", 53 .name = "XRGB-8-8-8-8, 32 bpp",
54 .fourcc = V4L2_PIX_FMT_RGB24, 54 .fourcc = V4L2_PIX_FMT_RGB32,
55 .depth = 32, 55 .depth = 32,
56 .color = S5P_FIMC_RGB888, 56 .color = S5P_FIMC_RGB888,
57 .buff_cnt = 1, 57 .buff_cnt = 1,
@@ -983,6 +983,7 @@ int fimc_vidioc_queryctrl(struct file *file, void *priv,
983{ 983{
984 struct fimc_ctx *ctx = priv; 984 struct fimc_ctx *ctx = priv;
985 struct v4l2_queryctrl *c; 985 struct v4l2_queryctrl *c;
986 int ret = -EINVAL;
986 987
987 c = get_ctrl(qc->id); 988 c = get_ctrl(qc->id);
988 if (c) { 989 if (c) {
@@ -990,10 +991,14 @@ int fimc_vidioc_queryctrl(struct file *file, void *priv,
990 return 0; 991 return 0;
991 } 992 }
992 993
993 if (ctx->state & FIMC_CTX_CAP) 994 if (ctx->state & FIMC_CTX_CAP) {
994 return v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd, 995 if (mutex_lock_interruptible(&ctx->fimc_dev->lock))
996 return -ERESTARTSYS;
997 ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd,
995 core, queryctrl, qc); 998 core, queryctrl, qc);
996 return -EINVAL; 999 mutex_unlock(&ctx->fimc_dev->lock);
1000 }
1001 return ret;
997} 1002}
998 1003
999int fimc_vidioc_g_ctrl(struct file *file, void *priv, 1004int fimc_vidioc_g_ctrl(struct file *file, void *priv,
@@ -1115,7 +1120,7 @@ static int fimc_m2m_s_ctrl(struct file *file, void *priv,
1115 return 0; 1120 return 0;
1116} 1121}
1117 1122
1118int fimc_vidioc_cropcap(struct file *file, void *fh, 1123static int fimc_m2m_cropcap(struct file *file, void *fh,
1119 struct v4l2_cropcap *cr) 1124 struct v4l2_cropcap *cr)
1120{ 1125{
1121 struct fimc_frame *frame; 1126 struct fimc_frame *frame;
@@ -1139,7 +1144,7 @@ int fimc_vidioc_cropcap(struct file *file, void *fh,
1139 return 0; 1144 return 0;
1140} 1145}
1141 1146
1142int fimc_vidioc_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) 1147static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1143{ 1148{
1144 struct fimc_frame *frame; 1149 struct fimc_frame *frame;
1145 struct fimc_ctx *ctx = file->private_data; 1150 struct fimc_ctx *ctx = file->private_data;
@@ -1167,22 +1172,22 @@ int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
1167 struct fimc_frame *f; 1172 struct fimc_frame *f;
1168 u32 min_size, halign; 1173 u32 min_size, halign;
1169 1174
1170 f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
1171 &ctx->s_frame : &ctx->d_frame;
1172
1173 if (cr->c.top < 0 || cr->c.left < 0) { 1175 if (cr->c.top < 0 || cr->c.left < 0) {
1174 v4l2_err(&fimc->m2m.v4l2_dev, 1176 v4l2_err(&fimc->m2m.v4l2_dev,
1175 "doesn't support negative values for top & left\n"); 1177 "doesn't support negative values for top & left\n");
1176 return -EINVAL; 1178 return -EINVAL;
1177 } 1179 }
1178 1180
1179 f = ctx_get_frame(ctx, cr->type); 1181 if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1180 if (IS_ERR(f)) 1182 f = (ctx->state & FIMC_CTX_CAP) ? &ctx->s_frame : &ctx->d_frame;
1181 return PTR_ERR(f); 1183 else if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
1184 ctx->state & FIMC_CTX_M2M)
1185 f = &ctx->s_frame;
1186 else
1187 return -EINVAL;
1182 1188
1183 min_size = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) 1189 min_size = (f == &ctx->s_frame) ?
1184 ? fimc->variant->min_inp_pixsize 1190 fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
1185 : fimc->variant->min_out_pixsize;
1186 1191
1187 if (ctx->state & FIMC_CTX_M2M) { 1192 if (ctx->state & FIMC_CTX_M2M) {
1188 if (fimc->id == 1 && fimc->variant->pix_hoff) 1193 if (fimc->id == 1 && fimc->variant->pix_hoff)
@@ -1233,6 +1238,9 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1233 f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ? 1238 f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
1234 &ctx->s_frame : &ctx->d_frame; 1239 &ctx->s_frame : &ctx->d_frame;
1235 1240
1241 if (mutex_lock_interruptible(&fimc->lock))
1242 return -ERESTARTSYS;
1243
1236 spin_lock_irqsave(&ctx->slock, flags); 1244 spin_lock_irqsave(&ctx->slock, flags);
1237 if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) { 1245 if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) {
1238 /* Check to see if scaling ratio is within supported range */ 1246 /* Check to see if scaling ratio is within supported range */
@@ -1241,9 +1249,9 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1241 else 1249 else
1242 ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame); 1250 ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
1243 if (ret) { 1251 if (ret) {
1244 spin_unlock_irqrestore(&ctx->slock, flags);
1245 v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range"); 1252 v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
1246 return -EINVAL; 1253 ret = -EINVAL;
1254 goto scr_unlock;
1247 } 1255 }
1248 } 1256 }
1249 ctx->state |= FIMC_PARAMS; 1257 ctx->state |= FIMC_PARAMS;
@@ -1253,7 +1261,9 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1253 f->width = cr->c.width; 1261 f->width = cr->c.width;
1254 f->height = cr->c.height; 1262 f->height = cr->c.height;
1255 1263
1264scr_unlock:
1256 spin_unlock_irqrestore(&ctx->slock, flags); 1265 spin_unlock_irqrestore(&ctx->slock, flags);
1266 mutex_unlock(&fimc->lock);
1257 return 0; 1267 return 0;
1258} 1268}
1259 1269
@@ -1285,9 +1295,9 @@ static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
1285 .vidioc_g_ctrl = fimc_vidioc_g_ctrl, 1295 .vidioc_g_ctrl = fimc_vidioc_g_ctrl,
1286 .vidioc_s_ctrl = fimc_m2m_s_ctrl, 1296 .vidioc_s_ctrl = fimc_m2m_s_ctrl,
1287 1297
1288 .vidioc_g_crop = fimc_vidioc_g_crop, 1298 .vidioc_g_crop = fimc_m2m_g_crop,
1289 .vidioc_s_crop = fimc_m2m_s_crop, 1299 .vidioc_s_crop = fimc_m2m_s_crop,
1290 .vidioc_cropcap = fimc_vidioc_cropcap 1300 .vidioc_cropcap = fimc_m2m_cropcap
1291 1301
1292}; 1302};
1293 1303
@@ -1396,7 +1406,7 @@ static const struct v4l2_file_operations fimc_m2m_fops = {
1396 .open = fimc_m2m_open, 1406 .open = fimc_m2m_open,
1397 .release = fimc_m2m_release, 1407 .release = fimc_m2m_release,
1398 .poll = fimc_m2m_poll, 1408 .poll = fimc_m2m_poll,
1399 .ioctl = video_ioctl2, 1409 .unlocked_ioctl = video_ioctl2,
1400 .mmap = fimc_m2m_mmap, 1410 .mmap = fimc_m2m_mmap,
1401}; 1411};
1402 1412
@@ -1736,6 +1746,7 @@ static struct samsung_fimc_variant fimc0_variant_s5pv310 = {
1736 .pix_hoff = 1, 1746 .pix_hoff = 1,
1737 .has_inp_rot = 1, 1747 .has_inp_rot = 1,
1738 .has_out_rot = 1, 1748 .has_out_rot = 1,
1749 .has_cistatus2 = 1,
1739 .min_inp_pixsize = 16, 1750 .min_inp_pixsize = 16,
1740 .min_out_pixsize = 16, 1751 .min_out_pixsize = 16,
1741 .hor_offs_align = 1, 1752 .hor_offs_align = 1,
@@ -1745,6 +1756,7 @@ static struct samsung_fimc_variant fimc0_variant_s5pv310 = {
1745 1756
1746static struct samsung_fimc_variant fimc2_variant_s5pv310 = { 1757static struct samsung_fimc_variant fimc2_variant_s5pv310 = {
1747 .pix_hoff = 1, 1758 .pix_hoff = 1,
1759 .has_cistatus2 = 1,
1748 .min_inp_pixsize = 16, 1760 .min_inp_pixsize = 16,
1749 .min_out_pixsize = 16, 1761 .min_out_pixsize = 16,
1750 .hor_offs_align = 1, 1762 .hor_offs_align = 1,
diff --git a/drivers/media/video/s5p-fimc/fimc-core.h b/drivers/media/video/s5p-fimc/fimc-core.h
index 3e1078516560..4f047d35f8ad 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.h
+++ b/drivers/media/video/s5p-fimc/fimc-core.h
@@ -13,13 +13,15 @@
13 13
14/*#define DEBUG*/ 14/*#define DEBUG*/
15 15
16#include <linux/sched.h>
16#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/videodev2.h>
17#include <media/videobuf-core.h> 19#include <media/videobuf-core.h>
18#include <media/v4l2-device.h> 20#include <media/v4l2-device.h>
19#include <media/v4l2-mem2mem.h> 21#include <media/v4l2-mem2mem.h>
20#include <media/v4l2-mediabus.h> 22#include <media/v4l2-mediabus.h>
21#include <media/s3c_fimc.h> 23#include <media/s3c_fimc.h>
22#include <linux/videodev2.h> 24
23#include "regs-fimc.h" 25#include "regs-fimc.h"
24 26
25#define err(fmt, args...) \ 27#define err(fmt, args...) \
@@ -369,6 +371,7 @@ struct fimc_pix_limit {
369 * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes 371 * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
370 * @has_inp_rot: set if has input rotator 372 * @has_inp_rot: set if has input rotator
371 * @has_out_rot: set if has output rotator 373 * @has_out_rot: set if has output rotator
374 * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision
372 * @pix_limit: pixel size constraints for the scaler 375 * @pix_limit: pixel size constraints for the scaler
373 * @min_inp_pixsize: minimum input pixel size 376 * @min_inp_pixsize: minimum input pixel size
374 * @min_out_pixsize: minimum output pixel size 377 * @min_out_pixsize: minimum output pixel size
@@ -379,6 +382,7 @@ struct samsung_fimc_variant {
379 unsigned int pix_hoff:1; 382 unsigned int pix_hoff:1;
380 unsigned int has_inp_rot:1; 383 unsigned int has_inp_rot:1;
381 unsigned int has_out_rot:1; 384 unsigned int has_out_rot:1;
385 unsigned int has_cistatus2:1;
382 struct fimc_pix_limit *pix_limit; 386 struct fimc_pix_limit *pix_limit;
383 u16 min_inp_pixsize; 387 u16 min_inp_pixsize;
384 u16 min_out_pixsize; 388 u16 min_out_pixsize;
@@ -554,11 +558,19 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
554 return frame; 558 return frame;
555} 559}
556 560
561/* Return an index to the buffer actually being written. */
557static inline u32 fimc_hw_get_frame_index(struct fimc_dev *dev) 562static inline u32 fimc_hw_get_frame_index(struct fimc_dev *dev)
558{ 563{
559 u32 reg = readl(dev->regs + S5P_CISTATUS); 564 u32 reg;
560 return (reg & S5P_CISTATUS_FRAMECNT_MASK) >> 565
561 S5P_CISTATUS_FRAMECNT_SHIFT; 566 if (dev->variant->has_cistatus2) {
567 reg = readl(dev->regs + S5P_CISTATUS2) & 0x3F;
568 return reg > 0 ? --reg : reg;
569 } else {
570 reg = readl(dev->regs + S5P_CISTATUS);
571 return (reg & S5P_CISTATUS_FRAMECNT_MASK) >>
572 S5P_CISTATUS_FRAMECNT_SHIFT;
573 }
562} 574}
563 575
564/* -----------------------------------------------------*/ 576/* -----------------------------------------------------*/
@@ -594,10 +606,6 @@ int fimc_vidioc_g_fmt(struct file *file, void *priv,
594 struct v4l2_format *f); 606 struct v4l2_format *f);
595int fimc_vidioc_try_fmt(struct file *file, void *priv, 607int fimc_vidioc_try_fmt(struct file *file, void *priv,
596 struct v4l2_format *f); 608 struct v4l2_format *f);
597int fimc_vidioc_g_crop(struct file *file, void *fh,
598 struct v4l2_crop *cr);
599int fimc_vidioc_cropcap(struct file *file, void *fh,
600 struct v4l2_cropcap *cr);
601int fimc_vidioc_queryctrl(struct file *file, void *priv, 609int fimc_vidioc_queryctrl(struct file *file, void *priv,
602 struct v4l2_queryctrl *qc); 610 struct v4l2_queryctrl *qc);
603int fimc_vidioc_g_ctrl(struct file *file, void *priv, 611int fimc_vidioc_g_ctrl(struct file *file, void *priv,
diff --git a/drivers/media/video/s5p-fimc/regs-fimc.h b/drivers/media/video/s5p-fimc/regs-fimc.h
index a57daedb5b5c..57e33f84fcfa 100644
--- a/drivers/media/video/s5p-fimc/regs-fimc.h
+++ b/drivers/media/video/s5p-fimc/regs-fimc.h
@@ -165,6 +165,9 @@
165#define S5P_CISTATUS_VVALID_A (1 << 15) 165#define S5P_CISTATUS_VVALID_A (1 << 15)
166#define S5P_CISTATUS_VVALID_B (1 << 14) 166#define S5P_CISTATUS_VVALID_B (1 << 14)
167 167
168/* Indexes to the last and the currently processed buffer. */
169#define S5P_CISTATUS2 0x68
170
168/* Image capture control */ 171/* Image capture control */
169#define S5P_CIIMGCPT 0xc0 172#define S5P_CIIMGCPT 0xc0
170#define S5P_CIIMGCPT_IMGCPTEN (1 << 31) 173#define S5P_CIIMGCPT_IMGCPTEN (1 << 31)
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index 5c209afb0ac8..2486520582f2 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -1980,7 +1980,7 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
1980 * we complete the completion. 1980 * we complete the completion.
1981 */ 1981 */
1982 1982
1983 if (!csi2->driver || !csi2->driver->owner) { 1983 if (!csi2->driver) {
1984 complete(&wait.completion); 1984 complete(&wait.completion);
1985 /* Either too late, or probing failed */ 1985 /* Either too late, or probing failed */
1986 bus_unregister_notifier(&platform_bus_type, &wait.notifier); 1986 bus_unregister_notifier(&platform_bus_type, &wait.notifier);
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 335120c2021b..052bd6dfa5a7 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -405,13 +405,13 @@ static int soc_camera_open(struct file *file)
405 ret = soc_camera_set_fmt(icd, &f); 405 ret = soc_camera_set_fmt(icd, &f);
406 if (ret < 0) 406 if (ret < 0)
407 goto esfmt; 407 goto esfmt;
408
409 ici->ops->init_videobuf(&icd->vb_vidq, icd);
408 } 410 }
409 411
410 file->private_data = icd; 412 file->private_data = icd;
411 dev_dbg(&icd->dev, "camera device open\n"); 413 dev_dbg(&icd->dev, "camera device open\n");
412 414
413 ici->ops->init_videobuf(&icd->vb_vidq, icd);
414
415 mutex_unlock(&icd->video_lock); 415 mutex_unlock(&icd->video_lock);
416 416
417 return 0; 417 return 0;
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 135525649086..fe8ef6419f83 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -35,7 +35,6 @@
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h> 36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-ctrls.h> 37#include <media/v4l2-ctrls.h>
38#include <media/wm8775.h>
39 38
40MODULE_DESCRIPTION("wm8775 driver"); 39MODULE_DESCRIPTION("wm8775 driver");
41MODULE_AUTHOR("Ulf Eklund, Hans Verkuil"); 40MODULE_AUTHOR("Ulf Eklund, Hans Verkuil");
@@ -51,16 +50,10 @@ enum {
51 TOT_REGS 50 TOT_REGS
52}; 51};
53 52
54#define ALC_HOLD 0x85 /* R17: use zero cross detection, ALC hold time 42.6 ms */
55#define ALC_EN 0x100 /* R17: ALC enable */
56
57struct wm8775_state { 53struct wm8775_state {
58 struct v4l2_subdev sd; 54 struct v4l2_subdev sd;
59 struct v4l2_ctrl_handler hdl; 55 struct v4l2_ctrl_handler hdl;
60 struct v4l2_ctrl *mute; 56 struct v4l2_ctrl *mute;
61 struct v4l2_ctrl *vol;
62 struct v4l2_ctrl *bal;
63 struct v4l2_ctrl *loud;
64 u8 input; /* Last selected input (0-0xf) */ 57 u8 input; /* Last selected input (0-0xf) */
65}; 58};
66 59
@@ -92,30 +85,6 @@ static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val)
92 return -1; 85 return -1;
93} 86}
94 87
95static void wm8775_set_audio(struct v4l2_subdev *sd, int quietly)
96{
97 struct wm8775_state *state = to_state(sd);
98 u8 vol_l, vol_r;
99 int muted = 0 != state->mute->val;
100 u16 volume = (u16)state->vol->val;
101 u16 balance = (u16)state->bal->val;
102
103 /* normalize ( 65535 to 0 -> 255 to 0 (+24dB to -103dB) ) */
104 vol_l = (min(65536 - balance, 32768) * volume) >> 23;
105 vol_r = (min(balance, (u16)32768) * volume) >> 23;
106
107 /* Mute */
108 if (muted || quietly)
109 wm8775_write(sd, R21, 0x0c0 | state->input);
110
111 wm8775_write(sd, R14, vol_l | 0x100); /* 0x100= Left channel ADC zero cross enable */
112 wm8775_write(sd, R15, vol_r | 0x100); /* 0x100= Right channel ADC zero cross enable */
113
114 /* Un-mute */
115 if (!muted)
116 wm8775_write(sd, R21, state->input);
117}
118
119static int wm8775_s_routing(struct v4l2_subdev *sd, 88static int wm8775_s_routing(struct v4l2_subdev *sd,
120 u32 input, u32 output, u32 config) 89 u32 input, u32 output, u32 config)
121{ 90{
@@ -133,26 +102,25 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
133 state->input = input; 102 state->input = input;
134 if (!v4l2_ctrl_g_ctrl(state->mute)) 103 if (!v4l2_ctrl_g_ctrl(state->mute))
135 return 0; 104 return 0;
136 if (!v4l2_ctrl_g_ctrl(state->vol)) 105 wm8775_write(sd, R21, 0x0c0);
137 return 0; 106 wm8775_write(sd, R14, 0x1d4);
138 if (!v4l2_ctrl_g_ctrl(state->bal)) 107 wm8775_write(sd, R15, 0x1d4);
139 return 0; 108 wm8775_write(sd, R21, 0x100 + state->input);
140 wm8775_set_audio(sd, 1);
141 return 0; 109 return 0;
142} 110}
143 111
144static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl) 112static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl)
145{ 113{
146 struct v4l2_subdev *sd = to_sd(ctrl); 114 struct v4l2_subdev *sd = to_sd(ctrl);
115 struct wm8775_state *state = to_state(sd);
147 116
148 switch (ctrl->id) { 117 switch (ctrl->id) {
149 case V4L2_CID_AUDIO_MUTE: 118 case V4L2_CID_AUDIO_MUTE:
150 case V4L2_CID_AUDIO_VOLUME: 119 wm8775_write(sd, R21, 0x0c0);
151 case V4L2_CID_AUDIO_BALANCE: 120 wm8775_write(sd, R14, 0x1d4);
152 wm8775_set_audio(sd, 0); 121 wm8775_write(sd, R15, 0x1d4);
153 return 0; 122 if (!ctrl->val)
154 case V4L2_CID_AUDIO_LOUDNESS: 123 wm8775_write(sd, R21, 0x100 + state->input);
155 wm8775_write(sd, R17, (ctrl->val ? ALC_EN : 0) | ALC_HOLD);
156 return 0; 124 return 0;
157 } 125 }
158 return -EINVAL; 126 return -EINVAL;
@@ -176,7 +144,16 @@ static int wm8775_log_status(struct v4l2_subdev *sd)
176 144
177static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) 145static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq)
178{ 146{
179 wm8775_set_audio(sd, 0); 147 struct wm8775_state *state = to_state(sd);
148
149 /* If I remove this, then it can happen that I have no
150 sound the first time I tune from static to a valid channel.
151 It's difficult to reproduce and is almost certainly related
152 to the zero cross detect circuit. */
153 wm8775_write(sd, R21, 0x0c0);
154 wm8775_write(sd, R14, 0x1d4);
155 wm8775_write(sd, R15, 0x1d4);
156 wm8775_write(sd, R21, 0x100 + state->input);
180 return 0; 157 return 0;
181} 158}
182 159
@@ -226,7 +203,6 @@ static int wm8775_probe(struct i2c_client *client,
226{ 203{
227 struct wm8775_state *state; 204 struct wm8775_state *state;
228 struct v4l2_subdev *sd; 205 struct v4l2_subdev *sd;
229 int err;
230 206
231 /* Check if the adapter supports the needed features */ 207 /* Check if the adapter supports the needed features */
232 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 208 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -240,21 +216,15 @@ static int wm8775_probe(struct i2c_client *client,
240 return -ENOMEM; 216 return -ENOMEM;
241 sd = &state->sd; 217 sd = &state->sd;
242 v4l2_i2c_subdev_init(sd, client, &wm8775_ops); 218 v4l2_i2c_subdev_init(sd, client, &wm8775_ops);
243 sd->grp_id = WM8775_GID; /* subdev group id */
244 state->input = 2; 219 state->input = 2;
245 220
246 v4l2_ctrl_handler_init(&state->hdl, 4); 221 v4l2_ctrl_handler_init(&state->hdl, 1);
247 state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops, 222 state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
248 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0); 223 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
249 state->vol = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
250 V4L2_CID_AUDIO_VOLUME, 0, 65535, (65535+99)/100, 0xCF00); /* 0dB*/
251 state->bal = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
252 V4L2_CID_AUDIO_BALANCE, 0, 65535, (65535+99)/100, 32768);
253 state->loud = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
254 V4L2_CID_AUDIO_LOUDNESS, 0, 1, 1, 1);
255 sd->ctrl_handler = &state->hdl; 224 sd->ctrl_handler = &state->hdl;
256 err = state->hdl.error; 225 if (state->hdl.error) {
257 if (err) { 226 int err = state->hdl.error;
227
258 v4l2_ctrl_handler_free(&state->hdl); 228 v4l2_ctrl_handler_free(&state->hdl);
259 kfree(state); 229 kfree(state);
260 return err; 230 return err;
@@ -266,25 +236,29 @@ static int wm8775_probe(struct i2c_client *client,
266 wm8775_write(sd, R23, 0x000); 236 wm8775_write(sd, R23, 0x000);
267 /* Disable zero cross detect timeout */ 237 /* Disable zero cross detect timeout */
268 wm8775_write(sd, R7, 0x000); 238 wm8775_write(sd, R7, 0x000);
269 /* HPF enable, I2S mode, 24-bit */ 239 /* Left justified, 24-bit mode */
270 wm8775_write(sd, R11, 0x022); 240 wm8775_write(sd, R11, 0x021);
271 /* Master mode, clock ratio 256fs */ 241 /* Master mode, clock ratio 256fs */
272 wm8775_write(sd, R12, 0x102); 242 wm8775_write(sd, R12, 0x102);
273 /* Powered up */ 243 /* Powered up */
274 wm8775_write(sd, R13, 0x000); 244 wm8775_write(sd, R13, 0x000);
275 /* ALC stereo, ALC target level -5dB FS, ALC max gain +8dB */ 245 /* ADC gain +2.5dB, enable zero cross */
276 wm8775_write(sd, R16, 0x1bb); 246 wm8775_write(sd, R14, 0x1d4);
277 /* Set ALC mode and hold time */ 247 /* ADC gain +2.5dB, enable zero cross */
278 wm8775_write(sd, R17, (state->loud->val ? ALC_EN : 0) | ALC_HOLD); 248 wm8775_write(sd, R15, 0x1d4);
249 /* ALC Stereo, ALC target level -1dB FS max gain +8dB */
250 wm8775_write(sd, R16, 0x1bf);
251 /* Enable gain control, use zero cross detection,
252 ALC hold time 42.6 ms */
253 wm8775_write(sd, R17, 0x185);
279 /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */ 254 /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */
280 wm8775_write(sd, R18, 0x0a2); 255 wm8775_write(sd, R18, 0x0a2);
281 /* Enable noise gate, threshold -72dBfs */ 256 /* Enable noise gate, threshold -72dBfs */
282 wm8775_write(sd, R19, 0x005); 257 wm8775_write(sd, R19, 0x005);
283 /* Transient window 4ms, ALC min gain -5dB */ 258 /* Transient window 4ms, lower PGA gain limit -1dB */
284 wm8775_write(sd, R20, 0x0fb); 259 wm8775_write(sd, R20, 0x07a);
285 260 /* LRBOTH = 1, use input 2. */
286 wm8775_set_audio(sd, 1); /* set volume/mute/mux */ 261 wm8775_write(sd, R21, 0x102);
287
288 return 0; 262 return 0;
289} 263}
290 264