5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 This source file is specifically designed to interface with the
30 #include "pvrusb2-wm8775.h"
31 #include "pvrusb2-i2c-cmd-v4l2.h"
34 #include "pvrusb2-hdw-internal.h"
35 #include "pvrusb2-debug.h"
36 #include <linux/videodev2.h>
37 #include <media/v4l2-common.h>
38 #include <linux/errno.h>
39 #include <linux/slab.h>
41 struct pvr2_v4l_wm8775
{
42 struct pvr2_i2c_handler handler
;
43 struct pvr2_i2c_client
*client
;
45 unsigned long stale_mask
;
49 static void set_input(struct pvr2_v4l_wm8775
*ctxt
)
51 struct v4l2_routing route
;
52 struct pvr2_hdw
*hdw
= ctxt
->hdw
;
55 memset(&route
,0,sizeof(route
));
57 pvr2_trace(PVR2_TRACE_CHIPS
,"i2c wm8775 set_input(val=%d msk=0x%x)",
60 // Always point to input #1 no matter what
62 pvr2_i2c_client_cmd(ctxt
->client
,VIDIOC_INT_S_AUDIO_ROUTING
,&route
);
65 static int check_input(struct pvr2_v4l_wm8775
*ctxt
)
67 struct pvr2_hdw
*hdw
= ctxt
->hdw
;
68 return hdw
->input_dirty
!= 0;
72 struct pvr2_v4l_wm8775_ops
{
73 void (*update
)(struct pvr2_v4l_wm8775
*);
74 int (*check
)(struct pvr2_v4l_wm8775
*);
78 static const struct pvr2_v4l_wm8775_ops wm8775_ops
[] = {
79 { .update
= set_input
, .check
= check_input
},
83 static unsigned int wm8775_describe(struct pvr2_v4l_wm8775
*ctxt
,
84 char *buf
,unsigned int cnt
)
86 return scnprintf(buf
,cnt
,"handler: pvrusb2-wm8775");
90 static void wm8775_detach(struct pvr2_v4l_wm8775
*ctxt
)
92 ctxt
->client
->handler
= NULL
;
97 static int wm8775_check(struct pvr2_v4l_wm8775
*ctxt
)
102 for (idx
= 0; idx
< sizeof(wm8775_ops
)/sizeof(wm8775_ops
[0]);
105 if (ctxt
->stale_mask
& msk
) continue;
106 if (wm8775_ops
[idx
].check(ctxt
)) {
107 ctxt
->stale_mask
|= msk
;
110 return ctxt
->stale_mask
!= 0;
114 static void wm8775_update(struct pvr2_v4l_wm8775
*ctxt
)
119 for (idx
= 0; idx
< sizeof(wm8775_ops
)/sizeof(wm8775_ops
[0]);
122 if (!(ctxt
->stale_mask
& msk
)) continue;
123 ctxt
->stale_mask
&= ~msk
;
124 wm8775_ops
[idx
].update(ctxt
);
129 static const struct pvr2_i2c_handler_functions hfuncs
= {
130 .detach
= (void (*)(void *))wm8775_detach
,
131 .check
= (int (*)(void *))wm8775_check
,
132 .update
= (void (*)(void *))wm8775_update
,
133 .describe
= (unsigned int (*)(void *,char *,unsigned int))wm8775_describe
,
137 int pvr2_i2c_wm8775_setup(struct pvr2_hdw
*hdw
,struct pvr2_i2c_client
*cp
)
139 struct pvr2_v4l_wm8775
*ctxt
;
141 if (cp
->handler
) return 0;
143 ctxt
= kmalloc(sizeof(*ctxt
),GFP_KERNEL
);
145 memset(ctxt
,0,sizeof(*ctxt
));
147 ctxt
->handler
.func_data
= ctxt
;
148 ctxt
->handler
.func_table
= &hfuncs
;
151 ctxt
->stale_mask
= (1 << (sizeof(wm8775_ops
)/
152 sizeof(wm8775_ops
[0]))) - 1;
153 cp
->handler
= &ctxt
->handler
;
154 pvr2_trace(PVR2_TRACE_CHIPS
,"i2c 0x%x wm8775 V4L2 handler set up",
163 Stuff for Emacs to see, in order to encourage consistent editing style:
164 *** Local Variables: ***
166 *** fill-column: 70 ***
168 *** c-basic-offset: 8 ***