blob: 3f6bc4b117c73d41fc5afd6c2f4b7ddf7261ffc7 [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
3 * $Id$
4 *
5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
7 *
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
11 *
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.
16 *
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
20 *
21 */
22
23/*
24
25 This source file is specifically designed to interface with the
26 wm8775.
27
28*/
29
30#include "pvrusb2-wm8775.h"
31#include "pvrusb2-i2c-cmd-v4l2.h"
32
33
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>
40
41struct pvr2_v4l_wm8775 {
42 struct pvr2_i2c_handler handler;
43 struct pvr2_i2c_client *client;
44 struct pvr2_hdw *hdw;
45 unsigned long stale_mask;
46};
47
48
49static void set_input(struct pvr2_v4l_wm8775 *ctxt)
50{
51 struct v4l2_routing route;
52 struct pvr2_hdw *hdw = ctxt->hdw;
Mike Iselyd8554972006-06-26 20:58:46 -030053
54 memset(&route,0,sizeof(route));
55
Mike Isely20832302006-12-27 23:26:55 -030056 switch(hdw->input_val) {
57 case PVR2_CVAL_INPUT_RADIO:
58 route.input = 1;
59 break;
60 default:
61 /* All other cases just use the second input */
62 route.input = 2;
63 break;
64 }
65 pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d route=0x%x)",
66 hdw->input_val,route.input);
Mike Iselyd8554972006-06-26 20:58:46 -030067
Mike Iselyd8554972006-06-26 20:58:46 -030068 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
69}
70
71static int check_input(struct pvr2_v4l_wm8775 *ctxt)
72{
73 struct pvr2_hdw *hdw = ctxt->hdw;
74 return hdw->input_dirty != 0;
75}
76
77
78struct pvr2_v4l_wm8775_ops {
79 void (*update)(struct pvr2_v4l_wm8775 *);
80 int (*check)(struct pvr2_v4l_wm8775 *);
81};
82
83
84static const struct pvr2_v4l_wm8775_ops wm8775_ops[] = {
85 { .update = set_input, .check = check_input},
86};
87
88
89static unsigned int wm8775_describe(struct pvr2_v4l_wm8775 *ctxt,
90 char *buf,unsigned int cnt)
91{
92 return scnprintf(buf,cnt,"handler: pvrusb2-wm8775");
93}
94
95
96static void wm8775_detach(struct pvr2_v4l_wm8775 *ctxt)
97{
Mike Iselya0fd1cb2006-06-30 11:35:28 -030098 ctxt->client->handler = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -030099 kfree(ctxt);
100}
101
102
103static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
104{
105 unsigned long msk;
106 unsigned int idx;
107
108 for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
109 idx++) {
110 msk = 1 << idx;
111 if (ctxt->stale_mask & msk) continue;
112 if (wm8775_ops[idx].check(ctxt)) {
113 ctxt->stale_mask |= msk;
114 }
115 }
116 return ctxt->stale_mask != 0;
117}
118
119
120static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
121{
122 unsigned long msk;
123 unsigned int idx;
124
125 for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
126 idx++) {
127 msk = 1 << idx;
128 if (!(ctxt->stale_mask & msk)) continue;
129 ctxt->stale_mask &= ~msk;
130 wm8775_ops[idx].update(ctxt);
131 }
132}
133
134
Tobias Klauserc5a69d52007-02-17 20:11:19 +0100135static const struct pvr2_i2c_handler_functions hfuncs = {
Mike Iselyd8554972006-06-26 20:58:46 -0300136 .detach = (void (*)(void *))wm8775_detach,
137 .check = (int (*)(void *))wm8775_check,
138 .update = (void (*)(void *))wm8775_update,
139 .describe = (unsigned int (*)(void *,char *,unsigned int))wm8775_describe,
140};
141
142
143int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
144{
145 struct pvr2_v4l_wm8775 *ctxt;
146
147 if (cp->handler) return 0;
148
149 ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL);
150 if (!ctxt) return 0;
151 memset(ctxt,0,sizeof(*ctxt));
152
153 ctxt->handler.func_data = ctxt;
154 ctxt->handler.func_table = &hfuncs;
155 ctxt->client = cp;
156 ctxt->hdw = hdw;
157 ctxt->stale_mask = (1 << (sizeof(wm8775_ops)/
158 sizeof(wm8775_ops[0]))) - 1;
159 cp->handler = &ctxt->handler;
160 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
161 cp->client->addr);
162 return !0;
163}
164
165
166
167
168/*
169 Stuff for Emacs to see, in order to encourage consistent editing style:
170 *** Local Variables: ***
171 *** mode: c ***
172 *** fill-column: 70 ***
173 *** tab-width: 8 ***
174 *** c-basic-offset: 8 ***
175 *** End: ***
176 */