]> Pileus Git - ~andy/linux/blobdiff - drivers/media/video/pvrusb2/pvrusb2-hdw.c
V4L/DVB (11189): pvrusb2: Deal with space-after-comma coding style idiocy
[~andy/linux] / drivers / media / video / pvrusb2 / pvrusb2-hdw.c
index 8aeccb27019b089cd9996a968162d824194951ec..029cdf411df00808e606ad938363265a059df029 100644 (file)
 #include "pvrusb2-encoder.h"
 #include "pvrusb2-debug.h"
 #include "pvrusb2-fx2-cmd.h"
+#include "pvrusb2-wm8775.h"
+#include "pvrusb2-video-v4l.h"
+#include "pvrusb2-cx2584x-v4l.h"
+#include "pvrusb2-audio.h"
 
 #define TV_MIN_FREQ     55250000L
 #define TV_MAX_FREQ    850000000L
@@ -105,17 +109,29 @@ MODULE_PARM_DESC(radio_freq, "specify initial radio frequency");
 /* size of a firmware chunk */
 #define FIRMWARE_CHUNK_SIZE 0x2000
 
+typedef void (*pvr2_subdev_update_func)(struct pvr2_hdw *,
+                                       struct v4l2_subdev *);
+
+static const pvr2_subdev_update_func pvr2_module_update_functions[] = {
+       [PVR2_CLIENT_ID_WM8775] = pvr2_wm8775_subdev_update,
+       [PVR2_CLIENT_ID_SAA7115] = pvr2_saa7115_subdev_update,
+       [PVR2_CLIENT_ID_MSP3400] = pvr2_msp3400_subdev_update,
+       [PVR2_CLIENT_ID_CX25840] = pvr2_cx25840_subdev_update,
+};
+
 static const char *module_names[] = {
        [PVR2_CLIENT_ID_MSP3400] = "msp3400",
        [PVR2_CLIENT_ID_CX25840] = "cx25840",
        [PVR2_CLIENT_ID_SAA7115] = "saa7115",
        [PVR2_CLIENT_ID_TUNER] = "tuner",
        [PVR2_CLIENT_ID_CS53132A] = "cs53132a",
+       [PVR2_CLIENT_ID_WM8775] = "wm8775",
 };
 
 
 static const unsigned char *module_i2c_addresses[] = {
        [PVR2_CLIENT_ID_TUNER] = "\x60\x61\x62\x63",
+       [PVR2_CLIENT_ID_WM8775] = "\x1b",
 };
 
 
@@ -1655,18 +1671,29 @@ static const char *pvr2_get_state_name(unsigned int st)
 
 static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
 {
-       if (!hdw->decoder_ctrl) {
-               if (!hdw->flag_decoder_missed) {
-                       pvr2_trace(PVR2_TRACE_ERROR_LEGS,
-                                  "WARNING: No decoder present");
-                       hdw->flag_decoder_missed = !0;
-                       trace_stbit("flag_decoder_missed",
-                                   hdw->flag_decoder_missed);
-               }
-               return -EIO;
+       if (hdw->decoder_ctrl) {
+               hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt, enablefl);
+               return 0;
        }
-       hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt,enablefl);
-       return 0;
+       /* Even though we really only care about the video decoder chip at
+          this point, we'll broadcast stream on/off to all sub-devices
+          anyway, just in case somebody else wants to hear the
+          command... */
+       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
+                  we'll issue a warning to the user (which should
+                  normally never happen). */
+               return 0;
+       }
+       if (!hdw->flag_decoder_missed) {
+               pvr2_trace(PVR2_TRACE_ERROR_LEGS,
+                          "WARNING: No decoder present");
+               hdw->flag_decoder_missed = !0;
+               trace_stbit("flag_decoder_missed",
+                           hdw->flag_decoder_missed);
+       }
+       return -EIO;
 }
 
 
@@ -1952,7 +1979,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];
@@ -1963,8 +1990,8 @@ static unsigned int pvr2_copy_i2c_addr_list(
 }
 
 
