blob: cdedaa55f152de97549d455ff2edf01bb3d3219c [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
Mike Iselyd8554972006-06-26 20:58:46 -03003 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6 *
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
10 *
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.
15 *
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
19 *
20 */
21
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>
28
29struct pvr2_msp3400_handler {
30 struct pvr2_hdw *hdw;
31 struct pvr2_i2c_client *client;
32 struct pvr2_i2c_handler i2c_handler;
Mike Iselyd8554972006-06-26 20:58:46 -030033 unsigned long stale_mask;
34};
35
36
Mike Iselyf5174af2007-11-26 02:07:26 -030037
38struct routing_scheme {
39 const int *def;
40 unsigned int cnt;
41};
42
43static const int routing_scheme0[] = {
44 [PVR2_CVAL_INPUT_TV] = MSP_INPUT_DEFAULT,
45 [PVR2_CVAL_INPUT_RADIO] = MSP_INPUT(MSP_IN_SCART2,
46 MSP_IN_TUNER1,
47 MSP_DSP_IN_SCART,
48 MSP_DSP_IN_SCART),
49 [PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1,
50 MSP_IN_TUNER1,
51 MSP_DSP_IN_SCART,
52 MSP_DSP_IN_SCART),
53 [PVR2_CVAL_INPUT_SVIDEO] = MSP_INPUT(MSP_IN_SCART1,
54 MSP_IN_TUNER1,
55 MSP_DSP_IN_SCART,
56 MSP_DSP_IN_SCART),
57};
58
59static const struct routing_scheme routing_schemes[] = {
60 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
61 .def = routing_scheme0,
62 .cnt = ARRAY_SIZE(routing_scheme0),
63 },
64};
65
Mike Iselyd8554972006-06-26 20:58:46 -030066/* This function selects the correct audio input source */
67static void set_stereo(struct pvr2_msp3400_handler *ctxt)
68{
69 struct pvr2_hdw *hdw = ctxt->hdw;
70 struct v4l2_routing route;
Mike Iselyf5174af2007-11-26 02:07:26 -030071 const struct routing_scheme *sp;
72 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
Mike Iselyd8554972006-06-26 20:58:46 -030073
74 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
75
Mike Iselyf5174af2007-11-26 02:07:26 -030076 if ((sid < ARRAY_SIZE(routing_schemes)) &&
Harvey Harrisona6a3a172008-04-28 16:50:03 -070077 ((sp = routing_schemes + sid) != NULL) &&
Mike Iselyf5174af2007-11-26 02:07:26 -030078 (hdw->input_val >= 0) &&
79 (hdw->input_val < sp->cnt)) {
80 route.input = sp->def[hdw->input_val];
81 } else {
82 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
83 "*** WARNING *** i2c msp3400 v4l2 set_stereo:"
84 " Invalid routing scheme (%u) and/or input (%d)",
85 sid,hdw->input_val);
86 return;
Mike Iselyd8554972006-06-26 20:58:46 -030087 }
Mike Iselyf5174af2007-11-26 02:07:26 -030088 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
Mike Iselyd8554972006-06-26 20:58:46 -030089 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
90}
91
92
93static int check_stereo(struct pvr2_msp3400_handler *ctxt)
94{
95 struct pvr2_hdw *hdw = ctxt->hdw;
Mike Isely606cf9c2007-01-20 01:56:04 -030096 return hdw->input_dirty;
Mike Iselyd8554972006-06-26 20:58:46 -030097}
98
99
100struct pvr2_msp3400_ops {
101 void (*update)(struct pvr2_msp3400_handler *);
102 int (*check)(struct pvr2_msp3400_handler *);
103};
104
105
106static const struct pvr2_msp3400_ops msp3400_ops[] = {
107 { .update = set_stereo, .check = check_stereo},
108};
109
110
111static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
112{
113 unsigned long msk;
114 unsigned int idx;
115
Mike Isely27c7b712007-01-20 00:39:17 -0300116 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
Mike Iselyd8554972006-06-26 20:58:46 -0300117 msk = 1 << idx;
118 if (ctxt->stale_mask & msk) continue;
119 if (msp3400_ops[idx].check(ctxt)) {
120 ctxt->stale_mask |= msk;
121 }
122 }
123 return ctxt->stale_mask != 0;
124}
125
126
127static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
128{
129 unsigned long msk;
130 unsigned int idx;
131
Mike Isely27c7b712007-01-20 00:39:17 -0300132 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
Mike Iselyd8554972006-06-26 20:58:46 -0300133 msk = 1 << idx;
134 if (!(ctxt->stale_mask & msk)) continue;
135 ctxt->stale_mask &= ~msk;
136 msp3400_ops[idx].update(ctxt);
137 }
138}
139
140
Mike Iselyd8554972006-06-26 20:58:46 -0300141static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
142{
Mike Iselya0fd1cb2006-06-30 11:35:28 -0300143 ctxt->client->handler = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -0300144 kfree(ctxt);
145}
146
147
148static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
149 char *buf,unsigned int cnt)
150{
151 return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2");
152}
153
154
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100155static const struct pvr2_i2c_handler_functions msp3400_funcs = {
Mike Iselyd8554972006-06-26 20:58:46 -0300156 .detach = (void (*)(void *))pvr2_msp3400_detach,
157 .check = (int (*)(void *))msp3400_check,
158 .update = (void (*)(void *))msp3400_update,
159 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_msp3400_describe,
160};
161
162
163int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
164{
165 struct pvr2_msp3400_handler *ctxt;
Mike Iselyd8554972006-06-26 20:58:46 -0300166 if (cp->handler) return 0;
167
Mike Iselyca545f72007-01-20 00:37:11 -0300168 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -0300169 if (!ctxt) return 0;
Mike Iselyd8554972006-06-26 20:58:46 -0300170
171 ctxt->i2c_handler.func_data = ctxt;
172 ctxt->i2c_handler.func_table = &msp3400_funcs;
173 ctxt->client = cp;
174 ctxt->hdw = hdw;
Mike Isely27c7b712007-01-20 00:39:17 -0300175 ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
Mike Iselyd8554972006-06-26 20:58:46 -0300176 cp->handler = &ctxt->i2c_handler;
Mike Iselyd8554972006-06-26 20:58:46 -0300177 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
178 cp->client->addr);
179 return !0;
180}
181
182
183/*
184 Stuff for Emacs to see, in order to encourage consistent editing style:
185 *** Local Variables: ***
186 *** mode: c ***
187 *** fill-column: 70 ***
188 *** tab-width: 8 ***
189 *** c-basic-offset: 8 ***
190 *** End: ***
191 */