xref: /linux/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c (revision dd60bf4360312559654a5efdac5108fee6fc9fdf)
10c0d06caSMauro Carvalho Chehab /*
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  *  This program is free software; you can redistribute it and/or modify
80c0d06caSMauro Carvalho Chehab  *  it under the terms of the GNU General Public License as published by
90c0d06caSMauro Carvalho Chehab  *  the Free Software Foundation; either version 2 of the License
100c0d06caSMauro Carvalho Chehab  *
110c0d06caSMauro Carvalho Chehab  *  This program is distributed in the hope that it will be useful,
120c0d06caSMauro Carvalho Chehab  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
130c0d06caSMauro Carvalho Chehab  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
140c0d06caSMauro Carvalho Chehab  *  GNU General Public License for more details.
150c0d06caSMauro Carvalho Chehab  *
160c0d06caSMauro Carvalho Chehab  */
170c0d06caSMauro Carvalho Chehab 
180c0d06caSMauro Carvalho Chehab /*
190c0d06caSMauro Carvalho Chehab 
200c0d06caSMauro Carvalho Chehab    This source file is specifically designed to interface with the
210c0d06caSMauro Carvalho Chehab    cx2584x, in kernels 2.6.16 or newer.
220c0d06caSMauro Carvalho Chehab 
230c0d06caSMauro Carvalho Chehab */
240c0d06caSMauro Carvalho Chehab 
250c0d06caSMauro Carvalho Chehab #include "pvrusb2-cx2584x-v4l.h"
260c0d06caSMauro Carvalho Chehab 
270c0d06caSMauro Carvalho Chehab 
280c0d06caSMauro Carvalho Chehab #include "pvrusb2-hdw-internal.h"
290c0d06caSMauro Carvalho Chehab #include "pvrusb2-debug.h"
30d647f0b7SMauro Carvalho Chehab #include <media/drv-intf/cx25840.h>
310c0d06caSMauro Carvalho Chehab #include <linux/videodev2.h>
320c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
330c0d06caSMauro Carvalho Chehab #include <linux/errno.h>
340c0d06caSMauro Carvalho Chehab 
350c0d06caSMauro Carvalho Chehab 
360c0d06caSMauro Carvalho Chehab struct routing_scheme_item {
370c0d06caSMauro Carvalho Chehab 	int vid;
380c0d06caSMauro Carvalho Chehab 	int aud;
390c0d06caSMauro Carvalho Chehab };
400c0d06caSMauro Carvalho Chehab 
410c0d06caSMauro Carvalho Chehab struct routing_scheme {
420c0d06caSMauro Carvalho Chehab 	const struct routing_scheme_item *def;
430c0d06caSMauro Carvalho Chehab 	unsigned int cnt;
440c0d06caSMauro Carvalho Chehab };
450c0d06caSMauro Carvalho Chehab 
460c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_scheme0[] = {
470c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_TV] = {
480c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE7,
490c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO8,
500c0d06caSMauro Carvalho Chehab 	},
510c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
520c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE3,
530c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
540c0d06caSMauro Carvalho Chehab 	},
550c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = {
560c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE3,
570c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
580c0d06caSMauro Carvalho Chehab 	},
590c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO] = {
600c0d06caSMauro Carvalho Chehab 		.vid = CX25840_SVIDEO1,
610c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
620c0d06caSMauro Carvalho Chehab 	},
630c0d06caSMauro Carvalho Chehab };
640c0d06caSMauro Carvalho Chehab 
650c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_def0 = {
660c0d06caSMauro Carvalho Chehab 	.def = routing_scheme0,
670c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_scheme0),
680c0d06caSMauro Carvalho Chehab };
690c0d06caSMauro Carvalho Chehab 
700c0d06caSMauro Carvalho Chehab /* Specific to gotview device */
710c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_schemegv[] = {
720c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_TV] = {
730c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE2,
740c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO5,
750c0d06caSMauro Carvalho Chehab 	},
760c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_RADIO] = {
770c0d06caSMauro Carvalho Chehab 		/* line-in is used for radio and composite.  A GPIO is
780c0d06caSMauro Carvalho Chehab 		   used to switch between the two choices. */
790c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE1,
800c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
810c0d06caSMauro Carvalho Chehab 	},
820c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = {
830c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE1,
840c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
850c0d06caSMauro Carvalho Chehab 	},
860c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO] = {
870c0d06caSMauro Carvalho Chehab 		.vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
880c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
890c0d06caSMauro Carvalho Chehab 	},
900c0d06caSMauro Carvalho Chehab };
910c0d06caSMauro Carvalho Chehab 
920c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_defgv = {
930c0d06caSMauro Carvalho Chehab 	.def = routing_schemegv,
940c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_schemegv),
950c0d06caSMauro Carvalho Chehab };
960c0d06caSMauro Carvalho Chehab 
970c0d06caSMauro Carvalho Chehab /* Specific to grabster av400 device */
980c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_schemeav400[] = {
990c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = {
1000c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE1,
1010c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
1020c0d06caSMauro Carvalho Chehab 	},
1030c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO] = {
1040c0d06caSMauro Carvalho Chehab 		.vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
1050c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
1060c0d06caSMauro Carvalho Chehab 	},
1070c0d06caSMauro Carvalho Chehab };
1080c0d06caSMauro Carvalho Chehab 
1090c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_defav400 = {
1100c0d06caSMauro Carvalho Chehab 	.def = routing_schemeav400,
1110c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_schemeav400),
1120c0d06caSMauro Carvalho Chehab };
1130c0d06caSMauro Carvalho Chehab 
114*dd60bf43SBrad Love static const struct routing_scheme_item routing_scheme160xxx[] = {
115*dd60bf43SBrad Love 	[PVR2_CVAL_INPUT_TV] = {
116*dd60bf43SBrad Love 		.vid = CX25840_COMPOSITE7,
117*dd60bf43SBrad Love 		.aud = CX25840_AUDIO8,
118*dd60bf43SBrad Love 	},
119*dd60bf43SBrad Love 	[PVR2_CVAL_INPUT_RADIO] = {
120*dd60bf43SBrad Love 		.vid = CX25840_COMPOSITE4,
121*dd60bf43SBrad Love 		.aud = CX25840_AUDIO6,
122*dd60bf43SBrad Love 	},
123*dd60bf43SBrad Love 	[PVR2_CVAL_INPUT_COMPOSITE] = {
124*dd60bf43SBrad Love 		.vid = CX25840_COMPOSITE3,
125*dd60bf43SBrad Love 		.aud = CX25840_AUDIO_SERIAL,
126*dd60bf43SBrad Love 	},
127*dd60bf43SBrad Love 	[PVR2_CVAL_INPUT_SVIDEO] = {
128*dd60bf43SBrad Love 		.vid = CX25840_SVIDEO1,
129*dd60bf43SBrad Love 		.aud = CX25840_AUDIO_SERIAL,
130*dd60bf43SBrad Love 	},
131*dd60bf43SBrad Love };
132*dd60bf43SBrad Love 
133*dd60bf43SBrad Love static const struct routing_scheme routing_def160xxx = {
134*dd60bf43SBrad Love 	.def = routing_scheme160xxx,
135*dd60bf43SBrad Love 	.cnt = ARRAY_SIZE(routing_scheme160xxx),
136*dd60bf43SBrad Love };
137*dd60bf43SBrad Love 
1380c0d06caSMauro Carvalho Chehab static const struct routing_scheme *routing_schemes[] = {
1390c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
1400c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
1410c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
142*dd60bf43SBrad Love 	[PVR2_ROUTING_SCHEME_HAUP160XXX] = &routing_def160xxx,
1430c0d06caSMauro Carvalho Chehab };
1440c0d06caSMauro Carvalho Chehab 
1450c0d06caSMauro Carvalho Chehab void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
1460c0d06caSMauro Carvalho Chehab {
1470c0d06caSMauro Carvalho Chehab 	pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
1480c0d06caSMauro Carvalho Chehab 	if (hdw->input_dirty || hdw->force_dirty) {
1490c0d06caSMauro Carvalho Chehab 		enum cx25840_video_input vid_input;
1500c0d06caSMauro Carvalho Chehab 		enum cx25840_audio_input aud_input;
1510c0d06caSMauro Carvalho Chehab 		const struct routing_scheme *sp;
1520c0d06caSMauro Carvalho Chehab 		unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
1530c0d06caSMauro Carvalho Chehab 
1540c0d06caSMauro Carvalho Chehab 		sp = (sid < ARRAY_SIZE(routing_schemes)) ?
1550c0d06caSMauro Carvalho Chehab 			routing_schemes[sid] : NULL;
1560c0d06caSMauro Carvalho Chehab 		if ((sp == NULL) ||
1570c0d06caSMauro Carvalho Chehab 		    (hdw->input_val < 0) ||
1580c0d06caSMauro Carvalho Chehab 		    (hdw->input_val >= sp->cnt)) {
1590c0d06caSMauro Carvalho Chehab 			pvr2_trace(PVR2_TRACE_ERROR_LEGS,
16096292c89SMauro Carvalho Chehab 				   "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)",
1610c0d06caSMauro Carvalho Chehab 				   sid, hdw->input_val);
1620c0d06caSMauro Carvalho Chehab 			return;
1630c0d06caSMauro Carvalho Chehab 		}
1640c0d06caSMauro Carvalho Chehab 		vid_input = sp->def[hdw->input_val].vid;
1650c0d06caSMauro Carvalho Chehab 		aud_input = sp->def[hdw->input_val].aud;
1660c0d06caSMauro Carvalho Chehab 		pvr2_trace(PVR2_TRACE_CHIPS,
1670c0d06caSMauro Carvalho Chehab 			   "subdev cx2584x set_input vid=0x%x aud=0x%x",
1680c0d06caSMauro Carvalho Chehab 			   vid_input, aud_input);
1690c0d06caSMauro Carvalho Chehab 		sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
1700c0d06caSMauro Carvalho Chehab 		sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
1710c0d06caSMauro Carvalho Chehab 	}
1720c0d06caSMauro Carvalho Chehab }
173