WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / usb / pvrusb2 / pvrusb2-cx2584x-v4l.c
blobe4b31ae02f5920212d0238e5a85bf71a5fd3e25c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6 */
8 /*
10 This source file is specifically designed to interface with the
11 cx2584x, in kernels 2.6.16 or newer.
15 #include "pvrusb2-cx2584x-v4l.h"
18 #include "pvrusb2-hdw-internal.h"
19 #include "pvrusb2-debug.h"
20 #include <media/drv-intf/cx25840.h>
21 #include <linux/videodev2.h>
22 #include <media/v4l2-common.h>
23 #include <linux/errno.h>
26 struct routing_scheme_item {
27 int vid;
28 int aud;
31 struct routing_scheme {
32 const struct routing_scheme_item *def;
33 unsigned int cnt;
36 static const struct routing_scheme_item routing_scheme0[] = {
37 [PVR2_CVAL_INPUT_TV] = {
38 .vid = CX25840_COMPOSITE7,
39 .aud = CX25840_AUDIO8,
41 [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
42 .vid = CX25840_COMPOSITE3,
43 .aud = CX25840_AUDIO_SERIAL,
45 [PVR2_CVAL_INPUT_COMPOSITE] = {
46 .vid = CX25840_COMPOSITE3,
47 .aud = CX25840_AUDIO_SERIAL,
49 [PVR2_CVAL_INPUT_SVIDEO] = {
50 .vid = CX25840_SVIDEO1,
51 .aud = CX25840_AUDIO_SERIAL,
55 static const struct routing_scheme routing_def0 = {
56 .def = routing_scheme0,
57 .cnt = ARRAY_SIZE(routing_scheme0),
60 /* Specific to gotview device */
61 static const struct routing_scheme_item routing_schemegv[] = {
62 [PVR2_CVAL_INPUT_TV] = {
63 .vid = CX25840_COMPOSITE2,
64 .aud = CX25840_AUDIO5,
66 [PVR2_CVAL_INPUT_RADIO] = {
67 /* line-in is used for radio and composite. A GPIO is
68 used to switch between the two choices. */
69 .vid = CX25840_COMPOSITE1,
70 .aud = CX25840_AUDIO_SERIAL,
72 [PVR2_CVAL_INPUT_COMPOSITE] = {
73 .vid = CX25840_COMPOSITE1,
74 .aud = CX25840_AUDIO_SERIAL,
76 [PVR2_CVAL_INPUT_SVIDEO] = {
77 .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
78 .aud = CX25840_AUDIO_SERIAL,
82 static const struct routing_scheme routing_defgv = {
83 .def = routing_schemegv,
84 .cnt = ARRAY_SIZE(routing_schemegv),
87 /* Specific to grabster av400 device */
88 static const struct routing_scheme_item routing_schemeav400[] = {
89 [PVR2_CVAL_INPUT_COMPOSITE] = {
90 .vid = CX25840_COMPOSITE1,
91 .aud = CX25840_AUDIO_SERIAL,
93 [PVR2_CVAL_INPUT_SVIDEO] = {
94 .vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
95 .aud = CX25840_AUDIO_SERIAL,
99 static const struct routing_scheme routing_defav400 = {
100 .def = routing_schemeav400,
101 .cnt = ARRAY_SIZE(routing_schemeav400),
104 static const struct routing_scheme_item routing_scheme160xxx[] = {
105 [PVR2_CVAL_INPUT_TV] = {
106 .vid = CX25840_COMPOSITE7,
107 .aud = CX25840_AUDIO8,
109 [PVR2_CVAL_INPUT_RADIO] = {
110 .vid = CX25840_COMPOSITE4,
111 .aud = CX25840_AUDIO6,
113 [PVR2_CVAL_INPUT_COMPOSITE] = {
114 .vid = CX25840_COMPOSITE3,
115 .aud = CX25840_AUDIO_SERIAL,
117 [PVR2_CVAL_INPUT_SVIDEO] = {
118 .vid = CX25840_SVIDEO1,
119 .aud = CX25840_AUDIO_SERIAL,
123 static const struct routing_scheme routing_def160xxx = {
124 .def = routing_scheme160xxx,
125 .cnt = ARRAY_SIZE(routing_scheme160xxx),
128 static const struct routing_scheme *routing_schemes[] = {
129 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
130 [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
131 [PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
132 [PVR2_ROUTING_SCHEME_HAUP160XXX] = &routing_def160xxx,
135 void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
137 pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
138 if (hdw->input_dirty || hdw->force_dirty) {
139 enum cx25840_video_input vid_input;
140 enum cx25840_audio_input aud_input;
141 const struct routing_scheme *sp;
142 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
144 sp = (sid < ARRAY_SIZE(routing_schemes)) ?
145 routing_schemes[sid] : NULL;
146 if ((sp == NULL) ||
147 (hdw->input_val < 0) ||
148 (hdw->input_val >= sp->cnt)) {
149 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
150 "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)",
151 sid, hdw->input_val);
152 return;
154 vid_input = sp->def[hdw->input_val].vid;
155 aud_input = sp->def[hdw->input_val].aud;
156 pvr2_trace(PVR2_TRACE_CHIPS,
157 "subdev cx2584x set_input vid=0x%x aud=0x%x",
158 vid_input, aud_input);
159 sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
160 sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);