~ubuntu-branches/ubuntu/lucid/linux-rt/lucid

« back to all changes in this revision

Viewing changes to drivers/media/video/pvrusb2/pvrusb2-audio.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2009-08-05 23:00:52 UTC
  • Revision ID: james.westby@ubuntu.com-20090805230052-7xedvqcyk9dnnxb2
Tags: 2.6.31-1.1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <media/msp3400.h>
27
27
#include <media/v4l2-common.h>
28
28
 
29
 
struct pvr2_msp3400_handler {
30
 
        struct pvr2_hdw *hdw;
31
 
        struct pvr2_i2c_client *client;
32
 
        struct pvr2_i2c_handler i2c_handler;
33
 
        unsigned long stale_mask;
34
 
};
35
 
 
36
 
 
37
29
 
38
30
struct routing_scheme {
39
31
        const int *def;
56
48
                                                MSP_DSP_IN_SCART),
57
49
};
58
50
 
59
 
static const struct routing_scheme routing_schemes[] = {
60
 
        [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
61
 
                .def = routing_scheme0,
62
 
                .cnt = ARRAY_SIZE(routing_scheme0),
63
 
        },
64
 
};
65
 
 
66
 
/* This function selects the correct audio input source */
67
 
static void set_stereo(struct pvr2_msp3400_handler *ctxt)
68
 
{
69
 
        struct pvr2_hdw *hdw = ctxt->hdw;
70
 
        struct v4l2_routing route;
71
 
        const struct routing_scheme *sp;
72
 
        unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
73
 
 
74
 
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
75
 
 
76
 
        if ((sid < ARRAY_SIZE(routing_schemes)) &&
77
 
            ((sp = routing_schemes + sid) != NULL) &&
78
 
            (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;
87
 
        }
88
 
        route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
89
 
        pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
90
 
}
91
 
 
92
 
 
93
 
static int check_stereo(struct pvr2_msp3400_handler *ctxt)
94
 
{
95
 
        struct pvr2_hdw *hdw = ctxt->hdw;
96
 
        return hdw->input_dirty;
97
 
}
98
 
 
99
 
 
100
 
struct pvr2_msp3400_ops {
101
 
        void (*update)(struct pvr2_msp3400_handler *);
102
 
        int (*check)(struct pvr2_msp3400_handler *);
103
 
};
104
 
 
105
 
 
106
 
static const struct pvr2_msp3400_ops msp3400_ops[] = {
107
 
        { .update = set_stereo, .check = check_stereo},
108
 
};
109
 
 
110
 
 
111
 
static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
112
 
{
113
 
        unsigned long msk;
114
 
        unsigned int idx;
115
 
 
116
 
        for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
117
 
                msk = 1 << idx;
118
 
                if (ctxt->stale_mask & msk) continue;
119
 
                if (msp3400_ops[idx].check(ctxt)) {
120
 
                        ctxt->stale_mask |= msk;
 
51
static const struct routing_scheme routing_def0 = {
 
52
        .def = routing_scheme0,
 
53
        .cnt = ARRAY_SIZE(routing_scheme0),
 
54
};
 
55
 
 
56
static const struct routing_scheme *routing_schemes[] = {
 
57
        [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
 
58
};
 
59
 
 
60
void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
 
61
{
 
62
        if (hdw->input_dirty || hdw->force_dirty) {
 
63
                const struct routing_scheme *sp;
 
64
                unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
 
65
                u32 input;
 
66
 
 
67
                pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
 
68
 
 
69
                if ((sid < ARRAY_SIZE(routing_schemes)) &&
 
70
                    ((sp = routing_schemes[sid]) != NULL) &&
 
71
                    (hdw->input_val >= 0) &&
 
72
                    (hdw->input_val < sp->cnt)) {
 
73
                        input = sp->def[hdw->input_val];
 
74
                } else {
 
75
                        pvr2_trace(PVR2_TRACE_ERROR_LEGS,
 
76
                                   "*** WARNING *** subdev msp3400 set_input:"
 
77
                                   " Invalid routing scheme (%u)"
 
78
                                   " and/or input (%d)",
 
79
                                   sid, hdw->input_val);
 
80
                        return;
121
81
                }
122
 
        }
123
 
        return ctxt->stale_mask != 0;
124
 
}
125
 
 
126
 
 
127
 
static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
128
 
{
129
 
        unsigned long msk;
130
 
        unsigned int idx;
131
 
 
132
 
        for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
133
 
                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
 
 
141
 
static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
142
 
{
143
 
        ctxt->client->handler = NULL;
144
 
        kfree(ctxt);
145
 
}
146
 
 
147
 
 
148
 
static 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
 
 
155
 
static const struct pvr2_i2c_handler_functions msp3400_funcs = {
156
 
        .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
 
 
163
 
int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
164
 
{
165
 
        struct pvr2_msp3400_handler *ctxt;
166
 
        if (cp->handler) return 0;
167
 
 
168
 
        ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
169
 
        if (!ctxt) return 0;
170
 
 
171
 
        ctxt->i2c_handler.func_data = ctxt;
172
 
        ctxt->i2c_handler.func_table = &msp3400_funcs;
173
 
        ctxt->client = cp;
174
 
        ctxt->hdw = hdw;
175
 
        ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
176
 
        cp->handler = &ctxt->i2c_handler;
177
 
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
178
 
                   cp->client->addr);
179
 
        return !0;
180
 
}
181
 
 
 
82
                sd->ops->audio->s_routing(sd, input,
 
83
                        MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
 
84
        }
 
85
}
182
86
 
183
87
/*
184
88
  Stuff for Emacs to see, in order to encourage consistent editing style: