V4L/DVB (11194): pvrusb2: Implement mechanism to force a full sub-device update
[safe/jmp/linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-hdw.c
index 1158021..1fb9ca5 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/firmware.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/tuner.h>
 #include "pvrusb2.h"
 #include "pvrusb2-std.h"
 #include "pvrusb2-util.h"
@@ -131,6 +132,8 @@ static const char *module_names[] = {
 
 static const unsigned char *module_i2c_addresses[] = {
        [PVR2_CLIENT_ID_TUNER] = "\x60\x61\x62\x63",
+       [PVR2_CLIENT_ID_WM8775] = "\x1b",
+       [PVR2_CLIENT_ID_CX25840] = "\x44",
 };
 
 
@@ -1678,6 +1681,8 @@ static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
           this point, we'll broadcast stream on/off to all sub-devices
           anyway, just in case somebody else wants to hear the
           command... */
+       pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s",
+                  (enablefl ? "on" : "off"));
        v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl);
        if (hdw->decoder_client_id) {
                /* We get here if the encoder has been noticed.  Otherwise
@@ -1978,7 +1983,7 @@ static unsigned int pvr2_copy_i2c_addr_list(
        unsigned short *dst, const unsigned char *src,
        unsigned int dst_max)
 {
-       unsigned int cnt;
+       unsigned int cnt = 0;
        if (!src) return 0;
        while (src[cnt] && (cnt + 1) < dst_max) {
                dst[cnt] = src[cnt];
@@ -2009,6 +2014,10 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
                           hdw->hdw_desc->description);
                return -EINVAL;
        }
+       pvr2_trace(PVR2_TRACE_INIT,
+                  "Module ID %u (%s) for device %s being loaded...",
+                  mid, fname,
+                  hdw->hdw_desc->description);
 
        i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, cd->i2c_address_list,
                                         ARRAY_SIZE(i2caddr));
@@ -2017,6 +2026,12 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
                /* Second chance: Try default i2c address list */
                i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, p,
                                                 ARRAY_SIZE(i2caddr));
