ce8332dd9cc976a9a9956c3003cfca2a44264c8d
[safe/jmp/linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-video-v4l.c
1 /*
2  *
3  *
4  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
5  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 /*
23
24    This source file is specifically designed to interface with the
25    saa711x support that is available in the v4l available starting
26    with linux 2.6.15.
27
28 */
29
30 #include "pvrusb2-video-v4l.h"
31
32
33
34 #include "pvrusb2-hdw-internal.h"
35 #include "pvrusb2-debug.h"
36 #include <linux/videodev2.h>
37 #include <media/v4l2-common.h>
38 #include <media/saa7115.h>
39 #include <linux/errno.h>
40 #include <linux/slab.h>
41
42 struct routing_scheme {
43         const int *def;
44         unsigned int cnt;
45 };
46
47
48 static const int routing_scheme0[] = {
49         [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
50         /* In radio mode, we mute the video, but point at one
51            spot just to stay consistent */
52         [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
53         [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE5,
54         [PVR2_CVAL_INPUT_SVIDEO] =  SAA7115_SVIDEO2,
55 };
56
57 static const struct routing_scheme routing_schemes[] = {
58         [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
59                 .def = routing_scheme0,
60                 .cnt = ARRAY_SIZE(routing_scheme0),
61         },
62 };
63
64 void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
65 {
66         if (hdw->input_dirty || hdw->force_dirty) {
67                 struct v4l2_routing route;
68                 const struct routing_scheme *sp;
69                 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
70                 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)",
71                            hdw->input_val);
72                 if ((sid < ARRAY_SIZE(routing_schemes)) &&
73                     ((sp = routing_schemes + sid) != NULL) &&
74                     (hdw->input_val >= 0) &&
75                     (hdw->input_val < sp->cnt)) {
76                         route.input = sp->def[hdw->input_val];
77                 } else {
78                         pvr2_trace(PVR2_TRACE_ERROR_LEGS,
79                                    "*** WARNING *** subdev v4l2 set_input:"
80                                    " Invalid routing scheme (%u)"
81                                    " and/or input (%d)",
82                                    sid, hdw->input_val);
83                         return;
84                 }
85                 route.output = 0;
86                 sd->ops->video->s_routing(sd, &route);
87         }
88 }
89
90
91 /*
92   Stuff for Emacs to see, in order to encourage consistent editing style:
93   *** Local Variables: ***
94   *** mode: c ***
95   *** fill-column: 70 ***
96   *** tab-width: 8 ***
97   *** c-basic-offset: 8 ***
98   *** End: ***
99   */