xref: /linux/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c (revision 96292c89cf1fa700ba086fd7c0e431ac90adba10)
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  *  You should have received a copy of the GNU General Public License
170c0d06caSMauro Carvalho Chehab  *  along with this program; if not, write to the Free Software
180c0d06caSMauro Carvalho Chehab  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
190c0d06caSMauro Carvalho Chehab  *
200c0d06caSMauro Carvalho Chehab  */
210c0d06caSMauro Carvalho Chehab 
220c0d06caSMauro Carvalho Chehab /*
230c0d06caSMauro Carvalho Chehab 
240c0d06caSMauro Carvalho Chehab    This source file is specifically designed to interface with the
250c0d06caSMauro Carvalho Chehab    cx2584x, in kernels 2.6.16 or newer.
260c0d06caSMauro Carvalho Chehab 
270c0d06caSMauro Carvalho Chehab */
280c0d06caSMauro Carvalho Chehab 
290c0d06caSMauro Carvalho Chehab #include "pvrusb2-cx2584x-v4l.h"
300c0d06caSMauro Carvalho Chehab #include "pvrusb2-video-v4l.h"
310c0d06caSMauro Carvalho Chehab 
320c0d06caSMauro Carvalho Chehab 
330c0d06caSMauro Carvalho Chehab #include "pvrusb2-hdw-internal.h"
340c0d06caSMauro Carvalho Chehab #include "pvrusb2-debug.h"
35d647f0b7SMauro Carvalho Chehab #include <media/drv-intf/cx25840.h>
360c0d06caSMauro Carvalho Chehab #include <linux/videodev2.h>
370c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
380c0d06caSMauro Carvalho Chehab #include <linux/errno.h>
390c0d06caSMauro Carvalho Chehab 
400c0d06caSMauro Carvalho Chehab 
410c0d06caSMauro Carvalho Chehab struct routing_scheme_item {
420c0d06caSMauro Carvalho Chehab 	int vid;
430c0d06caSMauro Carvalho Chehab 	int aud;
440c0d06caSMauro Carvalho Chehab };
450c0d06caSMauro Carvalho Chehab 
460c0d06caSMauro Carvalho Chehab struct routing_scheme {
470c0d06caSMauro Carvalho Chehab 	const struct routing_scheme_item *def;
480c0d06caSMauro Carvalho Chehab 	unsigned int cnt;
490c0d06caSMauro Carvalho Chehab };
500c0d06caSMauro Carvalho Chehab 
510c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_scheme0[] = {
520c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_TV] = {
530c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE7,
540c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO8,
550c0d06caSMauro Carvalho Chehab 	},
560c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
570c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE3,
580c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
590c0d06caSMauro Carvalho Chehab 	},
600c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = {
610c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE3,
620c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
630c0d06caSMauro Carvalho Chehab 	},
640c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO] = {
650c0d06caSMauro Carvalho Chehab 		.vid = CX25840_SVIDEO1,
660c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
670c0d06caSMauro Carvalho Chehab 	},
680c0d06caSMauro Carvalho Chehab };
690c0d06caSMauro Carvalho Chehab 
700c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_def0 = {
710c0d06caSMauro Carvalho Chehab 	.def = routing_scheme0,
720c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_scheme0),
730c0d06caSMauro Carvalho Chehab };
740c0d06caSMauro Carvalho Chehab 
750c0d06caSMauro Carvalho Chehab /* Specific to gotview device */
760c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_schemegv[] = {
770c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_TV] = {
780c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE2,
790c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO5,
800c0d06caSMauro Carvalho Chehab 	},
810c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_RADIO] = {
820c0d06caSMauro Carvalho Chehab 		/* line-in is used for radio and composite.  A GPIO is
830c0d06caSMauro Carvalho Chehab 		   used to switch between the two choices. */
840c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE1,
850c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
860c0d06caSMauro Carvalho Chehab 	},
870c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = {
880c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE1,
890c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
900c0d06caSMauro Carvalho Chehab 	},
910c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO] = {
920c0d06caSMauro Carvalho Chehab 		.vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
930c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
940c0d06caSMauro Carvalho Chehab 	},
950c0d06caSMauro Carvalho Chehab };
960c0d06caSMauro Carvalho Chehab 
970c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_defgv = {
980c0d06caSMauro Carvalho Chehab 	.def = routing_schemegv,
990c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_schemegv),
1000c0d06caSMauro Carvalho Chehab };
1010c0d06caSMauro Carvalho Chehab 
1020c0d06caSMauro Carvalho Chehab /* Specific to grabster av400 device */
1030c0d06caSMauro Carvalho Chehab static const struct routing_scheme_item routing_schemeav400[] = {
1040c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = {
1050c0d06caSMauro Carvalho Chehab 		.vid = CX25840_COMPOSITE1,
1060c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
1070c0d06caSMauro Carvalho Chehab 	},
1080c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO] = {
1090c0d06caSMauro Carvalho Chehab 		.vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
1100c0d06caSMauro Carvalho Chehab 		.aud = CX25840_AUDIO_SERIAL,
1110c0d06caSMauro Carvalho Chehab 	},
1120c0d06caSMauro Carvalho Chehab };
1130c0d06caSMauro Carvalho Chehab 
1140c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_defav400 = {
1150c0d06caSMauro Carvalho Chehab 	.def = routing_schemeav400,
1160c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_schemeav400),
1170c0d06caSMauro Carvalho Chehab };
1180c0d06caSMauro Carvalho Chehab 
1190c0d06caSMauro Carvalho Chehab static const struct routing_scheme *routing_schemes[] = {
1200c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
1210c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
1220c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
1230c0d06caSMauro Carvalho Chehab };
1240c0d06caSMauro Carvalho Chehab 
1250c0d06caSMauro Carvalho Chehab void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
1260c0d06caSMauro Carvalho Chehab {
1270c0d06caSMauro Carvalho Chehab 	pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
1280c0d06caSMauro Carvalho Chehab 	if (hdw->input_dirty || hdw->force_dirty) {
1290c0d06caSMauro Carvalho Chehab 		enum cx25840_video_input vid_input;
1300c0d06caSMauro Carvalho Chehab 		enum cx25840_audio_input aud_input;
1310c0d06caSMauro Carvalho Chehab 		const struct routing_scheme *sp;
1320c0d06caSMauro Carvalho Chehab 		unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
1330c0d06caSMauro Carvalho Chehab 
1340c0d06caSMauro Carvalho Chehab 		sp = (sid < ARRAY_SIZE(routing_schemes)) ?
1350c0d06caSMauro Carvalho Chehab 			routing_schemes[sid] : NULL;
1360c0d06caSMauro Carvalho Chehab 		if ((sp == NULL) ||
1370c0d06caSMauro Carvalho Chehab 		    (hdw->input_val < 0) ||
1380c0d06caSMauro Carvalho Chehab 		    (hdw->input_val >= sp->cnt)) {
1390c0d06caSMauro Carvalho Chehab 			pvr2_trace(PVR2_TRACE_ERROR_LEGS,
140*96292c89SMauro Carvalho Chehab 				   "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)",
1410c0d06caSMauro Carvalho Chehab 				   sid, hdw->input_val);
1420c0d06caSMauro Carvalho Chehab 			return;
1430c0d06caSMauro Carvalho Chehab 		}
1440c0d06caSMauro Carvalho Chehab 		vid_input = sp->def[hdw->input_val].vid;
1450c0d06caSMauro Carvalho Chehab 		aud_input = sp->def[hdw->input_val].aud;
1460c0d06caSMauro Carvalho Chehab 		pvr2_trace(PVR2_TRACE_CHIPS,
1470c0d06caSMauro Carvalho Chehab 			   "subdev cx2584x set_input vid=0x%x aud=0x%x",
1480c0d06caSMauro Carvalho Chehab 			   vid_input, aud_input);
1490c0d06caSMauro Carvalho Chehab 		sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
1500c0d06caSMauro Carvalho Chehab 		sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
1510c0d06caSMauro Carvalho Chehab 	}
1520c0d06caSMauro Carvalho Chehab }
153