Merge git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/v4l-dvb
[pandora-kernel.git] / drivers / media / video / pvrusb2 / pvrusb2-cx2584x-v4l.c
index 8df969c..895859e 100644 (file)
@@ -1,6 +1,5 @@
 /*
  *
- *  $Id$
  *
  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
@@ -49,34 +48,91 @@ struct pvr2_v4l_cx2584x {
 };
 
 
+struct routing_scheme_item {
+       int vid;
+       int aud;
+};
+
+struct routing_scheme {
+       const struct routing_scheme_item *def;
+       unsigned int cnt;
+};
+
+static const struct routing_scheme_item routing_scheme0[] = {
+       [PVR2_CVAL_INPUT_TV] = {
+               .vid = CX25840_COMPOSITE7,
+               .aud = CX25840_AUDIO8,
+       },
+       [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
+               .vid = CX25840_COMPOSITE3,
+               .aud = CX25840_AUDIO_SERIAL,
+       },
+       [PVR2_CVAL_INPUT_COMPOSITE] = {
+               .vid = CX25840_COMPOSITE3,
+               .aud = CX25840_AUDIO_SERIAL,
+       },
+       [PVR2_CVAL_INPUT_SVIDEO] = {
+               .vid = CX25840_SVIDEO1,
+               .aud = CX25840_AUDIO_SERIAL,
+       },
+};
+
+/* Specific to gotview device */
+static const struct routing_scheme_item routing_schemegv[] = {
+       [PVR2_CVAL_INPUT_TV] = {
+               .vid = CX25840_COMPOSITE2,
+               .aud = CX25840_AUDIO5,
+       },
+       [PVR2_CVAL_INPUT_RADIO] = {
+               /* line-in is used for radio and composite.  A GPIO is
+                  used to switch between the two choices. */
+               .vid = CX25840_COMPOSITE1,
+               .aud = CX25840_AUDIO_SERIAL,
+       },
+       [PVR2_CVAL_INPUT_COMPOSITE] = {
+               .vid = CX25840_COMPOSITE1,
+               .aud = CX25840_AUDIO_SERIAL,
+       },
+       [PVR2_CVAL_INPUT_SVIDEO] = {
+               .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
+               .aud = CX25840_AUDIO_SERIAL,
+       },
+};
+
+static const struct routing_scheme routing_schemes[] = {
+       [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
+               .def = routing_scheme0,
+               .cnt = ARRAY_SIZE(routing_scheme0),
+       },
+       [PVR2_ROUTING_SCHEME_GOTVIEW] = {
+               .def = routing_schemegv,
+               .cnt = ARRAY_SIZE(routing_schemegv),
+       },
+};
+
 static void set_input(struct pvr2_v4l_cx2584x *ctxt)
 {
        struct pvr2_hdw *hdw = ctxt->hdw;
        struct v4l2_routing route;
        enum cx25840_video_input vid_input;
        enum cx25840_audio_input aud_input;
+       const struct routing_scheme *sp;
+       unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
 
        memset(&route,0,sizeof(route));
 
-       switch(hdw->input_val) {
-       case PVR2_CVAL_INPUT_TV:
-               vid_input = CX25840_COMPOSITE7;
-               aud_input = CX25840_AUDIO8;
-               break;
-       case PVR2_CVAL_INPUT_COMPOSITE:
-               vid_input = CX25840_COMPOSITE3;
-               aud_input = CX25840_AUDIO_SERIAL;
-               break;
-       case PVR2_CVAL_INPUT_SVIDEO:
-               vid_input = CX25840_SVIDEO1;
-               aud_input = CX25840_AUDIO_SERIAL;
-               break;
-       case PVR2_CVAL_INPUT_RADIO:
-       default:
-               // Just set it to be composite input for now...
-               vid_input = CX25840_COMPOSITE3;
-               aud_input = CX25840_AUDIO_SERIAL;
-               break;
+       if ((sid < ARRAY_SIZE(routing_schemes)) &&
+           ((sp = routing_schemes + sid) != NULL) &&
+           (hdw->input_val >= 0) &&
+           (hdw->input_val < sp->cnt)) {
+               vid_input = sp->def[hdw->input_val].vid;
+               aud_input = sp->def[hdw->input_val].aud;
+       } else {
+               pvr2_trace(PVR2_TRACE_ERROR_LEGS,
+                          "*** WARNING *** i2c cx2584x set_input:"
+                          " Invalid routing scheme (%u) and/or input (%d)",
+                          sid,hdw->input_val);
+               return;
        }
 
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_input vid=0x%x aud=0x%x",
@@ -140,7 +196,7 @@ static const struct pvr2_v4l_cx2584x_ops decoder_ops[] = {
 static void decoder_detach(struct pvr2_v4l_cx2584x *ctxt)
 {
        ctxt->client->handler = NULL;
-       ctxt->hdw->decoder_ctrl = NULL;
+       pvr2_hdw_set_decoder(ctxt->hdw,NULL);
        kfree(ctxt);
 }
 
@@ -150,8 +206,7 @@ static int decoder_check(struct pvr2_v4l_cx2584x *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)) {
@@ -167,8 +222,7 @@ static void decoder_update(struct pvr2_v4l_cx2584x *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;
@@ -199,18 +253,6 @@ static int decoder_detect(struct pvr2_i2c_client *cp)
 }
 
 
-static int decoder_is_tuned(struct pvr2_v4l_cx2584x *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_cx2584x *ctxt,
                                     char *buf,unsigned int cnt)
 {
@@ -243,22 +285,19 @@ int pvr2_i2c_cx2584x_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->ctrl.force_reset = (void (*)(void*))decoder_reset;
        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;
        {
                /*