xref: /linux/drivers/media/usb/pvrusb2/pvrusb2-audio.c (revision 95298d63c67673c654c08952672d016212b26054)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *
4  *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
5  *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6  */
7 
8 #include "pvrusb2-audio.h"
9 #include "pvrusb2-hdw-internal.h"
10 #include "pvrusb2-debug.h"
11 #include <linux/videodev2.h>
12 #include <media/drv-intf/msp3400.h>
13 #include <media/v4l2-common.h>
14 
15 
16 struct routing_scheme {
17 	const int *def;
18 	unsigned int cnt;
19 };
20 
21 static const int routing_scheme0[] = {
22 	[PVR2_CVAL_INPUT_TV]        = MSP_INPUT_DEFAULT,
23 	[PVR2_CVAL_INPUT_RADIO]     = MSP_INPUT(MSP_IN_SCART2,
24 						MSP_IN_TUNER1,
25 						MSP_DSP_IN_SCART,
26 						MSP_DSP_IN_SCART),
27 	[PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1,
28 						MSP_IN_TUNER1,
29 						MSP_DSP_IN_SCART,
30 						MSP_DSP_IN_SCART),
31 	[PVR2_CVAL_INPUT_SVIDEO]    = MSP_INPUT(MSP_IN_SCART1,
32 						MSP_IN_TUNER1,
33 						MSP_DSP_IN_SCART,
34 						MSP_DSP_IN_SCART),
35 };
36 
37 static const struct routing_scheme routing_def0 = {
38 	.def = routing_scheme0,
39 	.cnt = ARRAY_SIZE(routing_scheme0),
40 };
41 
42 static const struct routing_scheme *routing_schemes[] = {
43 	[PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
44 };
45 
46 void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
47 {
48 	if (hdw->input_dirty || hdw->force_dirty) {
49 		const struct routing_scheme *sp;
50 		unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
51 		u32 input;
52 
53 		pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
54 		sp = (sid < ARRAY_SIZE(routing_schemes)) ?
55 			routing_schemes[sid] : NULL;
56 
57 		if ((sp != NULL) &&
58 		    (hdw->input_val >= 0) &&
59 		    (hdw->input_val < sp->cnt)) {
60 			input = sp->def[hdw->input_val];
61 		} else {
62 			pvr2_trace(PVR2_TRACE_ERROR_LEGS,
63 				   "*** WARNING *** subdev msp3400 set_input: Invalid routing scheme (%u) and/or input (%d)",
64 				   sid, hdw->input_val);
65 			return;
66 		}
67 		sd->ops->audio->s_routing(sd, input,
68 			MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
69 	}
70 }
71