+               if (i2ccnt) {
+                       pvr2_trace(PVR2_TRACE_INIT,
+                                  "Module ID %u:"
+                                  " Using default i2c address list",
+                                  mid);
+               }
        }
 
        if (!i2ccnt) {
@@ -2034,15 +2049,25 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
         * and every other place where I can find examples of this, the
         * "chipid" appears to just be the module name again.  So here we
         * just do the same thing. */
+       hdw->i2c_adap.class = 0;
        if (i2ccnt == 1) {
+               pvr2_trace(PVR2_TRACE_INIT,
+                          "Module ID %u:"
+                          " Setting up with specified i2c address 0x%x",
+                          mid, i2caddr[0]);
                sd = v4l2_i2c_new_subdev(&hdw->i2c_adap,
                                         fname, fname,
                                         i2caddr[0]);
        } else {
+               pvr2_trace(PVR2_TRACE_INIT,
+                          "Module ID %u:"
+                          " Setting up with address probe list",
+                          mid);
                sd = v4l2_i2c_new_probed_subdev(&hdw->i2c_adap,
                                                fname, fname,
                                                i2caddr);
        }
+       hdw->i2c_adap.class = I2C_CLASS_TV_ANALOG;
 
        if (!sd) {
                pvr2_trace(PVR2_TRACE_ERROR_LEGS,
@@ -2061,7 +2086,7 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
           aid, in normal situations there's no reason for both mechanisms
           to be enabled. */
        pvr2_i2c_untrack_subdev(hdw, sd);
-       pvr2_trace(PVR2_TRACE_INIT, "Attached sub-driver %s", fname);
+       pvr2_trace(PVR2_TRACE_INFO, "Attached sub-driver %s", fname);
 
 
        /* client-specific setup... */
@@ -2081,6 +2106,10 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
                          up.
                        */
                        struct v4l2_format fmt;
+                       pvr2_trace(PVR2_TRACE_INIT,
+                                  "Module ID %u:"
+                                  " Executing cx25840 VBI hack",
+                                  mid);
                        memset(&fmt, 0, sizeof(fmt));
                        fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
                        v4l2_device_call_all(&hdw->v4l2_dev, mid,
@@ -2111,7 +2140,7 @@ static void pvr2_hdw_load_modules(struct pvr2_hdw *hdw)
 
        ct = &hdw->hdw_desc->client_table;
        for (idx = 0; idx < ct->cnt; idx++) {
-               if (!pvr2_hdw_load_subdev(hdw, &ct->lst[idx])) okFl = 0;
+               if (pvr2_hdw_load_subdev(hdw, &ct->lst[idx]) < 0) okFl = 0;
        }
        if (!okFl) pvr2_hdw_render_useless(hdw);
 }
@@ -2156,6 +2185,8 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
 
        if (!pvr2_hdw_dev_ok(hdw)) return;
 
+       hdw->force_dirty = !0;
+
        if (!hdw->hdw_desc->flag_no_powerup) {
                pvr2_hdw_cmd_powerup(hdw);
                if (!pvr2_hdw_dev_ok(hdw)) return;
@@ -2236,7 +2267,6 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
        }
 
        pvr2_i2c_core_check_stale(hdw);
-       hdw->tuner_updated = 0;
 
        if (!pvr2_hdw_dev_ok(hdw)) return;
 
@@ -2907,7 +2937,7 @@ static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
 }
 
 #define PVR2_SUBDEV_SET_CONTROL(hdw, id, lab) \
-       if ((hdw)->lab##_dirty) { \
+       if ((hdw)->lab##_dirty || (hdw)->force_dirty) {         \
                pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
        }
 
@@ -2919,8 +2949,23 @@ static void pvr2_subdev_update(struct pvr2_hdw *hdw)
        unsigned int id;
        pvr2_subdev_update_func fp;
 
-       if (hdw->input_dirty || hdw->std_dirty) {
-               pvr2_trace(PVR2_TRACE_CHIPS,"subdev v4l2 set_standard");
+       pvr2_trace(PVR2_TRACE_CHIPS, "subdev update...");
+
+       if (hdw->tuner_updated || hdw->force_dirty) {
+               struct tuner_setup setup;
+               pvr2_trace(PVR2_TRACE_CHIPS, "subdev tuner set_type(%d)",
+                          hdw->tuner_type);
+               if (((int)(hdw->tuner_type)) >= 0) {
+                       setup.addr = ADDR_UNSET;
+                       setup.type = hdw->tuner_type;
+                       setup.mode_mask = T_RADIO | T_ANALOG_TV;
+                       v4l2_device_call_all(&hdw->v4l2_dev, 0,
+                                            tuner, s_type_addr, &setup);
+               }
+       }
+
+       if (hdw->input_dirty || hdw->std_dirty || hdw->force_dirty) {
+               pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_standard");
                if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
                        v4l2_device_call_all(&hdw->v4l2_dev, 0,
                                             tuner, s_radio);
@@ -2944,14 +2989,14 @@ static void pvr2_subdev_update(struct pvr2_hdw *hdw)
        PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BASS, bass);
        PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_TREBLE, treble);
 
-       if (hdw->input_dirty || hdw->audiomode_dirty) {
+       if (hdw->input_dirty || hdw->audiomode_dirty || hdw->force_dirty) {
                struct v4l2_tuner vt;
                memset(&vt, 0, sizeof(vt));
                vt.audmode = hdw->audiomode_val;
                v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, s_tuner, &vt);
        }
 
-       if (hdw->freqDirty) {
+       if (hdw->freqDirty || hdw->force_dirty) {
                unsigned long fv;
                struct v4l2_frequency freq;
                fv = pvr2_hdw_get_cur_freq(hdw);
@@ -2976,7 +3021,7 @@ static void pvr2_subdev_update(struct pvr2_hdw *hdw)
                                     s_frequency, &freq);
        }
 
-       if (hdw->res_hor_dirty || hdw->res_ver_dirty) {
+       if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->force_dirty) {
                struct v4l2_format fmt;
                memset(&fmt, 0, sizeof(fmt));
                fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -2987,7 +3032,7 @@ static void pvr2_subdev_update(struct pvr2_hdw *hdw)
                v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_fmt, &fmt);
        }
 
-       if (hdw->srate_dirty) {
+       if (hdw->srate_dirty || hdw->force_dirty) {
                u32 val;
                pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_audio %d",
                           hdw->srate_val);
@@ -3018,7 +3063,7 @@ static void pvr2_subdev_update(struct pvr2_hdw *hdw)
                (*fp)(hdw, sd);
        }
 
-       if (hdw->tuner_signal_stale && hdw->cropcap_stale) {
+       if (hdw->tuner_signal_stale || hdw->cropcap_stale) {
                pvr2_hdw_status_poll(hdw);
        }
 }
@@ -3032,7 +3077,7 @@ static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw)
        unsigned int idx;
        struct pvr2_ctrl *cptr;
        int value;
-       int commit_flag = 0;
+       int commit_flag = hdw->force_dirty;
        char buf[100];
        unsigned int bcnt,ccnt;
 
@@ -3213,15 +3258,17 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
                }
        }
 
+       /* Check and update state for all sub-devices. */
+       pvr2_subdev_update(hdw);
+
+       hdw->tuner_updated = 0;
+       hdw->force_dirty = 0;
        for (idx = 0; idx < hdw->control_cnt; idx++) {
                cptr = hdw->controls + idx;
                if (!cptr->info->clear_dirty) continue;
                cptr->info->clear_dirty(cptr);
        }
 
-       /* Check and update state for all sub-devices. */
-       pvr2_subdev_update(hdw);
-
        /* Now execute i2c core update */
        pvr2_i2c_core_sync(hdw);
 
@@ -4832,7 +4879,7 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
                unsigned int id;
                ccnt = scnprintf(buf,
                                 acnt,
-                                "Associted v4l2_subdev drivers:");
+                                "Associated v4l2_subdev drivers:");
                tcnt += ccnt;
                v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
                        id = sd->grp_id;
@@ -4840,10 +4887,16 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
                        if (id < ARRAY_SIZE(module_names)) {
                                p = module_names[id];
                        }
-                       if (!p) p = "(unknown)";
-                       ccnt = scnprintf(buf + tcnt,
-                                        acnt - tcnt,
-                                        " %s (%u)", p, id);
+                       if (p) {
+                               ccnt = scnprintf(buf + tcnt,
+                                                acnt - tcnt,
+                                                " %s", p);
+                       } else {
+                               ccnt = scnprintf(buf + tcnt,
+                                                acnt - tcnt,
+                                                " (unknown id=%u)", id);
+                       }
+                       tcnt += ccnt;
                }
                return tcnt;
        }