V4L/DVB (7090): V4L: stkwebcam: use v4l_compat_ioctl32
[cascardo/linux.git] / drivers / media / video / pvrusb2 / pvrusb2-video-v4l.c
index e4ec7f2..7c47345 100644 (file)
@@ -49,27 +49,50 @@ struct pvr2_v4l_decoder {
 };
 
 
+struct routing_scheme {
+       const int *def;
+       unsigned int cnt;
+};
+
+
+static const int routing_scheme0[] = {
+       [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
+       /* In radio mode, we mute the video, but point at one
+          spot just to stay consistent */
+       [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
+       [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE5,
+       [PVR2_CVAL_INPUT_SVIDEO] =  SAA7115_SVIDEO2,
+};
+
+static const struct routing_scheme routing_schemes[] = {
+       [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
+               .def = routing_scheme0,
+               .cnt = ARRAY_SIZE(routing_scheme0),
+       },
+};
+
 static void set_input(struct pvr2_v4l_decoder *ctxt)
 {
        struct pvr2_hdw *hdw = ctxt->hdw;
        struct v4l2_routing route;
+       const struct routing_scheme *sp;
+       unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
 
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_input(%d)",hdw->input_val);
-       switch(hdw->input_val) {
-       case PVR2_CVAL_INPUT_TV:
-               route.input = SAA7115_COMPOSITE4;
-               break;
-       case PVR2_CVAL_INPUT_COMPOSITE:
-               route.input = SAA7115_COMPOSITE5;
-               break;
-       case PVR2_CVAL_INPUT_SVIDEO:
-               route.input = SAA7115_SVIDEO2;
-               break;
-       case PVR2_CVAL_INPUT_RADIO:
-               // ????? No idea yet what to do here
-       default:
+
+       if ((sid < ARRAY_SIZE(routing_schemes)) &&
+           ((sp = routing_schemes + sid) != 0) &&
+           (hdw->input_val >= 0) &&
+           (hdw->input_val < sp->cnt)) {
+               route.input = sp->def[hdw->input_val];
+       } else {
+               pvr2_trace(PVR2_TRACE_ERROR_LEGS,
+                          "*** WARNING *** i2c v4l2 set_input:"
+                          " Invalid routing scheme (%u) and/or input (%d)",
+                          sid,hdw->input_val);
                return;
        }
+
        route.output = 0;
        pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route);
 }
@@ -126,8 +149,8 @@ static const struct pvr2_v4l_decoder_ops decoder_ops[] = {
 
 static void decoder_detach(struct pvr2_v4l_decoder *ctxt)
 {
-       ctxt->client->handler = 0;
-       ctxt->hdw->decoder_ctrl = 0;
+       ctxt->client->handler = NULL;
+       pvr2_hdw_set_decoder(ctxt->hdw,NULL);
        kfree(ctxt);
 }
 
@@ -137,8 +160,7 @@ static int decoder_check(struct pvr2_v4l_decoder *ctxt)
        unsigned long msk;
        unsigned int idx;
 
-       for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-            idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
                msk = 1 << idx;
                if (ctxt->stale_mask & msk) continue;
                if (decoder_ops[idx].check(ctxt)) {
@@ -154,8 +176,7 @@ static void decoder_update(struct pvr2_v4l_decoder *ctxt)
        unsigned long msk;
        unsigned int idx;
 
-       for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-            idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
                msk = 1 << idx;
                if (!(ctxt->stale_mask & msk)) continue;
                ctxt->stale_mask &= ~msk;
@@ -183,25 +204,13 @@ static void decoder_enable(struct pvr2_v4l_decoder *ctxt,int fl)
 }
 
 
-static int decoder_is_tuned(struct pvr2_v4l_decoder *ctxt)
-{
-       struct v4l2_tuner vt;
-       int ret;
-
-       memset(&vt,0,sizeof(vt));
-       ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_G_TUNER,&vt);
-       if (ret < 0) return -EINVAL;
-       return vt.signal ? 1 : 0;
-}
-
-
 static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,unsigned int cnt)
 {
        return scnprintf(buf,cnt,"handler: pvrusb2-video-v4l");
 }
 
 
-const static struct pvr2_i2c_handler_functions hfuncs = {
+static const struct pvr2_i2c_handler_functions hfuncs = {
        .detach = (void (*)(void *))decoder_detach,
        .check = (int (*)(void *))decoder_check,
        .update = (void (*)(void *))decoder_update,
@@ -218,21 +227,18 @@ int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
        if (cp->handler) return 0;
        if (!decoder_detect(cp)) return 0;
 
-       ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL);
+       ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
        if (!ctxt) return 0;
-       memset(ctxt,0,sizeof(*ctxt));
 
        ctxt->handler.func_data = ctxt;
        ctxt->handler.func_table = &hfuncs;
        ctxt->ctrl.ctxt = ctxt;
        ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
        ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
-       ctxt->ctrl.tuned = (int (*)(void *))decoder_is_tuned;
        ctxt->client = cp;
        ctxt->hdw = hdw;
-       ctxt->stale_mask = (1 << (sizeof(decoder_ops)/
-                                 sizeof(decoder_ops[0]))) - 1;
-       hdw->decoder_ctrl = &ctxt->ctrl;
+       ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
+       pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
        cp->handler = &ctxt->handler;
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
                   cp->client->addr);