xref: /linux/drivers/media/usb/pvrusb2/pvrusb2-audio.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
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 #include "pvrusb2-audio.h"
90c0d06caSMauro Carvalho Chehab #include "pvrusb2-hdw-internal.h"
100c0d06caSMauro Carvalho Chehab #include "pvrusb2-debug.h"
110c0d06caSMauro Carvalho Chehab #include <linux/videodev2.h>
12d647f0b7SMauro Carvalho Chehab #include <media/drv-intf/msp3400.h>
130c0d06caSMauro Carvalho Chehab #include <media/v4l2-common.h>
140c0d06caSMauro Carvalho Chehab 
150c0d06caSMauro Carvalho Chehab 
160c0d06caSMauro Carvalho Chehab struct routing_scheme {
170c0d06caSMauro Carvalho Chehab 	const int *def;
180c0d06caSMauro Carvalho Chehab 	unsigned int cnt;
190c0d06caSMauro Carvalho Chehab };
200c0d06caSMauro Carvalho Chehab 
210c0d06caSMauro Carvalho Chehab static const int routing_scheme0[] = {
220c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_TV]        = MSP_INPUT_DEFAULT,
230c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_RADIO]     = MSP_INPUT(MSP_IN_SCART2,
240c0d06caSMauro Carvalho Chehab 						MSP_IN_TUNER1,
250c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART,
260c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART),
270c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1,
280c0d06caSMauro Carvalho Chehab 						MSP_IN_TUNER1,
290c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART,
300c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART),
310c0d06caSMauro Carvalho Chehab 	[PVR2_CVAL_INPUT_SVIDEO]    = MSP_INPUT(MSP_IN_SCART1,
320c0d06caSMauro Carvalho Chehab 						MSP_IN_TUNER1,
330c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART,
340c0d06caSMauro Carvalho Chehab 						MSP_DSP_IN_SCART),
350c0d06caSMauro Carvalho Chehab };
360c0d06caSMauro Carvalho Chehab 
370c0d06caSMauro Carvalho Chehab static const struct routing_scheme routing_def0 = {
380c0d06caSMauro Carvalho Chehab 	.def = routing_scheme0,
390c0d06caSMauro Carvalho Chehab 	.cnt = ARRAY_SIZE(routing_scheme0),
400c0d06caSMauro Carvalho Chehab };
410c0d06caSMauro Carvalho Chehab 
420c0d06caSMauro Carvalho Chehab static const struct routing_scheme *routing_schemes[] = {
430c0d06caSMauro Carvalho Chehab 	[PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
440c0d06caSMauro Carvalho Chehab };
450c0d06caSMauro Carvalho Chehab 
pvr2_msp3400_subdev_update(struct pvr2_hdw * hdw,struct v4l2_subdev * sd)460c0d06caSMauro Carvalho Chehab void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
470c0d06caSMauro Carvalho Chehab {
480c0d06caSMauro Carvalho Chehab 	if (hdw->input_dirty || hdw->force_dirty) {
490c0d06caSMauro Carvalho Chehab 		const struct routing_scheme *sp;
500c0d06caSMauro Carvalho Chehab 		unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
510c0d06caSMauro Carvalho Chehab 		u32 input;
520c0d06caSMauro Carvalho Chehab 
530c0d06caSMauro Carvalho Chehab 		pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
540c0d06caSMauro Carvalho Chehab 		sp = (sid < ARRAY_SIZE(routing_schemes)) ?
550c0d06caSMauro Carvalho Chehab 			routing_schemes[sid] : NULL;
560c0d06caSMauro Carvalho Chehab 
570c0d06caSMauro Carvalho Chehab 		if ((sp != NULL) &&
580c0d06caSMauro Carvalho Chehab 		    (hdw->input_val >= 0) &&
590c0d06caSMauro Carvalho Chehab 		    (hdw->input_val < sp->cnt)) {
600c0d06caSMauro Carvalho Chehab 			input = sp->def[hdw->input_val];
610c0d06caSMauro Carvalho Chehab 		} else {
620c0d06caSMauro Carvalho Chehab 			pvr2_trace(PVR2_TRACE_ERROR_LEGS,
6396292c89SMauro Carvalho Chehab 				   "*** WARNING *** subdev msp3400 set_input: Invalid routing scheme (%u) and/or input (%d)",
640c0d06caSMauro Carvalho Chehab 				   sid, hdw->input_val);
650c0d06caSMauro Carvalho Chehab 			return;
660c0d06caSMauro Carvalho Chehab 		}
670c0d06caSMauro Carvalho Chehab 		sd->ops->audio->s_routing(sd, input,
680c0d06caSMauro Carvalho Chehab 			MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
690c0d06caSMauro Carvalho Chehab 	}
700c0d06caSMauro Carvalho Chehab }
71