xref: /linux/drivers/media/usb/pvrusb2/pvrusb2-audio.c (revision 0c0d06cac63ee327ceaab4b5ffe2206574ab86bd)
1*0c0d06caSMauro Carvalho Chehab /*
2*0c0d06caSMauro Carvalho Chehab  *
3*0c0d06caSMauro Carvalho Chehab  *
4*0c0d06caSMauro Carvalho Chehab  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
5*0c0d06caSMauro Carvalho Chehab  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6*0c0d06caSMauro Carvalho Chehab  *
7*0c0d06caSMauro Carvalho Chehab  *  This program is free software; you can redistribute it and/or modify
8*0c0d06caSMauro Carvalho Chehab  *  it under the terms of the GNU General Public License as published by
9*0c0d06caSMauro Carvalho Chehab  *  the Free Software Foundation; either version 2 of the License
10*0c0d06caSMauro Carvalho Chehab  *
11*0c0d06caSMauro Carvalho Chehab  *  This program is distributed in the hope that it will be useful,
12*0c0d06caSMauro Carvalho Chehab  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13*0c0d06caSMauro Carvalho Chehab  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*0c0d06caSMauro Carvalho Chehab  *  GNU General Public License for more details.
15*0c0d06caSMauro Carvalho Chehab  *
16*0c0d06caSMauro Carvalho Chehab  *  You should have received a copy of the GNU General Public License
17*0c0d06caSMauro Carvalho Chehab  *  along with this program; if not, write to the Free Software
18*0c0d06caSMauro Carvalho Chehab  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19*0c0d06caSMauro Carvalho Chehab  *
20*0c0d06caSMauro Carvalho Chehab  */
21*0c0d06caSMauro Carvalho Chehab 
22*0c0d06caSMauro Carvalho Chehab #include "pvrusb2-audio.h"
23*0c0d06caSMauro Carvalho Chehab #include "pvrusb2-hdw-internal.h"
24*0c0d06caSMauro Carvalho Chehab #include "pvrusb2-debug.h"
25*0c0d06caSMauro Carvalho Chehab #include <linux/videodev2.h>
26*0c0d06caSMauro Carvalho Chehab #include <media/msp3400.h>
27*0c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
28*0c0d06caSMauro Carvalho Chehab 
29*0c0d06caSMauro Carvalho Chehab 
30*0c0d06caSMauro Carvalho Chehab struct routing_scheme {
31*0c0d06caSMauro Carvalho Chehab 	const int *def;
32*0c0d06caSMauro Carvalho Chehab 	unsigned int cnt;
33*0c0d06caSMauro Carvalho Chehab };
34*0c0d06caSMauro Carvalho Chehab 
35*0c0d06caSMauro Carvalho Chehab static const int routing_scheme0[] = {
36*0c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_TV]        = MSP_INPUT_DEFAULT,
37*0c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_RADIO]     = MSP_INPUT(MSP_IN_SCART2,
38*0c0d06caSMauro Carvalho Chehab 						MSP_IN_TUNER1,
39*0c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART,
40*0c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART),
41*0c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1,
42*0c0d06caSMauro Carvalho Chehab 						MSP_IN_TUNER1,
43*0c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART,
44*0c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART),
45*0c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO]    = MSP_INPUT(MSP_IN_SCART1,
46*0c0d06caSMauro Carvalho Chehab 						MSP_IN_TUNER1,
47*0c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART,
48*0c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART),
49*0c0d06caSMauro Carvalho Chehab };
50*0c0d06caSMauro Carvalho Chehab 
51*0c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_def0 = {
52*0c0d06caSMauro Carvalho Chehab 	.def = routing_scheme0,
53*0c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_scheme0),
54*0c0d06caSMauro Carvalho Chehab };
55*0c0d06caSMauro Carvalho Chehab 
56*0c0d06caSMauro Carvalho Chehab static const struct routing_scheme *routing_schemes[] = {
57*0c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
58*0c0d06caSMauro Carvalho Chehab };
59*0c0d06caSMauro Carvalho Chehab 
60*0c0d06caSMauro Carvalho Chehab void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
61*0c0d06caSMauro Carvalho Chehab {
62*0c0d06caSMauro Carvalho Chehab 	if (hdw->input_dirty || hdw->force_dirty) {
63*0c0d06caSMauro Carvalho Chehab 		const struct routing_scheme *sp;
64*0c0d06caSMauro Carvalho Chehab 		unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
65*0c0d06caSMauro Carvalho Chehab 		u32 input;
66*0c0d06caSMauro Carvalho Chehab 
67*0c0d06caSMauro Carvalho Chehab 		pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
68*0c0d06caSMauro Carvalho Chehab 		sp = (sid < ARRAY_SIZE(routing_schemes)) ?
69*0c0d06caSMauro Carvalho Chehab 			routing_schemes[sid] : NULL;
70*0c0d06caSMauro Carvalho Chehab 
71*0c0d06caSMauro Carvalho Chehab 		if ((sp != NULL) &&
72*0c0d06caSMauro Carvalho Chehab 		    (hdw->input_val >= 0) &&
73*0c0d06caSMauro Carvalho Chehab 		    (hdw->input_val < sp->cnt)) {
74*0c0d06caSMauro Carvalho Chehab 			input = sp->def[hdw->input_val];
75*0c0d06caSMauro Carvalho Chehab 		} else {
76*0c0d06caSMauro Carvalho Chehab 			pvr2_trace(PVR2_TRACE_ERROR_LEGS,
77*0c0d06caSMauro Carvalho Chehab 				   "*** WARNING *** subdev msp3400 set_input:"
78*0c0d06caSMauro Carvalho Chehab 				   " Invalid routing scheme (%u)"
79*0c0d06caSMauro Carvalho Chehab 				   " and/or input (%d)",
80*0c0d06caSMauro Carvalho Chehab 				   sid, hdw->input_val);
81*0c0d06caSMauro Carvalho Chehab 			return;
82*0c0d06caSMauro Carvalho Chehab 		}
83*0c0d06caSMauro Carvalho Chehab 		sd->ops->audio->s_routing(sd, input,
84*0c0d06caSMauro Carvalho Chehab 			MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
85*0c0d06caSMauro Carvalho Chehab 	}
86*0c0d06caSMauro Carvalho Chehab }
87*0c0d06caSMauro Carvalho Chehab 
88*0c0d06caSMauro Carvalho Chehab /*
89*0c0d06caSMauro Carvalho Chehab   Stuff for Emacs to see, in order to encourage consistent editing style:
90*0c0d06caSMauro Carvalho Chehab   *** Local Variables: ***
91*0c0d06caSMauro Carvalho Chehab   *** mode: c ***
92*0c0d06caSMauro Carvalho Chehab   *** fill-column: 70 ***
93*0c0d06caSMauro Carvalho Chehab   *** tab-width: 8 ***
94*0c0d06caSMauro Carvalho Chehab   *** c-basic-offset: 8 ***
95*0c0d06caSMauro Carvalho Chehab   *** End: ***
96*0c0d06caSMauro Carvalho Chehab   */
97