V4L/DVB (5034): Pvrusb2: Enable radio mode round #1
authorPantelis Koukousoulas <pakt223@freemail.gr>
Thu, 28 Dec 2006 02:05:19 +0000 (23:05 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Wed, 21 Feb 2007 15:34:21 +0000 (13:34 -0200)
This is the logic that supports switching modes via e.g.,
  echo radio > /sys/class/pvrusb2/sn-*/ctl_input/cur_val.

To do the mode switching we need to:
a) broadcast AUDC_SET_RADIO and
b) issue the CX2341X_ENC_MUTE_VIDEO command to the encoder.

The first is done by adding a new pvr2_i2c_op and having it trigger on
input change, the second by adding this command in pvr2_encoder_start()
and requesting an encoder restart on input change by setting
stale_subsys_mask appropriately.

The clues about AUDC_SET_RADIO and CX2341X_ENC_MUTE_VIDEO were kindly
provided by Hans Verkuil on the pvrusb2 mailing list. The idea to
implement mode switching this way (on input change) is due to Mike Isely.

Why AUDC_SET_RADIO/VIDIOC_S_STD are used for switching? I can 't be sure,
but I think this can be traced to a cornell student being the first to
implement radio support in ivtv "as a different standard". I think the
rest just evolved from there (it 's in the ivtv ML archives).

Signed-off-by: Pantelis Koukousoulas <pakt223@freemail.gr>
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/video/pvrusb2/pvrusb2-encoder.c
drivers/media/video/pvrusb2/pvrusb2-hdw.c
drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h

index c94f97b7939246ff0dd61e6ad417f438861a621d..d094cac9f7a59cb37c349dd26f1acd9e26be1871 100644 (file)
@@ -360,6 +360,9 @@ int pvr2_encoder_start(struct pvr2_hdw *hdw)
        pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000481);
        pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000);
 
+       pvr2_encoder_vcmd(hdw,CX2341X_ENC_MUTE_VIDEO,1,
+                         hdw->input_val == PVR2_CVAL_INPUT_RADIO ? 1 : 0);
+
        if (hdw->config == pvr2_config_vbi) {
                status = pvr2_encoder_vcmd(hdw,CX2341X_ENC_START_CAPTURE,2,
                                           0x01,0x14);
index 503255cebc2e268828131b96db9f71d527c59434..5f6ab998bbe76ed5c0f9b1a590f978fe085bbb3f 100644 (file)
@@ -2260,6 +2260,13 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
                stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_CFG);
        }
 
+       if (hdw->input_dirty) {
+               /* pk: If input changes to or from radio, then the encoder
+                  needs to be restarted (for ENC_MUTE_VIDEO to work) */
+               stale_subsys_mask |= (1<<PVR2_SUBSYS_B_ENC_RUN);
+       }
+
+
        if (hdw->srate_dirty) {
                /* Write new sample rate into control structure since
                 * the master copy is stale.  We must track srate
index 05121666b9ba5c6a516dcf76023c7a4602ac8401..93b8d077c11e0b043703b612d30232ffc5f044dd 100644 (file)
@@ -39,6 +39,7 @@
 #define OP_AUDIORATE 4
 #define OP_SIZE 5
 #define OP_LOG 6
+#define OP_RADIO 7
 
 static const struct pvr2_i2c_op * const ops[] = {
        [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard,
@@ -47,6 +48,7 @@ static const struct pvr2_i2c_op * const ops[] = {
        [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency,
        [OP_SIZE] = &pvr2_i2c_op_v4l2_size,
        [OP_LOG] = &pvr2_i2c_op_v4l2_log,
+       [OP_RADIO] = &pvr2_i2c_op_v4l2_radio,
 };
 
 void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
@@ -58,7 +60,8 @@ void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
                        (1 << OP_VOLUME) |
                        (1 << OP_FREQ) |
                        (1 << OP_SIZE) |
-                       (1 << OP_LOG));
+                       (1 << OP_LOG) |
+                       (1 << OP_RADIO));
 
        if (id == I2C_DRIVERID_MSP3400) {
                if (pvr2_i2c_msp3400_setup(hdw,cp)) {
index 05ea17afe9037817567c710b4c06e3dae94ddc6b..50fcceb15d512220b89d964572fcd3a730119178 100644 (file)
@@ -24,7 +24,7 @@
 #include "pvrusb2-hdw-internal.h"
 #include "pvrusb2-debug.h"
 #include <linux/videodev2.h>
-
+#include <media/v4l2-common.h> /* AUDC_SET_RADIO */
 
 static void set_standard(struct pvr2_hdw *hdw)
 {
@@ -50,6 +50,32 @@ const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
 };
 
 
+static void set_radio(struct pvr2_hdw *hdw)
+{
+       pvr2_trace(PVR2_TRACE_CHIPS,
+                          "i2c v4l2 set_radio()");
+
+       if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
+               pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
+       } else {
+               set_standard(hdw);
+       }
+}
+
+
+static int check_radio(struct pvr2_hdw *hdw)
+{
+       return hdw->input_dirty != 0;
+}
+
+
+const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio = {
+       .check = check_radio,
+       .update = set_radio,
+       .name = "v4l2_radio",
+};
+
+
 static void set_bcsh(struct pvr2_hdw *hdw)
 {
        struct v4l2_control ctrl;
@@ -145,7 +171,8 @@ static void set_frequency(struct pvr2_hdw *hdw)
        memset(&freq,0,sizeof(freq));
        freq.frequency = fv / 62500;
        freq.tuner = 0;
-       freq.type = V4L2_TUNER_ANALOG_TV;
+       freq.type = (hdw->input_val == PVR2_CVAL_INPUT_RADIO) ?
+                    V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
        pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
 }
 
index ecabddba1ec50a1d0e9c675d22a4598f70fc1986..894de610893b6c808a8dc810a5916e06e0f060e8 100644 (file)
@@ -26,6 +26,7 @@
 #include "pvrusb2-i2c-core.h"
 
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard;
+extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency;