V4L/DVB (11194): pvrusb2: Implement mechanism to force a full sub-device update
[linux-2.6/linux-2.6-openrd.git] / drivers / media / video / pvrusb2 / pvrusb2-audio.c
blobaca6b1d1561a9d756beba61b24fc4cb689eb4d29
1 /*
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "pvrusb2-audio.h"
23 #include "pvrusb2-hdw-internal.h"
24 #include "pvrusb2-debug.h"
25 #include <linux/videodev2.h>
26 #include <media/msp3400.h>
27 #include <media/v4l2-common.h>
30 struct routing_scheme {
31 const int *def;
32 unsigned int cnt;
35 static const int routing_scheme0[] = {
36 [PVR2_CVAL_INPUT_TV] = MSP_INPUT_DEFAULT,
37 [PVR2_CVAL_INPUT_RADIO] = MSP_INPUT(MSP_IN_SCART2,
38 MSP_IN_TUNER1,
39 MSP_DSP_IN_SCART,
40 MSP_DSP_IN_SCART),
41 [PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1,
42 MSP_IN_TUNER1,
43 MSP_DSP_IN_SCART,
44 MSP_DSP_IN_SCART),
45 [PVR2_CVAL_INPUT_SVIDEO] = MSP_INPUT(MSP_IN_SCART1,
46 MSP_IN_TUNER1,
47 MSP_DSP_IN_SCART,
48 MSP_DSP_IN_SCART),
51 static const struct routing_scheme routing_schemes[] = {
52 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
53 .def = routing_scheme0,
54 .cnt = ARRAY_SIZE(routing_scheme0),
59 struct pvr2_msp3400_handler {
60 struct pvr2_hdw *hdw;
61 struct pvr2_i2c_client *client;
62 struct pvr2_i2c_handler i2c_handler;
63 unsigned long stale_mask;
69 /* This function selects the correct audio input source */
70 static void set_stereo(struct pvr2_msp3400_handler *ctxt)
72 struct pvr2_hdw *hdw = ctxt->hdw;
73 struct v4l2_routing route;
74 const struct routing_scheme *sp;
75 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
77 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
79 if ((sid < ARRAY_SIZE(routing_schemes)) &&
80 ((sp = routing_schemes + sid) != NULL) &&
81 (hdw->input_val >= 0) &&
82 (hdw->input_val < sp->cnt)) {
83 route.input = sp->def[hdw->input_val];
84 } else {
85 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
86 "*** WARNING *** i2c msp3400 v4l2 set_stereo:"
87 " Invalid routing scheme (%u) and/or input (%d)",
88 sid,hdw->input_val);
89 return;
91 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
92 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
96 static int check_stereo(struct pvr2_msp3400_handler *ctxt)
98 struct pvr2_hdw *hdw = ctxt->hdw;
99 return hdw->input_dirty;
103 struct pvr2_msp3400_ops {
104 void (*update)(struct pvr2_msp3400_handler *);
105 int (*check)(struct pvr2_msp3400_handler *);
109 static const struct pvr2_msp3400_ops msp3400_ops[] = {
110 { .update = set_stereo, .check = check_stereo},
114 static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
116 unsigned long msk;
117 unsigned int idx;
119 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
120 msk = 1 << idx;
121 if (ctxt->stale_mask & msk) continue;
122 if (msp3400_ops[idx].check(ctxt)) {
123 ctxt->stale_mask |= msk;
126 return ctxt->stale_mask != 0;
130 static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
132 unsigned long msk;
133 unsigned int idx;
135 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
136 msk = 1 << idx;
137 if (!(ctxt->stale_mask & msk)) continue;
138 ctxt->stale_mask &= ~msk;
139 msp3400_ops[idx].update(ctxt);
144 static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
146 ctxt->client->handler = NULL;
147 kfree(ctxt);
151 static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
152 char *buf,unsigned int cnt)
154 return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2");
158 static const struct pvr2_i2c_handler_functions msp3400_funcs = {
159 .detach = (void (*)(void *))pvr2_msp3400_detach,
160 .check = (int (*)(void *))msp3400_check,
161 .update = (void (*)(void *))msp3400_update,
162 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_msp3400_describe,
166 int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
168 struct pvr2_msp3400_handler *ctxt;
169 if (cp->handler) return 0;
171 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
172 if (!ctxt) return 0;
174 ctxt->i2c_handler.func_data = ctxt;
175 ctxt->i2c_handler.func_table = &msp3400_funcs;
176 ctxt->client = cp;
177 ctxt->hdw = hdw;
178 ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
179 cp->handler = &ctxt->i2c_handler;
180 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
181 cp->client->addr);
182 return !0;
185 void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
187 if (hdw->input_dirty || hdw->force_dirty) {
188 struct v4l2_routing route;
189 const struct routing_scheme *sp;
190 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
192 pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
194 if ((sid < ARRAY_SIZE(routing_schemes)) &&
195 ((sp = routing_schemes + sid) != NULL) &&
196 (hdw->input_val >= 0) &&
197 (hdw->input_val < sp->cnt)) {
198 route.input = sp->def[hdw->input_val];
199 } else {
200 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
201 "*** WARNING *** subdev msp3400 set_input:"
202 " Invalid routing scheme (%u)"
203 " and/or input (%d)",
204 sid, hdw->input_val);
205 return;
207 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
208 sd->ops->audio->s_routing(sd, &route);
213 Stuff for Emacs to see, in order to encourage consistent editing style:
214 *** Local Variables: ***
215 *** mode: c ***
216 *** fill-column: 70 ***
217 *** tab-width: 8 ***
218 *** c-basic-offset: 8 ***
219 *** End: ***