1*2504ba9fSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
20c0d06caSMauro Carvalho Chehab /*
30c0d06caSMauro Carvalho Chehab *
40c0d06caSMauro Carvalho Chehab * Copyright (C) 2005 Mike Isely <isely@pobox.com>
50c0d06caSMauro Carvalho Chehab * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
60c0d06caSMauro Carvalho Chehab */
70c0d06caSMauro Carvalho Chehab
80c0d06caSMauro Carvalho Chehab /*
90c0d06caSMauro Carvalho Chehab
100c0d06caSMauro Carvalho Chehab This source file is specifically designed to interface with the
110c0d06caSMauro Carvalho Chehab cx2584x, in kernels 2.6.16 or newer.
120c0d06caSMauro Carvalho Chehab
130c0d06caSMauro Carvalho Chehab */
140c0d06caSMauro Carvalho Chehab
150c0d06caSMauro Carvalho Chehab #include "pvrusb2-cx2584x-v4l.h"
160c0d06caSMauro Carvalho Chehab
170c0d06caSMauro Carvalho Chehab
180c0d06caSMauro Carvalho Chehab #include "pvrusb2-hdw-internal.h"
190c0d06caSMauro Carvalho Chehab #include "pvrusb2-debug.h"
20d647f0b7SMauro Carvalho Chehab #include <media/drv-intf/cx25840.h>
210c0d06caSMauro Carvalho Chehab #include <linux/videodev2.h>
220c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
230c0d06caSMauro Carvalho Chehab #include <linux/errno.h>
240c0d06caSMauro Carvalho Chehab
250c0d06caSMauro Carvalho Chehab
260c0d06caSMauro Carvalho Chehab struct routing_scheme_item {
270c0d06caSMauro Carvalho Chehab int vid;
280c0d06caSMauro Carvalho Chehab int aud;
290c0d06caSMauro Carvalho Chehab };
300c0d06caSMauro Carvalho Chehab
310c0d06caSMauro Carvalho Chehab struct routing_scheme {
320c0d06caSMauro Carvalho Chehab const struct routing_scheme_item *def;
330c0d06caSMauro Carvalho Chehab unsigned int cnt;
340c0d06caSMauro Carvalho Chehab };
350c0d06caSMauro Carvalho Chehab
360c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_scheme0[] = {
370c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_TV] = {
380c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE7,
390c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO8,
400c0d06caSMauro Carvalho Chehab },
410c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
420c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE3,
430c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
440c0d06caSMauro Carvalho Chehab },
450c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_COMPOSITE] = {
460c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE3,
470c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
480c0d06caSMauro Carvalho Chehab },
490c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_SVIDEO] = {
500c0d06caSMauro Carvalho Chehab .vid = CX25840_SVIDEO1,
510c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
520c0d06caSMauro Carvalho Chehab },
530c0d06caSMauro Carvalho Chehab };
540c0d06caSMauro Carvalho Chehab
550c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_def0 = {
560c0d06caSMauro Carvalho Chehab .def = routing_scheme0,
570c0d06caSMauro Carvalho Chehab .cnt = ARRAY_SIZE(routing_scheme0),
580c0d06caSMauro Carvalho Chehab };
590c0d06caSMauro Carvalho Chehab
600c0d06caSMauro Carvalho Chehab /* Specific to gotview device */
610c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_schemegv[] = {
620c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_TV] = {
630c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE2,
640c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO5,
650c0d06caSMauro Carvalho Chehab },
660c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_RADIO] = {
670c0d06caSMauro Carvalho Chehab /* line-in is used for radio and composite. A GPIO is
680c0d06caSMauro Carvalho Chehab used to switch between the two choices. */
690c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE1,
700c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
710c0d06caSMauro Carvalho Chehab },
720c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_COMPOSITE] = {
730c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE1,
740c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
750c0d06caSMauro Carvalho Chehab },
760c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_SVIDEO] = {
770c0d06caSMauro Carvalho Chehab .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
780c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
790c0d06caSMauro Carvalho Chehab },
800c0d06caSMauro Carvalho Chehab };
810c0d06caSMauro Carvalho Chehab
820c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_defgv = {
830c0d06caSMauro Carvalho Chehab .def = routing_schemegv,
840c0d06caSMauro Carvalho Chehab .cnt = ARRAY_SIZE(routing_schemegv),
850c0d06caSMauro Carvalho Chehab };
860c0d06caSMauro Carvalho Chehab
870c0d06caSMauro Carvalho Chehab /* Specific to grabster av400 device */
880c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_schemeav400[] = {
890c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_COMPOSITE] = {
900c0d06caSMauro Carvalho Chehab .vid = CX25840_COMPOSITE1,
910c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
920c0d06caSMauro Carvalho Chehab },
930c0d06caSMauro Carvalho Chehab [PVR2_CVAL_INPUT_SVIDEO] = {
940c0d06caSMauro Carvalho Chehab .vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
950c0d06caSMauro Carvalho Chehab .aud = CX25840_AUDIO_SERIAL,
960c0d06caSMauro Carvalho Chehab },
970c0d06caSMauro Carvalho Chehab };
980c0d06caSMauro Carvalho Chehab
990c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_defav400 = {
1000c0d06caSMauro Carvalho Chehab .def = routing_schemeav400,
1010c0d06caSMauro Carvalho Chehab .cnt = ARRAY_SIZE(routing_schemeav400),
1020c0d06caSMauro Carvalho Chehab };
1030c0d06caSMauro Carvalho Chehab
104dd60bf43SBrad Love static const struct routing_scheme_item routing_scheme160xxx[] = {
105dd60bf43SBrad Love [PVR2_CVAL_INPUT_TV] = {
106dd60bf43SBrad Love .vid = CX25840_COMPOSITE7,
107dd60bf43SBrad Love .aud = CX25840_AUDIO8,
108dd60bf43SBrad Love },
109dd60bf43SBrad Love [PVR2_CVAL_INPUT_RADIO] = {
110dd60bf43SBrad Love .vid = CX25840_COMPOSITE4,
111dd60bf43SBrad Love .aud = CX25840_AUDIO6,
112dd60bf43SBrad Love },
113dd60bf43SBrad Love [PVR2_CVAL_INPUT_COMPOSITE] = {
114dd60bf43SBrad Love .vid = CX25840_COMPOSITE3,
115dd60bf43SBrad Love .aud = CX25840_AUDIO_SERIAL,
116dd60bf43SBrad Love },
117dd60bf43SBrad Love [PVR2_CVAL_INPUT_SVIDEO] = {
118dd60bf43SBrad Love .vid = CX25840_SVIDEO1,
119dd60bf43SBrad Love .aud = CX25840_AUDIO_SERIAL,
120dd60bf43SBrad Love },
121dd60bf43SBrad Love };
122dd60bf43SBrad Love
123dd60bf43SBrad Love static const struct routing_scheme routing_def160xxx = {
124dd60bf43SBrad Love .def = routing_scheme160xxx,
125dd60bf43SBrad Love .cnt = ARRAY_SIZE(routing_scheme160xxx),
126dd60bf43SBrad Love };
127dd60bf43SBrad Love
1280c0d06caSMauro Carvalho Chehab static const struct routing_scheme *routing_schemes[] = {
1290c0d06caSMauro Carvalho Chehab [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
1300c0d06caSMauro Carvalho Chehab [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
1310c0d06caSMauro Carvalho Chehab [PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
132dd60bf43SBrad Love [PVR2_ROUTING_SCHEME_HAUP160XXX] = &routing_def160xxx,
1330c0d06caSMauro Carvalho Chehab };
1340c0d06caSMauro Carvalho Chehab
pvr2_cx25840_subdev_update(struct pvr2_hdw * hdw,struct v4l2_subdev * sd)1350c0d06caSMauro Carvalho Chehab void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
1360c0d06caSMauro Carvalho Chehab {
1370c0d06caSMauro Carvalho Chehab pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
1380c0d06caSMauro Carvalho Chehab if (hdw->input_dirty || hdw->force_dirty) {
1390c0d06caSMauro Carvalho Chehab enum cx25840_video_input vid_input;
1400c0d06caSMauro Carvalho Chehab enum cx25840_audio_input aud_input;
1410c0d06caSMauro Carvalho Chehab const struct routing_scheme *sp;
1420c0d06caSMauro Carvalho Chehab unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
1430c0d06caSMauro Carvalho Chehab
1440c0d06caSMauro Carvalho Chehab sp = (sid < ARRAY_SIZE(routing_schemes)) ?
1450c0d06caSMauro Carvalho Chehab routing_schemes[sid] : NULL;
1460c0d06caSMauro Carvalho Chehab if ((sp == NULL) ||
1470c0d06caSMauro Carvalho Chehab (hdw->input_val < 0) ||
1480c0d06caSMauro Carvalho Chehab (hdw->input_val >= sp->cnt)) {
1490c0d06caSMauro Carvalho Chehab pvr2_trace(PVR2_TRACE_ERROR_LEGS,
15096292c89SMauro Carvalho Chehab "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)",
1510c0d06caSMauro Carvalho Chehab sid, hdw->input_val);
1520c0d06caSMauro Carvalho Chehab return;
1530c0d06caSMauro Carvalho Chehab }
1540c0d06caSMauro Carvalho Chehab vid_input = sp->def[hdw->input_val].vid;
1550c0d06caSMauro Carvalho Chehab aud_input = sp->def[hdw->input_val].aud;
1560c0d06caSMauro Carvalho Chehab pvr2_trace(PVR2_TRACE_CHIPS,
1570c0d06caSMauro Carvalho Chehab "subdev cx2584x set_input vid=0x%x aud=0x%x",
1580c0d06caSMauro Carvalho Chehab vid_input, aud_input);
1590c0d06caSMauro Carvalho Chehab sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
1600c0d06caSMauro Carvalho Chehab sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
1610c0d06caSMauro Carvalho Chehab }
1620c0d06caSMauro Carvalho Chehab }
163