-static void pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
-                                const struct pvr2_device_client_desc *cd)
+static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
+                               const struct pvr2_device_client_desc *cd)
 {
        const char *fname;
        unsigned char mid;
@@ -1978,12 +2005,15 @@ static void pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
        fname = (mid < ARRAY_SIZE(module_names)) ? module_names[mid] : NULL;
        if (!fname) {
                pvr2_trace(PVR2_TRACE_ERROR_LEGS,
-                          "Module ID %u for device %s is unknown"
-                          " (this is probably a bad thing...)",
+                          "Module ID %u for device %s has no name",
                           mid,
                           hdw->hdw_desc->description);
-               return;
+               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));
@@ -1992,15 +2022,20 @@ static void 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) {
                pvr2_trace(PVR2_TRACE_ERROR_LEGS,
-                          "Module ID %u for device %s:"
-                          " No i2c addresses"
-                          " (this is probably a bad thing...)",
-                          mid, hdw->hdw_desc->description);
-               return;
+                          "Module ID %u (%s) for device %s:"
+                          " No i2c addresses",
+                          mid, fname, hdw->hdw_desc->description);
+               return -EINVAL;
        }
 
        /* Note how the 2nd and 3rd arguments are the same for both
@@ -2010,22 +2045,31 @@ static void 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,
-                          "Module ID %u for device %s failed to load"
-                          " (this is probably a bad thing...)",
-                          mid, hdw->hdw_desc->description);
-               return;
+                          "Module ID %u (%s) for device %s failed to load",
+                          mid, fname, hdw->hdw_desc->description);
+               return -EIO;
        }
 
        /* Tag this sub-device instance with the module ID we know about.
@@ -2038,9 +2082,43 @@ static void 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... */
+       switch (mid) {
+       case PVR2_CLIENT_ID_CX25840:
+               hdw->decoder_client_id = mid;
+               {
+                       /*
+                         Mike Isely <isely@pobox.com> 19-Nov-2006 - This
+                         bit of nuttiness for cx25840 causes that module
+                         to correctly set up its video scaling.  This is
+                         really a problem in the cx25840 module itself,
+                         but we work around it here.  The problem has not
+                         been seen in ivtv because there VBI is supported
+                         and set up.  We don't do VBI here (at least not
+                         yet) and thus we never attempted to even set it
+                         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,
+                                            video, s_fmt, &fmt);
+               }
+               break;
+       case PVR2_CLIENT_ID_SAA7115:
+               hdw->decoder_client_id = mid;
+               break;
+       default: break;
+       }
 
+       return 0;
 }
 
 
@@ -2049,6 +2127,7 @@ static void pvr2_hdw_load_modules(struct pvr2_hdw *hdw)
        unsigned int idx;
        const struct pvr2_string_table *cm;
        const struct pvr2_device_client_table *ct;
+       int okFl = !0;
 
        cm = &hdw->hdw_desc->client_modules;
        for (idx = 0; idx < cm->cnt; idx++) {
@@ -2057,8 +2136,9 @@ static void pvr2_hdw_load_modules(struct pvr2_hdw *hdw)
 
        ct = &hdw->hdw_desc->client_table;
        for (idx = 0; idx < ct->cnt; idx++) {
-               pvr2_hdw_load_subdev(hdw,&ct->lst[idx]);
+               if (pvr2_hdw_load_subdev(hdw, &ct->lst[idx]) < 0) okFl = 0;
        }
+       if (!okFl) pvr2_hdw_render_useless(hdw);
 }
 
 
@@ -2120,6 +2200,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
        if (!pvr2_hdw_dev_ok(hdw)) return;
 
        pvr2_hdw_load_modules(hdw);
+       if (!pvr2_hdw_dev_ok(hdw)) return;
 
        for (idx = 0; idx < CTRLDEF_COUNT; idx++) {
                cptr = hdw->controls + idx;
@@ -2859,8 +2940,12 @@ static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
    sub-devices so that they match our current control values. */
 static void pvr2_subdev_update(struct pvr2_hdw *hdw)
 {
+       struct v4l2_subdev *sd;
+       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 v4l2 set_standard");
                if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
                        v4l2_device_call_all(&hdw->v4l2_dev, 0,
                                             tuner, s_radio);
@@ -2927,10 +3012,36 @@ 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) {
+               u32 val;
+               pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_audio %d",
+                          hdw->srate_val);
+               switch (hdw->srate_val) {
+               default:
+               case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
+                       val = 48000;
+                       break;
+               case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
+                       val = 44100;
+                       break;
+               case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
+                       val = 32000;
+                       break;
+               }
+               v4l2_device_call_all(&hdw->v4l2_dev, 0,
+                                    audio, s_clock_freq, val);
+       }
+
        /* Unable to set crop parameters; there is apparently no equivalent
           for VIDIOC_S_CROP */
 
-       /* ????? Cover special cases for specific sub-devices. */
+       v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
+               id = sd->grp_id;
+               if (id >= ARRAY_SIZE(pvr2_module_update_functions)) continue;
+               fp = pvr2_module_update_functions[id];
+               if (!fp) continue;
+               (*fp)(hdw, sd);
+       }
 
        if (hdw->tuner_signal_stale && hdw->cropcap_stale) {
                pvr2_hdw_status_poll(hdw);
@@ -3127,15 +3238,15 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
                }
        }
 
+       /* Check and update state for all sub-devices. */
+       pvr2_subdev_update(hdw);
+
        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);
 
@@ -3980,22 +4091,26 @@ int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *hdw)
 
 int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
 {
-       if (!hdw->decoder_ctrl) {
-               pvr2_trace(PVR2_TRACE_INIT,
-                          "Unable to reset decoder: nothing attached");
-               return -ENOTTY;
+       pvr2_trace(PVR2_TRACE_INIT,
+                  "Requesting decoder reset");
+       if (hdw->decoder_ctrl) {
+               if (!hdw->decoder_ctrl->force_reset) {
+                       pvr2_trace(PVR2_TRACE_INIT,
+                                  "Unable to reset decoder: not implemented");
+                       return -ENOTTY;
+               }
+               hdw->decoder_ctrl->force_reset(hdw->decoder_ctrl->ctxt);
+               return 0;
+       } else {
        }
-
-       if (!hdw->decoder_ctrl->force_reset) {
-               pvr2_trace(PVR2_TRACE_INIT,
-                          "Unable to reset decoder: not implemented");
-               return -ENOTTY;
+       if (hdw->decoder_client_id) {
+               v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id,
+                                    core, reset, 0);
+               return 0;
        }
-
        pvr2_trace(PVR2_TRACE_INIT,
-                  "Requesting decoder reset");
-       hdw->decoder_ctrl->force_reset(hdw->decoder_ctrl->ctxt);
-       return 0;
+                  "Unable to reset decoder: nothing attached");
+       return -ENOTTY;
 }
 
 
@@ -4734,6 +4849,35 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
                        stats.buffers_processed,
                        stats.buffers_failed);
        }
+       case 6: {
+               struct v4l2_subdev *sd;
+               unsigned int tcnt = 0;
+               unsigned int ccnt;
+               const char *p;
+               unsigned int id;
+               ccnt = scnprintf(buf,
+                                acnt,
+                                "Associated v4l2_subdev drivers:");
+               tcnt += ccnt;
+               v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
+                       id = sd->grp_id;
+                       p = NULL;
+                       if (id < ARRAY_SIZE(module_names)) {
+                               p = module_names[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;
+       }
        default: break;
        }
        return 0;