GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / media / usb / pvrusb2 / pvrusb2-cx2584x-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  */
17
18 /*
19
20    This source file is specifically designed to interface with the
21    cx2584x, in kernels 2.6.16 or newer.
22
23 */
24
25 #include "pvrusb2-cx2584x-v4l.h"
26 #include "pvrusb2-video-v4l.h"
27
28
29 #include "pvrusb2-hdw-internal.h"
30 #include "pvrusb2-debug.h"
31 #include <media/drv-intf/cx25840.h>
32 #include <linux/videodev2.h>
33 #include <media/v4l2-common.h>
34 #include <linux/errno.h>
35
36
37 struct routing_scheme_item {
38         int vid;
39         int aud;
40 };
41
42 struct routing_scheme {
43         const struct routing_scheme_item *def;
44         unsigned int cnt;
45 };
46
47 static const struct routing_scheme_item routing_scheme0[] = {
48         [PVR2_CVAL_INPUT_TV] = {
49                 .vid = CX25840_COMPOSITE7,
50                 .aud = CX25840_AUDIO8,
51         },
52         [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
53                 .vid = CX25840_COMPOSITE3,
54                 .aud = CX25840_AUDIO_SERIAL,
55         },
56         [PVR2_CVAL_INPUT_COMPOSITE] = {
57                 .vid = CX25840_COMPOSITE3,
58                 .aud = CX25840_AUDIO_SERIAL,
59         },
60         [PVR2_CVAL_INPUT_SVIDEO] = {
61                 .vid = CX25840_SVIDEO1,
62                 .aud = CX25840_AUDIO_SERIAL,
63         },
64 };
65
66 static const struct routing_scheme routing_def0 = {
67         .def = routing_scheme0,
68         .cnt = ARRAY_SIZE(routing_scheme0),
69 };
70
71 /* Specific to gotview device */
72 static const struct routing_scheme_item routing_schemegv[] = {
73         [PVR2_CVAL_INPUT_TV] = {
74                 .vid = CX25840_COMPOSITE2,
75                 .aud = CX25840_AUDIO5,
76         },
77         [PVR2_CVAL_INPUT_RADIO] = {
78                 /* line-in is used for radio and composite.  A GPIO is
79                    used to switch between the two choices. */
80                 .vid = CX25840_COMPOSITE1,
81                 .aud = CX25840_AUDIO_SERIAL,
82         },
83         [PVR2_CVAL_INPUT_COMPOSITE] = {
84                 .vid = CX25840_COMPOSITE1,
85                 .aud = CX25840_AUDIO_SERIAL,
86         },
87         [PVR2_CVAL_INPUT_SVIDEO] = {
88                 .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
89                 .aud = CX25840_AUDIO_SERIAL,
90         },
91 };
92
93 static const struct routing_scheme routing_defgv = {
94         .def = routing_schemegv,
95         .cnt = ARRAY_SIZE(routing_schemegv),
96 };
97
98 /* Specific to grabster av400 device */
99 static const struct routing_scheme_item routing_schemeav400[] = {
100         [PVR2_CVAL_INPUT_COMPOSITE] = {
101                 .vid = CX25840_COMPOSITE1,
102                 .aud = CX25840_AUDIO_SERIAL,
103         },
104         [PVR2_CVAL_INPUT_SVIDEO] = {
105                 .vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
106                 .aud = CX25840_AUDIO_SERIAL,
107         },
108 };
109
110 static const struct routing_scheme routing_defav400 = {
111         .def = routing_schemeav400,
112         .cnt = ARRAY_SIZE(routing_schemeav400),
113 };
114
115 static const struct routing_scheme *routing_schemes[] = {
116         [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
117         [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
118         [PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
119 };
120
121 void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
122 {
123         pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
124         if (hdw->input_dirty || hdw->force_dirty) {
125                 enum cx25840_video_input vid_input;
126                 enum cx25840_audio_input aud_input;
127                 const struct routing_scheme *sp;
128                 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
129
130                 sp = (sid < ARRAY_SIZE(routing_schemes)) ?
131                         routing_schemes[sid] : NULL;
132                 if ((sp == NULL) ||
133                     (hdw->input_val < 0) ||
134                     (hdw->input_val >= sp->cnt)) {
135                         pvr2_trace(PVR2_TRACE_ERROR_LEGS,
136                                    "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)",
137                                    sid, hdw->input_val);
138                         return;
139                 }
140                 vid_input = sp->def[hdw->input_val].vid;
141                 aud_input = sp->def[hdw->input_val].aud;
142                 pvr2_trace(PVR2_TRACE_CHIPS,
143                            "subdev cx2584x set_input vid=0x%x aud=0x%x",
144                            vid_input, aud_input);
145                 sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
146                 sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
147         }
148 }