aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Isely <isely@pobox.com>2009-03-08 17:47:47 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:39 -0400
commit5a3bab8eb02f9413b802540530ea390d8d063e43 (patch)
tree70f29f62325b7ced90612f30909ddd0c7bc03e49
parent2eb563b7e726b517ef86213df436f50ec6c1740c (diff)
V4L/DVB (11204): pvrusb2: Remove old i2c layer; we use v4l2-subdev now
This change removes the old i2c module controlling layer from the pvrusb2 driver. This is code that first had appeared in the driver back in December 2005. It's history. Now we use v4l2-subdev. Please note also that with this change, the driver will no longer be usable in kernels older that 2.6.22. Signed-off-by: Mike Isely <isely@pobox.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/pvrusb2/Makefile7
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.c127
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.h4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c221
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h29
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c85
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c118
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c338
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h53
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-track.c503
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-track.h102
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-tuner.c121
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-tuner.h37
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.c186
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.h5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-wm8775.c124
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-wm8775.h3
20 files changed, 3 insertions, 2074 deletions
diff --git a/drivers/media/video/pvrusb2/Makefile b/drivers/media/video/pvrusb2/Makefile
index 931d9d1a0b4..a4478618a7f 100644
--- a/drivers/media/video/pvrusb2/Makefile
+++ b/drivers/media/video/pvrusb2/Makefile
@@ -2,11 +2,10 @@ obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o
2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o 2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o
3obj-pvrusb2-dvb-$(CONFIG_VIDEO_PVRUSB2_DVB) := pvrusb2-dvb.o 3obj-pvrusb2-dvb-$(CONFIG_VIDEO_PVRUSB2_DVB) := pvrusb2-dvb.o
4 4
5pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \ 5pvrusb2-objs := pvrusb2-i2c-core.o \
6 pvrusb2-i2c-track.o \ 6 pvrusb2-audio.o \
7 pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \
8 pvrusb2-encoder.o pvrusb2-video-v4l.o \ 7 pvrusb2-encoder.o pvrusb2-video-v4l.o \
9 pvrusb2-eeprom.o pvrusb2-tuner.o \ 8 pvrusb2-eeprom.o \
10 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \ 9 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \
11 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \ 10 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \
12 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \ 11 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index aca6b1d1561..ccf2a3c7ad0 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -55,133 +55,6 @@ static const struct routing_scheme routing_schemes[] = {
55 }, 55 },
56}; 56};
57 57
58
59struct 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;
64};
65
66
67
68
69/* This function selects the correct audio input source */
70static void set_stereo(struct pvr2_msp3400_handler *ctxt)
71{
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;
76
77 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
78
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;
90 }
91 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
92 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
93}
94
95
96static int check_stereo(struct pvr2_msp3400_handler *ctxt)
97{
98 struct pvr2_hdw *hdw = ctxt->hdw;
99 return hdw->input_dirty;
100}
101
102
103struct pvr2_msp3400_ops {
104 void (*update)(struct pvr2_msp3400_handler *);
105 int (*check)(struct pvr2_msp3400_handler *);
106};
107
108
109static const struct pvr2_msp3400_ops msp3400_ops[] = {
110 { .update = set_stereo, .check = check_stereo},
111};
112
113
114static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
115{
116 unsigned long msk;
117 unsigned int idx;
118
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;
124 }
125 }
126 return ctxt->stale_mask != 0;
127}
128
129
130static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
131{
132 unsigned long msk;
133 unsigned int idx;
134
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);
140 }
141}
142
143
144static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
145{
146 ctxt->client->handler = NULL;
147 kfree(ctxt);
148}
149
150
151static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
152 char *buf,unsigned int cnt)
153{
154 return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2");
155}
156
157
158static 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,
163};
164
165
166int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
167{
168 struct pvr2_msp3400_handler *ctxt;
169 if (cp->handler) return 0;
170
171 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
172 if (!ctxt) return 0;
173
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;
183}
184
185void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) 58void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
186{ 59{
187 if (hdw->input_dirty || hdw->force_dirty) { 60 if (hdw->input_dirty || hdw->force_dirty) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.h b/drivers/media/video/pvrusb2/pvrusb2-audio.h
index c47c8de3ba0..e3e63d75089 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.h
@@ -22,10 +22,6 @@
22#ifndef __PVRUSB2_AUDIO_H 22#ifndef __PVRUSB2_AUDIO_H
23#define __PVRUSB2_AUDIO_H 23#define __PVRUSB2_AUDIO_H
24 24
25#include "pvrusb2-i2c-track.h"
26
27int pvr2_i2c_msp3400_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
28
29#include "pvrusb2-hdw-internal.h" 25#include "pvrusb2-hdw-internal.h"
30void pvr2_msp3400_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); 26void pvr2_msp3400_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
31#endif /* __PVRUSB2_AUDIO_H */ 27#endif /* __PVRUSB2_AUDIO_H */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index 5adbf00323e..4e017ff26c3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -28,7 +28,6 @@
28 28
29#include "pvrusb2-cx2584x-v4l.h" 29#include "pvrusb2-cx2584x-v4l.h"
30#include "pvrusb2-video-v4l.h" 30#include "pvrusb2-video-v4l.h"
31#include "pvrusb2-i2c-cmd-v4l2.h"
32 31
33 32
34#include "pvrusb2-hdw-internal.h" 33#include "pvrusb2-hdw-internal.h"
@@ -102,226 +101,6 @@ static const struct routing_scheme routing_schemes[] = {
102 }, 101 },
103}; 102};
104 103
105struct pvr2_v4l_cx2584x {
106 struct pvr2_i2c_handler handler;
107 struct pvr2_decoder_ctrl ctrl;
108 struct pvr2_i2c_client *client;
109 struct pvr2_hdw *hdw;
110 unsigned long stale_mask;
111};
112
113
114static void set_input(struct pvr2_v4l_cx2584x *ctxt)
115{
116 struct pvr2_hdw *hdw = ctxt->hdw;
117 struct v4l2_routing route;
118 enum cx25840_video_input vid_input;
119 enum cx25840_audio_input aud_input;
120 const struct routing_scheme *sp;
121 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
122
123 memset(&route,0,sizeof(route));
124
125 if ((sid < ARRAY_SIZE(routing_schemes)) &&
126 ((sp = routing_schemes + sid) != NULL) &&
127 (hdw->input_val >= 0) &&
128 (hdw->input_val < sp->cnt)) {
129 vid_input = sp->def[hdw->input_val].vid;
130 aud_input = sp->def[hdw->input_val].aud;
131 } else {
132 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
133 "*** WARNING *** i2c cx2584x set_input:"
134 " Invalid routing scheme (%u) and/or input (%d)",
135 sid,hdw->input_val);
136 return;
137 }
138
139 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_input vid=0x%x aud=0x%x",
140 vid_input,aud_input);
141 route.input = (u32)vid_input;
142 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route);
143 route.input = (u32)aud_input;
144 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
145}
146
147
148static int check_input(struct pvr2_v4l_cx2584x *ctxt)
149{
150 struct pvr2_hdw *hdw = ctxt->hdw;
151 return hdw->input_dirty != 0;
152}
153
154
155static void set_audio(struct pvr2_v4l_cx2584x *ctxt)
156{
157 u32 val;
158 struct pvr2_hdw *hdw = ctxt->hdw;
159
160 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_audio %d",
161 hdw->srate_val);
162 switch (hdw->srate_val) {
163 default:
164 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
165 val = 48000;
166 break;
167 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
168 val = 44100;
169 break;
170 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
171 val = 32000;
172 break;
173 }
174 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_AUDIO_CLOCK_FREQ,&val);
175}
176
177
178static int check_audio(struct pvr2_v4l_cx2584x *ctxt)
179{
180 struct pvr2_hdw *hdw = ctxt->hdw;
181 return hdw->srate_dirty != 0;
182}
183
184
185struct pvr2_v4l_cx2584x_ops {
186 void (*update)(struct pvr2_v4l_cx2584x *);
187 int (*check)(struct pvr2_v4l_cx2584x *);
188};
189
190
191static const struct pvr2_v4l_cx2584x_ops decoder_ops[] = {
192 { .update = set_input, .check = check_input},
193 { .update = set_audio, .check = check_audio},
194};
195
196
197static void decoder_detach(struct pvr2_v4l_cx2584x *ctxt)
198{
199 ctxt->client->handler = NULL;
200 pvr2_hdw_set_decoder(ctxt->hdw,NULL);
201 kfree(ctxt);
202}
203
204
205static int decoder_check(struct pvr2_v4l_cx2584x *ctxt)
206{
207 unsigned long msk;
208 unsigned int idx;
209
210 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
211 msk = 1 << idx;
212 if (ctxt->stale_mask & msk) continue;
213 if (decoder_ops[idx].check(ctxt)) {
214 ctxt->stale_mask |= msk;
215 }
216 }
217 return ctxt->stale_mask != 0;
218}
219
220
221static void decoder_update(struct pvr2_v4l_cx2584x *ctxt)
222{
223 unsigned long msk;
224 unsigned int idx;
225
226 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
227 msk = 1 << idx;
228 if (!(ctxt->stale_mask & msk)) continue;
229 ctxt->stale_mask &= ~msk;
230 decoder_ops[idx].update(ctxt);
231 }
232}
233
234
235static void decoder_enable(struct pvr2_v4l_cx2584x *ctxt,int fl)
236{
237 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_enable(%d)",fl);
238 pvr2_v4l2_cmd_stream(ctxt->client,fl);
239}
240
241
242static int decoder_detect(struct pvr2_i2c_client *cp)
243{
244 int ret;
245 /* Attempt to query the decoder - let's see if it will answer */
246 struct v4l2_queryctrl qc;
247
248 memset(&qc,0,sizeof(qc));
249
250 qc.id = V4L2_CID_BRIGHTNESS;
251
252 ret = pvr2_i2c_client_cmd(cp,VIDIOC_QUERYCTRL,&qc);
253 return ret == 0; /* Return true if it answered */
254}
255
256
257static unsigned int decoder_describe(struct pvr2_v4l_cx2584x *ctxt,
258 char *buf,unsigned int cnt)
259{
260 return scnprintf(buf,cnt,"handler: pvrusb2-cx2584x-v4l");
261}
262
263
264static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt)
265{
266 int ret;
267 ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_RESET,NULL);
268 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_reset (ret=%d)",ret);
269}
270
271
272static const struct pvr2_i2c_handler_functions hfuncs = {
273 .detach = (void (*)(void *))decoder_detach,
274 .check = (int (*)(void *))decoder_check,
275 .update = (void (*)(void *))decoder_update,
276 .describe = (unsigned int (*)(void *,char *,unsigned int))decoder_describe,
277};
278
279
280int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
281 struct pvr2_i2c_client *cp)
282{
283 struct pvr2_v4l_cx2584x *ctxt;
284
285 if (hdw->decoder_ctrl) return 0;
286 if (cp->handler) return 0;
287 if (!decoder_detect(cp)) return 0;
288
289 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
290 if (!ctxt) return 0;
291
292 ctxt->handler.func_data = ctxt;
293 ctxt->handler.func_table = &hfuncs;
294 ctxt->ctrl.ctxt = ctxt;
295 ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
296 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
297 ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset;
298 ctxt->client = cp;
299 ctxt->hdw = hdw;
300 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
301 pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
302 cp->handler = &ctxt->handler;
303 {
304 /*
305 Mike Isely <isely@pobox.com> 19-Nov-2006 - This bit
306 of nuttiness for cx25840 causes that module to
307 correctly set up its video scaling. This is really
308 a problem in the cx25840 module itself, but we work
309 around it here. The problem has not been seen in
310 ivtv because there VBI is supported and set up. We
311 don't do VBI here (at least not yet) and thus we
312 never attempted to even set it up.
313 */
314 struct v4l2_format fmt;
315 memset(&fmt,0,sizeof(fmt));
316 fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
317 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_S_FMT,&fmt);
318 }
319 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x cx2584x V4L2 handler set up",
320 cp->client->addr);
321 return !0;
322}
323
324
325void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) 104void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
326{ 105{
327 pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update..."); 106 pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h
index e48ce808bfe..e35c2322a08 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h
@@ -34,11 +34,6 @@
34 34
35 35
36 36
37#include "pvrusb2-i2c-track.h"
38
39int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
40
41
42#include "pvrusb2-hdw-internal.h" 37#include "pvrusb2-hdw-internal.h"
43 38
44void pvr2_cx25840_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd); 39void pvr2_cx25840_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index 2074ce05c76..fbe3856bdca 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -23,7 +23,6 @@
23#include "pvrusb2-debugifc.h" 23#include "pvrusb2-debugifc.h"
24#include "pvrusb2-hdw.h" 24#include "pvrusb2-hdw.h"
25#include "pvrusb2-debug.h" 25#include "pvrusb2-debug.h"
26#include "pvrusb2-i2c-track.h"
27 26
28struct debugifc_mask_item { 27struct debugifc_mask_item {
29 const char *name; 28 const char *name;
@@ -147,10 +146,6 @@ int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
147 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 146 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
148 ccnt = pvr2_hdw_state_report(hdw,buf,acnt); 147 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
149 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 148 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
150 ccnt = scnprintf(buf, acnt, "Attached old-style I2C modules:\n");
151 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
152 ccnt = pvr2_i2c_report(hdw,buf,acnt);
153 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
154 149
155 return bcnt; 150 return bcnt;
156} 151}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index 2afbd9bcedd..5d75eb5211b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -138,22 +138,6 @@ struct pvr2_ctrl {
138}; 138};
139 139
140 140
141struct pvr2_decoder_ctrl {
142 void *ctxt;
143 void (*detach)(void *);
144 void (*enable)(void *,int);
145 void (*force_reset)(void *);
146};
147
148#define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */
149#define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */
150#define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */
151#define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */
152
153#define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\
154 PVR2_I2C_PEND_CLIENT |\
155 PVR2_I2C_PEND_REFRESH |\
156 PVR2_I2C_PEND_STALE)
157 141
158/* Disposition of firmware1 loading situation */ 142/* Disposition of firmware1 loading situation */
159#define FW1_STATE_UNKNOWN 0 143#define FW1_STATE_UNKNOWN 0
@@ -187,7 +171,6 @@ struct pvr2_hdw {
187 /* Kernel worker thread handling */ 171 /* Kernel worker thread handling */
188 struct workqueue_struct *workqueue; 172 struct workqueue_struct *workqueue;
189 struct work_struct workpoll; /* Update driver state */ 173 struct work_struct workpoll; /* Update driver state */
190 struct work_struct worki2csync; /* Update i2c clients */
191 174
192 /* Video spigot */ 175 /* Video spigot */
193 struct pvr2_stream *vid_stream; 176 struct pvr2_stream *vid_stream;
@@ -216,12 +199,6 @@ struct pvr2_hdw {
216 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT]; 199 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
217 int i2c_cx25840_hack_state; 200 int i2c_cx25840_hack_state;
218 int i2c_linked; 201 int i2c_linked;
219 unsigned int i2c_pend_types; /* Which types of update are needed */
220 unsigned long i2c_pend_mask; /* Change bits we need to scan */
221 unsigned long i2c_stale_mask; /* Pending broadcast change bits */
222 unsigned long i2c_active_mask; /* All change bits currently in use */
223 struct list_head i2c_clients;
224 struct mutex i2c_list_lock;
225 202
226 /* Frequency table */ 203 /* Frequency table */
227 unsigned int freqTable[FREQTABLE_SIZE]; 204 unsigned int freqTable[FREQTABLE_SIZE];
@@ -297,7 +274,6 @@ struct pvr2_hdw {
297 int flag_decoder_missed;/* We've noticed missing decoder */ 274 int flag_decoder_missed;/* We've noticed missing decoder */
298 int flag_tripped; /* Indicates overall failure to start */ 275 int flag_tripped; /* Indicates overall failure to start */
299 276
300 struct pvr2_decoder_ctrl *decoder_ctrl;
301 unsigned int decoder_client_id; 277 unsigned int decoder_client_id;
302 278
303 // CPU firmware info (used to help find / save firmware data) 279 // CPU firmware info (used to help find / save firmware data)
@@ -305,10 +281,6 @@ struct pvr2_hdw {
305 unsigned int fw_size; 281 unsigned int fw_size;
306 int fw_cpu_flag; /* True if we are dealing with the CPU */ 282 int fw_cpu_flag; /* True if we are dealing with the CPU */
307 283
308 // True if there is a request to trigger logging of state in each
309 // module.
310 int log_requested;
311
312 /* Tuner / frequency control stuff */ 284 /* Tuner / frequency control stuff */
313 unsigned int tuner_type; 285 unsigned int tuner_type;
314 int tuner_updated; 286 int tuner_updated;
@@ -406,7 +378,6 @@ struct pvr2_hdw {
406 378
407/* This function gets the current frequency */ 379/* This function gets the current frequency */
408unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *); 380unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
409void pvr2_hdw_set_decoder(struct pvr2_hdw *,struct pvr2_decoder_ctrl *);
410 381
411void pvr2_hdw_status_poll(struct pvr2_hdw *); 382void pvr2_hdw_status_poll(struct pvr2_hdw *);
412 383
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index b0383153e3c..7c66779b1f4 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -30,8 +30,6 @@
30#include "pvrusb2-util.h" 30#include "pvrusb2-util.h"
31#include "pvrusb2-hdw.h" 31#include "pvrusb2-hdw.h"
32#include "pvrusb2-i2c-core.h" 32#include "pvrusb2-i2c-core.h"
33#include "pvrusb2-i2c-track.h"
34#include "pvrusb2-tuner.h"
35#include "pvrusb2-eeprom.h" 33#include "pvrusb2-eeprom.h"
36#include "pvrusb2-hdw-internal.h" 34#include "pvrusb2-hdw-internal.h"
37#include "pvrusb2-encoder.h" 35#include "pvrusb2-encoder.h"
@@ -313,7 +311,6 @@ static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v);
313static void pvr2_hdw_state_sched(struct pvr2_hdw *); 311static void pvr2_hdw_state_sched(struct pvr2_hdw *);
314static int pvr2_hdw_state_eval(struct pvr2_hdw *); 312static int pvr2_hdw_state_eval(struct pvr2_hdw *);
315static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); 313static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
316static void pvr2_hdw_worker_i2c(struct work_struct *work);
317static void pvr2_hdw_worker_poll(struct work_struct *work); 314static void pvr2_hdw_worker_poll(struct work_struct *work);
318static int pvr2_hdw_wait(struct pvr2_hdw *,int state); 315static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
319static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *); 316static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
@@ -1676,10 +1673,6 @@ static const char *pvr2_get_state_name(unsigned int st)
1676 1673
1677static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl) 1674static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
1678{ 1675{
1679 if (hdw->decoder_ctrl) {
1680 hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt, enablefl);
1681 return 0;
1682 }
1683 /* Even though we really only care about the video decoder chip at 1676 /* Even though we really only care about the video decoder chip at
1684 this point, we'll broadcast stream on/off to all sub-devices 1677 this point, we'll broadcast stream on/off to all sub-devices
1685 anyway, just in case somebody else wants to hear the 1678 anyway, just in case somebody else wants to hear the
@@ -1704,21 +1697,6 @@ static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
1704} 1697}
1705 1698
1706 1699
1707void pvr2_hdw_set_decoder(struct pvr2_hdw *hdw,struct pvr2_decoder_ctrl *ptr)
1708{
1709 if (hdw->decoder_ctrl == ptr) return;
1710 hdw->decoder_ctrl = ptr;
1711 if (hdw->decoder_ctrl && hdw->flag_decoder_missed) {
1712 hdw->flag_decoder_missed = 0;
1713 trace_stbit("flag_decoder_missed",
1714 hdw->flag_decoder_missed);
1715 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1716 "Decoder has appeared");
1717 pvr2_hdw_state_sched(hdw);
1718 }
1719}
1720
1721
1722int pvr2_hdw_get_state(struct pvr2_hdw *hdw) 1700int pvr2_hdw_get_state(struct pvr2_hdw *hdw)
1723{ 1701{
1724 return hdw->master_state; 1702 return hdw->master_state;
@@ -2052,7 +2030,6 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
2052 * and every other place where I can find examples of this, the 2030 * and every other place where I can find examples of this, the
2053 * "chipid" appears to just be the module name again. So here we 2031 * "chipid" appears to just be the module name again. So here we
2054 * just do the same thing. */ 2032 * just do the same thing. */
2055 hdw->i2c_adap.class = 0;
2056 if (i2ccnt == 1) { 2033 if (i2ccnt == 1) {
2057 pvr2_trace(PVR2_TRACE_INIT, 2034 pvr2_trace(PVR2_TRACE_INIT,
2058 "Module ID %u:" 2035 "Module ID %u:"
@@ -2070,7 +2047,6 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
2070 fname, fname, 2047 fname, fname,
2071 i2caddr); 2048 i2caddr);
2072 } 2049 }
2073 hdw->i2c_adap.class = I2C_CLASS_TV_ANALOG;
2074 2050
2075 if (!sd) { 2051 if (!sd) {
2076 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 2052 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
@@ -2084,11 +2060,6 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
2084 requires special handling. */ 2060 requires special handling. */
2085 sd->grp_id = mid; 2061 sd->grp_id = mid;
2086 2062
2087 /* If we have both old and new i2c layers enabled, make sure that
2088 old layer isn't also tracking this module. This is a debugging
2089 aid, in normal situations there's no reason for both mechanisms
2090 to be enabled. */
2091 pvr2_i2c_untrack_subdev(hdw, sd);
2092 pvr2_trace(PVR2_TRACE_INFO, "Attached sub-driver %s", fname); 2063 pvr2_trace(PVR2_TRACE_INFO, "Attached sub-driver %s", fname);
2093 2064
2094 2065
@@ -2204,7 +2175,6 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
2204 } 2175 }
2205 2176
2206 // This step MUST happen after the earlier powerup step. 2177 // This step MUST happen after the earlier powerup step.
2207 pvr2_i2c_track_init(hdw);
2208 pvr2_i2c_core_init(hdw); 2178 pvr2_i2c_core_init(hdw);
2209 if (!pvr2_hdw_dev_ok(hdw)) return; 2179 if (!pvr2_hdw_dev_ok(hdw)) return;
2210 2180
@@ -2271,7 +2241,6 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
2271 hdw->tuner_type); 2241 hdw->tuner_type);
2272 } 2242 }
2273 2243
2274 pvr2_i2c_core_check_stale(hdw);
2275 2244
2276 if (!pvr2_hdw_dev_ok(hdw)) return; 2245 if (!pvr2_hdw_dev_ok(hdw)) return;
2277 2246
@@ -2628,7 +2597,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2628 2597
2629 hdw->workqueue = create_singlethread_workqueue(hdw->name); 2598 hdw->workqueue = create_singlethread_workqueue(hdw->name);
2630 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); 2599 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
2631 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c);
2632 2600
2633 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", 2601 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
2634 hdw->unit_number,hdw->name); 2602 hdw->unit_number,hdw->name);
@@ -2731,11 +2699,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2731 pvr2_stream_destroy(hdw->vid_stream); 2699 pvr2_stream_destroy(hdw->vid_stream);
2732 hdw->vid_stream = NULL; 2700 hdw->vid_stream = NULL;
2733 } 2701 }
2734 if (hdw->decoder_ctrl) {
2735 hdw->decoder_ctrl->detach(hdw->decoder_ctrl->ctxt);
2736 }
2737 pvr2_i2c_core_done(hdw); 2702 pvr2_i2c_core_done(hdw);
2738 pvr2_i2c_track_done(hdw);
2739 v4l2_device_unregister(&hdw->v4l2_dev); 2703 v4l2_device_unregister(&hdw->v4l2_dev);
2740 pvr2_hdw_remove_usb_stuff(hdw); 2704 pvr2_hdw_remove_usb_stuff(hdw);
2741 mutex_lock(&pvr2_unit_mtx); do { 2705 mutex_lock(&pvr2_unit_mtx); do {
@@ -3238,12 +3202,6 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
3238 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS); 3202 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS);
3239 } 3203 }
3240 3204
3241 /* Scan i2c core at this point - before we clear all the dirty
3242 bits. Various parts of the i2c core will notice dirty bits as
3243 appropriate and arrange to broadcast or directly send updates to
3244 the client drivers in order to keep everything in sync */
3245 pvr2_i2c_core_check_stale(hdw);
3246
3247 if (hdw->active_stream_type != hdw->desired_stream_type) { 3205 if (hdw->active_stream_type != hdw->desired_stream_type) {
3248 /* Handle any side effects of stream config here */ 3206 /* Handle any side effects of stream config here */
3249 hdw->active_stream_type = hdw->desired_stream_type; 3207 hdw->active_stream_type = hdw->desired_stream_type;
@@ -3274,9 +3232,6 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
3274 cptr->info->clear_dirty(cptr); 3232 cptr->info->clear_dirty(cptr);
3275 } 3233 }
3276 3234
3277 /* Now execute i2c core update */
3278 pvr2_i2c_core_sync(hdw);
3279
3280 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) && 3235 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) &&
3281 hdw->state_encoder_run) { 3236 hdw->state_encoder_run) {
3282 /* If encoder isn't running or it can't be touched, then 3237 /* If encoder isn't running or it can't be touched, then
@@ -3305,15 +3260,6 @@ int pvr2_hdw_commit_ctl(struct pvr2_hdw *hdw)
3305} 3260}
3306 3261
3307 3262
3308static void pvr2_hdw_worker_i2c(struct work_struct *work)
3309{
3310 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,worki2csync);
3311 LOCK_TAKE(hdw->big_lock); do {
3312 pvr2_i2c_core_sync(hdw);
3313 } while (0); LOCK_GIVE(hdw->big_lock);
3314}
3315
3316
3317static void pvr2_hdw_worker_poll(struct work_struct *work) 3263static void pvr2_hdw_worker_poll(struct work_struct *work)
3318{ 3264{
3319 int fl = 0; 3265 int fl = 0;
@@ -3431,10 +3377,6 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
3431 int nr = pvr2_hdw_get_unit_number(hdw); 3377 int nr = pvr2_hdw_get_unit_number(hdw);
3432 LOCK_TAKE(hdw->big_lock); do { 3378 LOCK_TAKE(hdw->big_lock); do {
3433 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr); 3379 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
3434 hdw->log_requested = !0;
3435 pvr2_i2c_core_check_stale(hdw);
3436 pvr2_i2c_core_sync(hdw);
3437 hdw->log_requested = 0;
3438 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status); 3380 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status);
3439 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:"); 3381 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
3440 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2"); 3382 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
@@ -4120,16 +4062,6 @@ int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
4120{ 4062{
4121 pvr2_trace(PVR2_TRACE_INIT, 4063 pvr2_trace(PVR2_TRACE_INIT,
4122 "Requesting decoder reset"); 4064 "Requesting decoder reset");
4123 if (hdw->decoder_ctrl) {
4124 if (!hdw->decoder_ctrl->force_reset) {
4125 pvr2_trace(PVR2_TRACE_INIT,
4126 "Unable to reset decoder: not implemented");
4127 return -ENOTTY;
4128 }
4129 hdw->decoder_ctrl->force_reset(hdw->decoder_ctrl->ctxt);
4130 return 0;
4131 } else {
4132 }
4133 if (hdw->decoder_client_id) { 4065 if (hdw->decoder_client_id) {
4134 v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id, 4066 v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id,
4135 core, reset, 0); 4067 core, reset, 0);
@@ -5138,7 +5070,6 @@ void pvr2_hdw_status_poll(struct pvr2_hdw *hdw)
5138 struct v4l2_tuner *vtp = &hdw->tuner_signal_info; 5070 struct v4l2_tuner *vtp = &hdw->tuner_signal_info;
5139 memset(vtp, 0, sizeof(*vtp)); 5071 memset(vtp, 0, sizeof(*vtp));
5140 hdw->tuner_signal_stale = 0; 5072 hdw->tuner_signal_stale = 0;
5141 pvr2_i2c_core_status_poll(hdw);
5142 /* Note: There apparently is no replacement for VIDIOC_CROPCAP 5073 /* Note: There apparently is no replacement for VIDIOC_CROPCAP
5143 using v4l2-subdev - therefore we can't support that AT ALL right 5074 using v4l2-subdev - therefore we can't support that AT ALL right
5144 now. (Of course, no sub-drivers seem to implement it either. 5075 now. (Of course, no sub-drivers seem to implement it either.
@@ -5253,7 +5184,6 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
5253 int setFl, u64 *val_ptr) 5184 int setFl, u64 *val_ptr)
5254{ 5185{
5255#ifdef CONFIG_VIDEO_ADV_DEBUG 5186#ifdef CONFIG_VIDEO_ADV_DEBUG
5256 struct pvr2_i2c_client *cp;
5257 struct v4l2_dbg_register req; 5187 struct v4l2_dbg_register req;
5258 int stat = 0; 5188 int stat = 0;
5259 int okFl = 0; 5189 int okFl = 0;
@@ -5266,21 +5196,6 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
5266 /* It would be nice to know if a sub-device answered the request */ 5196 /* It would be nice to know if a sub-device answered the request */
5267 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, g_register, &req); 5197 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, g_register, &req);
5268 if (!setFl) *val_ptr = req.val; 5198 if (!setFl) *val_ptr = req.val;
5269 if (!okFl) mutex_lock(&hdw->i2c_list_lock); do {
5270 list_for_each_entry(cp, &hdw->i2c_clients, list) {
5271 if (!v4l2_chip_match_i2c_client(
5272 cp->client,
5273 &req.match)) {
5274 continue;
5275 }
5276 stat = pvr2_i2c_client_cmd(
5277 cp,(setFl ? VIDIOC_DBG_S_REGISTER :
5278 VIDIOC_DBG_G_REGISTER),&req);
5279 if (!setFl) *val_ptr = req.val;
5280 okFl = !0;
5281 break;
5282 }
5283 } while (0); mutex_unlock(&hdw->i2c_list_lock);
5284 if (okFl) { 5199 if (okFl) {
5285 return stat; 5200 return stat;
5286 } 5201 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
deleted file mode 100644
index 7e0628b988c..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#include <linux/kernel.h>
22#include "pvrusb2-i2c-track.h"
23#include "pvrusb2-hdw-internal.h"
24#include "pvrusb2-debug.h"
25#include "pvrusb2-i2c-cmd-v4l2.h"
26#include "pvrusb2-audio.h"
27#include "pvrusb2-tuner.h"
28#include "pvrusb2-video-v4l.h"
29#include "pvrusb2-cx2584x-v4l.h"
30#include "pvrusb2-wm8775.h"
31
32
33#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
34
35#define OP_INIT 0 /* MUST come first so it is run first */
36#define OP_STANDARD 1
37#define OP_AUDIOMODE 2
38#define OP_BCSH 3
39#define OP_VOLUME 4
40#define OP_FREQ 5
41#define OP_AUDIORATE 6
42#define OP_CROP 7
43#define OP_SIZE 8
44#define OP_LOG 9
45
46static const struct pvr2_i2c_op * const ops[] = {
47 [OP_INIT] = &pvr2_i2c_op_v4l2_init,
48 [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard,
49 [OP_AUDIOMODE] = &pvr2_i2c_op_v4l2_audiomode,
50 [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh,
51 [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume,
52 [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency,
53 [OP_CROP] = &pvr2_i2c_op_v4l2_crop,
54 [OP_SIZE] = &pvr2_i2c_op_v4l2_size,
55 [OP_LOG] = &pvr2_i2c_op_v4l2_log,
56};
57
58void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
59{
60 int id;
61 id = cp->client->driver->id;
62 cp->ctl_mask = ((1 << OP_INIT) |
63 (1 << OP_STANDARD) |
64 (1 << OP_AUDIOMODE) |
65 (1 << OP_BCSH) |
66 (1 << OP_VOLUME) |
67 (1 << OP_FREQ) |
68 (1 << OP_CROP) |
69 (1 << OP_SIZE) |
70 (1 << OP_LOG));
71 cp->status_poll = pvr2_v4l2_cmd_status_poll;
72
73 if (id == I2C_DRIVERID_MSP3400) {
74 if (pvr2_i2c_msp3400_setup(hdw,cp)) {
75 return;
76 }
77 }
78 if (id == I2C_DRIVERID_TUNER) {
79 if (pvr2_i2c_tuner_setup(hdw,cp)) {
80 return;
81 }
82 }
83 if (id == I2C_DRIVERID_CX25840) {
84 if (pvr2_i2c_cx2584x_v4l_setup(hdw,cp)) {
85 return;
86 }
87 }
88 if (id == I2C_DRIVERID_WM8775) {
89 if (pvr2_i2c_wm8775_setup(hdw,cp)) {
90 return;
91 }
92 }
93 if (id == I2C_DRIVERID_SAA711X) {
94 if (pvr2_i2c_decoder_v4l_setup(hdw,cp)) {
95 return;
96 }
97 }
98}
99
100
101const struct pvr2_i2c_op *pvr2_i2c_get_op(unsigned int idx)
102{
103 if (idx >= ARRAY_SIZE(ops))
104 return NULL;
105 return ops[idx];
106}
107
108
109
110/*
111 Stuff for Emacs to see, in order to encourage consistent editing style:
112 *** Local Variables: ***
113 *** mode: c ***
114 *** fill-column: 75 ***
115 *** tab-width: 8 ***
116 *** c-basic-offset: 8 ***
117 *** End: ***
118 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
deleted file mode 100644
index 7afe513bebf..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
+++ /dev/null
@@ -1,338 +0,0 @@
1/*
2 *
3 *
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-i2c-cmd-v4l2.h"
23#include "pvrusb2-hdw-internal.h"
24#include "pvrusb2-debug.h"
25#include <linux/videodev2.h>
26#include <media/v4l2-common.h>
27
28
29static void execute_init(struct pvr2_hdw *hdw)
30{
31 u32 dummy = 0;
32 pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 init");
33 pvr2_i2c_core_cmd(hdw, VIDIOC_INT_INIT, &dummy);
34}
35
36
37const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init = {
38 .update = execute_init,
39 .name = "v4l2_init",
40};
41
42
43static void set_standard(struct pvr2_hdw *hdw)
44{
45 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
46
47 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
48 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
49 } else {
50 v4l2_std_id vs;
51 vs = hdw->std_mask_cur;
52 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
53 }
54 hdw->tuner_signal_stale = !0;
55 hdw->cropcap_stale = !0;
56}
57
58
59static int check_standard(struct pvr2_hdw *hdw)
60{
61 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
62}
63
64
65const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
66 .check = check_standard,
67 .update = set_standard,
68 .name = "v4l2_standard",
69};
70
71
72static void set_bcsh(struct pvr2_hdw *hdw)
73{
74 struct v4l2_control ctrl;
75 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
76 " b=%d c=%d s=%d h=%d",
77 hdw->brightness_val,hdw->contrast_val,
78 hdw->saturation_val,hdw->hue_val);
79 memset(&ctrl,0,sizeof(ctrl));
80 ctrl.id = V4L2_CID_BRIGHTNESS;
81 ctrl.value = hdw->brightness_val;
82 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
83 ctrl.id = V4L2_CID_CONTRAST;
84 ctrl.value = hdw->contrast_val;
85 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
86 ctrl.id = V4L2_CID_SATURATION;
87 ctrl.value = hdw->saturation_val;
88 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
89 ctrl.id = V4L2_CID_HUE;
90 ctrl.value = hdw->hue_val;
91 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
92}
93
94
95static int check_bcsh(struct pvr2_hdw *hdw)
96{
97 return (hdw->brightness_dirty ||
98 hdw->contrast_dirty ||
99 hdw->saturation_dirty ||
100 hdw->hue_dirty);
101}
102
103
104const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
105 .check = check_bcsh,
106 .update = set_bcsh,
107 .name = "v4l2_bcsh",
108};
109
110
111static void set_volume(struct pvr2_hdw *hdw)
112{
113 struct v4l2_control ctrl;
114 pvr2_trace(PVR2_TRACE_CHIPS,
115 "i2c v4l2 set_volume"
116 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
117 hdw->volume_val,
118 hdw->balance_val,
119 hdw->bass_val,
120 hdw->treble_val,
121 hdw->mute_val);
122 memset(&ctrl,0,sizeof(ctrl));
123 ctrl.id = V4L2_CID_AUDIO_MUTE;
124 ctrl.value = hdw->mute_val ? 1 : 0;
125 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
126 ctrl.id = V4L2_CID_AUDIO_VOLUME;
127 ctrl.value = hdw->volume_val;
128 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
129 ctrl.id = V4L2_CID_AUDIO_BALANCE;
130 ctrl.value = hdw->balance_val;
131 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
132 ctrl.id = V4L2_CID_AUDIO_BASS;
133 ctrl.value = hdw->bass_val;
134 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
135 ctrl.id = V4L2_CID_AUDIO_TREBLE;
136 ctrl.value = hdw->treble_val;
137 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
138}
139
140
141static int check_volume(struct pvr2_hdw *hdw)
142{
143 return (hdw->volume_dirty ||
144 hdw->balance_dirty ||
145 hdw->bass_dirty ||
146 hdw->treble_dirty ||
147 hdw->mute_dirty);
148}
149
150
151const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
152 .check = check_volume,
153 .update = set_volume,
154 .name = "v4l2_volume",
155};
156
157
158static void set_audiomode(struct pvr2_hdw *hdw)
159{
160 struct v4l2_tuner vt;
161 memset(&vt,0,sizeof(vt));
162 vt.audmode = hdw->audiomode_val;
163 pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt);
164}
165
166
167static int check_audiomode(struct pvr2_hdw *hdw)
168{
169 return (hdw->input_dirty ||
170 hdw->audiomode_dirty);
171}
172
173
174const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
175 .check = check_audiomode,
176 .update = set_audiomode,
177 .name = "v4l2_audiomode",
178};
179
180
181static void set_frequency(struct pvr2_hdw *hdw)
182{
183 unsigned long fv;
184 struct v4l2_frequency freq;
185 fv = pvr2_hdw_get_cur_freq(hdw);
186 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
187 if (hdw->tuner_signal_stale) {
188 pvr2_hdw_status_poll(hdw);
189 }
190 memset(&freq,0,sizeof(freq));
191 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
192 // ((fv * 1000) / 62500)
193 freq.frequency = (fv * 2) / 125;
194 } else {
195 freq.frequency = fv / 62500;
196 }
197 /* tuner-core currently doesn't seem to care about this, but
198 let's set it anyway for completeness. */
199 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
200 freq.type = V4L2_TUNER_RADIO;
201 } else {
202 freq.type = V4L2_TUNER_ANALOG_TV;
203 }
204 freq.tuner = 0;
205 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
206}
207
208
209static int check_frequency(struct pvr2_hdw *hdw)
210{
211 return hdw->freqDirty != 0;
212}
213
214
215const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
216 .check = check_frequency,
217 .update = set_frequency,
218 .name = "v4l2_freq",
219};
220
221
222static void set_size(struct pvr2_hdw *hdw)
223{
224 struct v4l2_format fmt;
225
226 memset(&fmt,0,sizeof(fmt));
227
228 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
229 fmt.fmt.pix.width = hdw->res_hor_val;
230 fmt.fmt.pix.height = hdw->res_ver_val;
231
232 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
233 fmt.fmt.pix.width,fmt.fmt.pix.height);
234
235 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
236}
237
238
239static int check_size(struct pvr2_hdw *hdw)
240{
241 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
242}
243
244
245const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
246 .check = check_size,
247 .update = set_size,
248 .name = "v4l2_size",
249};
250
251
252static void set_crop(struct pvr2_hdw *hdw)
253{
254 struct v4l2_crop crop;
255
256 memset(&crop, 0, sizeof crop);
257 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
258 crop.c.left = hdw->cropl_val;
259 crop.c.top = hdw->cropt_val;
260 crop.c.height = hdw->croph_val;
261 crop.c.width = hdw->cropw_val;
262
263 pvr2_trace(PVR2_TRACE_CHIPS,
264 "i2c v4l2 set_crop crop=%d:%d:%d:%d",
265 crop.c.width, crop.c.height, crop.c.left, crop.c.top);
266
267 pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
268}
269
270static int check_crop(struct pvr2_hdw *hdw)
271{
272 return (hdw->cropl_dirty || hdw->cropt_dirty ||
273 hdw->cropw_dirty || hdw->croph_dirty);
274}
275
276const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
277 .check = check_crop,
278 .update = set_crop,
279 .name = "v4l2_crop",
280};
281
282
283static void do_log(struct pvr2_hdw *hdw)
284{
285 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
286 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
287
288}
289
290
291static int check_log(struct pvr2_hdw *hdw)
292{
293 return hdw->log_requested != 0;
294}
295
296
297const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
298 .check = check_log,
299 .update = do_log,
300 .name = "v4l2_log",
301};
302
303
304void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
305{
306 pvr2_i2c_client_cmd(cp,
307 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
308}
309
310
311void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
312{
313 int stat;
314 struct pvr2_hdw *hdw = cp->hdw;
315 if (hdw->cropcap_stale) {
316 hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
317 stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
318 &hdw->cropcap_info);
319 if (stat == 0) {
320 /* Check was successful, so the data is no
321 longer considered stale. */
322 hdw->cropcap_stale = 0;
323 }
324 }
325 pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
326}
327
328
329
330/*
331 Stuff for Emacs to see, in order to encourage consistent editing style:
332 *** Local Variables: ***
333 *** mode: c ***
334 *** fill-column: 70 ***
335 *** tab-width: 8 ***
336 *** c-basic-offset: 8 ***
337 *** End: ***
338 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
deleted file mode 100644
index fa42497b40b..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 *
3 *
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#ifndef __PVRUSB2_CMD_V4L2_H
23#define __PVRUSB2_CMD_V4L2_H
24
25#include "pvrusb2-i2c-track.h"
26
27
28extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init;
29extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard;
30extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio;
31extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh;
32extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume;
33extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency;
34extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop;
35extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size;
36extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode;
37extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log;
38
39void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *,int);
40void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *);
41
42
43#endif /* __PVRUSB2_CMD_V4L2_H */
44
45/*
46 Stuff for Emacs to see, in order to encourage consistent editing style:
47 *** Local Variables: ***
48 *** mode: c ***
49 *** fill-column: 70 ***
50 *** tab-width: 8 ***
51 *** c-basic-offset: 8 ***
52 *** End: ***
53 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 13d016efc0d..9464862745f 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -20,7 +20,6 @@
20 20
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include "pvrusb2-i2c-core.h" 22#include "pvrusb2-i2c-core.h"
23#include "pvrusb2-i2c-track.h"
24#include "pvrusb2-hdw-internal.h" 23#include "pvrusb2-hdw-internal.h"
25#include "pvrusb2-debug.h" 24#include "pvrusb2-debug.h"
26#include "pvrusb2-fx2-cmd.h" 25#include "pvrusb2-fx2-cmd.h"
@@ -523,13 +522,11 @@ static u32 pvr2_i2c_functionality(struct i2c_adapter *adap)
523 522
524static int pvr2_i2c_attach_inform(struct i2c_client *client) 523static int pvr2_i2c_attach_inform(struct i2c_client *client)
525{ 524{
526 pvr2_i2c_track_attach_inform(client);
527 return 0; 525 return 0;
528} 526}
529 527
530static int pvr2_i2c_detach_inform(struct i2c_client *client) 528static int pvr2_i2c_detach_inform(struct i2c_client *client)
531{ 529{
532 pvr2_i2c_track_detach_inform(client);
533 return 0; 530 return 0;
534} 531}
535 532
@@ -607,7 +604,6 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
607 hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev; 604 hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev;
608 hdw->i2c_adap.algo = &hdw->i2c_algo; 605 hdw->i2c_adap.algo = &hdw->i2c_algo;
609 hdw->i2c_adap.algo_data = hdw; 606 hdw->i2c_adap.algo_data = hdw;
610 hdw->i2c_adap.class = I2C_CLASS_TV_ANALOG;
611 hdw->i2c_linked = !0; 607 hdw->i2c_linked = !0;
612 i2c_set_adapdata(&hdw->i2c_adap, &hdw->v4l2_dev); 608 i2c_set_adapdata(&hdw->i2c_adap, &hdw->v4l2_dev);
613 i2c_add_adapter(&hdw->i2c_adap); 609 i2c_add_adapter(&hdw->i2c_adap);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-track.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-track.c
deleted file mode 100644
index d0682c13b02..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-track.c
+++ /dev/null
@@ -1,503 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#include "pvrusb2-i2c-track.h"
22#include "pvrusb2-hdw-internal.h"
23#include "pvrusb2-debug.h"
24#include "pvrusb2-fx2-cmd.h"
25#include "pvrusb2.h"
26
27#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
28
29
30/*
31
32 This module implements the foundation of a rather large architecture for
33 tracking state in all the various V4L I2C modules. This is obsolete with
34 kernels later than roughly 2.6.24, but it is still present in the
35 standalone pvrusb2 driver to allow continued operation with older
36 kernel.
37
38*/
39
40static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
41 unsigned int detail,
42 char *buf,unsigned int maxlen);
43
44static int pvr2_i2c_core_singleton(struct i2c_client *cp,
45 unsigned int cmd,void *arg)
46{
47 int stat;
48 if (!cp) return -EINVAL;
49 if (!(cp->driver)) return -EINVAL;
50 if (!(cp->driver->command)) return -EINVAL;
51 if (!try_module_get(cp->driver->driver.owner)) return -EAGAIN;
52 stat = cp->driver->command(cp,cmd,arg);
53 module_put(cp->driver->driver.owner);
54 return stat;
55}
56
57int pvr2_i2c_client_cmd(struct pvr2_i2c_client *cp,unsigned int cmd,void *arg)
58{
59 int stat;
60 if (pvrusb2_debug & PVR2_TRACE_I2C_CMD) {
61 char buf[100];
62 unsigned int cnt;
63 cnt = pvr2_i2c_client_describe(cp,PVR2_I2C_DETAIL_DEBUG,
64 buf,sizeof(buf));
65 pvr2_trace(PVR2_TRACE_I2C_CMD,
66 "i2c COMMAND (code=%u 0x%x) to %.*s",
67 cmd,cmd,cnt,buf);
68 }
69 stat = pvr2_i2c_core_singleton(cp->client,cmd,arg);
70 if (pvrusb2_debug & PVR2_TRACE_I2C_CMD) {
71 char buf[100];
72 unsigned int cnt;
73 cnt = pvr2_i2c_client_describe(cp,PVR2_I2C_DETAIL_DEBUG,
74 buf,sizeof(buf));
75 pvr2_trace(PVR2_TRACE_I2C_CMD,
76 "i2c COMMAND to %.*s (ret=%d)",cnt,buf,stat);
77 }
78 return stat;
79}
80
81int pvr2_i2c_core_cmd(struct pvr2_hdw *hdw,unsigned int cmd,void *arg)
82{
83 struct pvr2_i2c_client *cp, *ncp;
84 int stat = -EINVAL;
85
86 if (!hdw) return stat;
87
88 mutex_lock(&hdw->i2c_list_lock);
89 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
90 if (!cp->recv_enable) continue;
91 mutex_unlock(&hdw->i2c_list_lock);
92 stat = pvr2_i2c_client_cmd(cp,cmd,arg);
93 mutex_lock(&hdw->i2c_list_lock);
94 }
95 mutex_unlock(&hdw->i2c_list_lock);
96 return stat;
97}
98
99
100static int handler_check(struct pvr2_i2c_client *cp)
101{
102 struct pvr2_i2c_handler *hp = cp->handler;
103 if (!hp) return 0;
104 if (!hp->func_table->check) return 0;
105 return hp->func_table->check(hp->func_data) != 0;
106}
107
108#define BUFSIZE 500
109
110
111void pvr2_i2c_core_status_poll(struct pvr2_hdw *hdw)
112{
113 struct pvr2_i2c_client *cp;
114 mutex_lock(&hdw->i2c_list_lock); do {
115 list_for_each_entry(cp, &hdw->i2c_clients, list) {
116 if (!cp->detected_flag) continue;
117 if (!cp->status_poll) continue;
118 cp->status_poll(cp);
119 }
120 } while (0); mutex_unlock(&hdw->i2c_list_lock);
121}
122
123
124/* Issue various I2C operations to bring chip-level drivers into sync with
125 state stored in this driver. */
126void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
127{
128 unsigned long msk;
129 unsigned int idx;
130 struct pvr2_i2c_client *cp, *ncp;
131
132 if (!hdw->i2c_linked) return;
133 if (!(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL)) {
134 return;
135 }
136 mutex_lock(&hdw->i2c_list_lock); do {
137 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: core_sync BEGIN");
138 if (hdw->i2c_pend_types & PVR2_I2C_PEND_DETECT) {
139 /* One or more I2C clients have attached since we
140 last synced. So scan the list and identify the
141 new clients. */
142 char *buf;
143 unsigned int cnt;
144 unsigned long amask = 0;
145 buf = kmalloc(BUFSIZE,GFP_KERNEL);
146 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_DETECT");
147 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_DETECT;
148 list_for_each_entry(cp, &hdw->i2c_clients, list) {
149 if (!cp->detected_flag) {
150 cp->ctl_mask = 0;
151 pvr2_i2c_probe(hdw,cp);
152 cp->detected_flag = !0;
153 msk = cp->ctl_mask;
154 cnt = 0;
155 if (buf) {
156 cnt = pvr2_i2c_client_describe(
157 cp,
158 PVR2_I2C_DETAIL_ALL,
159 buf,BUFSIZE);
160 }
161 trace_i2c("Probed: %.*s",cnt,buf);
162 if (handler_check(cp)) {
163 hdw->i2c_pend_types |=
164 PVR2_I2C_PEND_CLIENT;
165 }
166 cp->pend_mask = msk;
167 hdw->i2c_pend_mask |= msk;
168 hdw->i2c_pend_types |=
169 PVR2_I2C_PEND_REFRESH;
170 }
171 amask |= cp->ctl_mask;
172 }
173 hdw->i2c_active_mask = amask;
174 if (buf) kfree(buf);
175 }
176 if (hdw->i2c_pend_types & PVR2_I2C_PEND_STALE) {
177 /* Need to do one or more global updates. Arrange
178 for this to happen. */
179 unsigned long m2;
180 pvr2_trace(PVR2_TRACE_I2C_CORE,
181 "i2c: PEND_STALE (0x%lx)",
182 hdw->i2c_stale_mask);
183 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_STALE;
184 list_for_each_entry(cp, &hdw->i2c_clients, list) {
185 m2 = hdw->i2c_stale_mask;
186 m2 &= cp->ctl_mask;
187 m2 &= ~cp->pend_mask;
188 if (m2) {
189 pvr2_trace(PVR2_TRACE_I2C_CORE,
190 "i2c: cp=%p setting 0x%lx",
191 cp,m2);
192 cp->pend_mask |= m2;
193 }
194 }
195 hdw->i2c_pend_mask |= hdw->i2c_stale_mask;
196 hdw->i2c_stale_mask = 0;
197 hdw->i2c_pend_types |= PVR2_I2C_PEND_REFRESH;
198 }
199 if (hdw->i2c_pend_types & PVR2_I2C_PEND_CLIENT) {
200 /* One or more client handlers are asking for an
201 update. Run through the list of known clients
202 and update each one. */
203 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_CLIENT");
204 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_CLIENT;
205 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients,
206 list) {
207 if (!cp->handler) continue;
208 if (!cp->handler->func_table->update) continue;
209 pvr2_trace(PVR2_TRACE_I2C_CORE,
210 "i2c: cp=%p update",cp);
211 mutex_unlock(&hdw->i2c_list_lock);
212 cp->handler->func_table->update(
213 cp->handler->func_data);
214 mutex_lock(&hdw->i2c_list_lock);
215 /* If client's update function set some
216 additional pending bits, account for that
217 here. */
218 if (cp->pend_mask & ~hdw->i2c_pend_mask) {
219 hdw->i2c_pend_mask |= cp->pend_mask;
220 hdw->i2c_pend_types |=
221 PVR2_I2C_PEND_REFRESH;
222 }
223 }
224 }
225 if (hdw->i2c_pend_types & PVR2_I2C_PEND_REFRESH) {
226 const struct pvr2_i2c_op *opf;
227 unsigned long pm;
228 /* Some actual updates are pending. Walk through
229 each update type and perform it. */
230 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_REFRESH"
231 " (0x%lx)",hdw->i2c_pend_mask);
232 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_REFRESH;
233 pm = hdw->i2c_pend_mask;
234 hdw->i2c_pend_mask = 0;
235 for (idx = 0, msk = 1; pm; idx++, msk <<= 1) {
236 if (!(pm & msk)) continue;
237 pm &= ~msk;
238 list_for_each_entry(cp, &hdw->i2c_clients,
239 list) {
240 if (cp->pend_mask & msk) {
241 cp->pend_mask &= ~msk;
242 cp->recv_enable = !0;
243 } else {
244 cp->recv_enable = 0;
245 }
246 }
247 opf = pvr2_i2c_get_op(idx);
248 if (!opf) continue;
249 mutex_unlock(&hdw->i2c_list_lock);
250 opf->update(hdw);
251 mutex_lock(&hdw->i2c_list_lock);
252 }
253 }
254 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: core_sync END");
255 } while (0); mutex_unlock(&hdw->i2c_list_lock);
256}
257
258int pvr2_i2c_core_check_stale(struct pvr2_hdw *hdw)
259{
260 unsigned long msk,sm,pm;
261 unsigned int idx;
262 const struct pvr2_i2c_op *opf;
263 struct pvr2_i2c_client *cp;
264 unsigned int pt = 0;
265
266 pvr2_trace(PVR2_TRACE_I2C_CORE,"pvr2_i2c_core_check_stale BEGIN");
267
268 pm = hdw->i2c_active_mask;
269 sm = 0;
270 for (idx = 0, msk = 1; pm; idx++, msk <<= 1) {
271 if (!(msk & pm)) continue;
272 pm &= ~msk;
273 opf = pvr2_i2c_get_op(idx);
274 if (!(opf && opf->check)) continue;
275 if (opf->check(hdw)) {
276 sm |= msk;
277 }
278 }
279 if (sm) pt |= PVR2_I2C_PEND_STALE;
280
281 list_for_each_entry(cp, &hdw->i2c_clients, list)
282 if (handler_check(cp))
283 pt |= PVR2_I2C_PEND_CLIENT;
284
285 if (pt) {
286 mutex_lock(&hdw->i2c_list_lock); do {
287 hdw->i2c_pend_types |= pt;
288 hdw->i2c_stale_mask |= sm;
289 hdw->i2c_pend_mask |= hdw->i2c_stale_mask;
290 } while (0); mutex_unlock(&hdw->i2c_list_lock);
291 }
292
293 pvr2_trace(PVR2_TRACE_I2C_CORE,
294 "i2c: types=0x%x stale=0x%lx pend=0x%lx",
295 hdw->i2c_pend_types,
296 hdw->i2c_stale_mask,
297 hdw->i2c_pend_mask);
298 pvr2_trace(PVR2_TRACE_I2C_CORE,"pvr2_i2c_core_check_stale END");
299
300 return (hdw->i2c_pend_types & PVR2_I2C_PEND_ALL) != 0;
301}
302
303static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
304 unsigned int detail,
305 char *buf,unsigned int maxlen)
306{
307 unsigned int ccnt,bcnt;
308 int spcfl = 0;
309 const struct pvr2_i2c_op *opf;
310
311 ccnt = 0;
312 if (detail & PVR2_I2C_DETAIL_DEBUG) {
313 bcnt = scnprintf(buf,maxlen,
314 "ctxt=%p ctl_mask=0x%lx",
315 cp,cp->ctl_mask);
316 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
317 spcfl = !0;
318 }
319 bcnt = scnprintf(buf,maxlen,
320 "%s%s @ 0x%x",
321 (spcfl ? " " : ""),
322 cp->client->name,
323 cp->client->addr);
324 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
325 if ((detail & PVR2_I2C_DETAIL_HANDLER) &&
326 cp->handler && cp->handler->func_table->describe) {
327 bcnt = scnprintf(buf,maxlen," (");
328 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
329 bcnt = cp->handler->func_table->describe(
330 cp->handler->func_data,buf,maxlen);
331 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
332 bcnt = scnprintf(buf,maxlen,")");
333 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
334 }
335 if ((detail & PVR2_I2C_DETAIL_CTLMASK) && cp->ctl_mask) {
336 unsigned int idx;
337 unsigned long msk,sm;
338
339 bcnt = scnprintf(buf,maxlen," [");
340 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
341 sm = 0;
342 spcfl = 0;
343 for (idx = 0, msk = 1; msk; idx++, msk <<= 1) {
344 if (!(cp->ctl_mask & msk)) continue;
345 opf = pvr2_i2c_get_op(idx);
346 if (opf) {
347 bcnt = scnprintf(buf,maxlen,"%s%s",
348 spcfl ? " " : "",
349 opf->name);
350 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
351 spcfl = !0;
352 } else {
353 sm |= msk;
354 }
355 }
356 if (sm) {
357 bcnt = scnprintf(buf,maxlen,"%s%lx",
358 idx != 0 ? " " : "",sm);
359 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
360 }
361 bcnt = scnprintf(buf,maxlen,"]");
362 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
363 }
364 return ccnt;
365}
366
367unsigned int pvr2_i2c_report(struct pvr2_hdw *hdw,
368 char *buf,unsigned int maxlen)
369{
370 unsigned int ccnt,bcnt;
371 struct pvr2_i2c_client *cp;
372 ccnt = 0;
373 mutex_lock(&hdw->i2c_list_lock); do {
374 list_for_each_entry(cp, &hdw->i2c_clients, list) {
375 bcnt = pvr2_i2c_client_describe(
376 cp,
377 (PVR2_I2C_DETAIL_HANDLER|
378 PVR2_I2C_DETAIL_CTLMASK),
379 buf,maxlen);
380 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
381 bcnt = scnprintf(buf,maxlen,"\n");
382 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
383 }
384 } while (0); mutex_unlock(&hdw->i2c_list_lock);
385 return ccnt;
386}
387
388void pvr2_i2c_track_attach_inform(struct i2c_client *client)
389{
390 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data);
391 struct pvr2_i2c_client *cp;
392 int fl = !(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL);
393 cp = kzalloc(sizeof(*cp),GFP_KERNEL);
394 trace_i2c("i2c_attach [client=%s @ 0x%x ctxt=%p]",
395 client->name,
396 client->addr,cp);
397 if (!cp) {
398 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
399 "Unable to allocate tracking memory for incoming"
400 " i2c module; ignoring module. This is likely"
401 " going to be a problem.");
402 return;
403 }
404 cp->hdw = hdw;
405 INIT_LIST_HEAD(&cp->list);
406 cp->client = client;
407 mutex_lock(&hdw->i2c_list_lock); do {
408 hdw->cropcap_stale = !0;
409 list_add_tail(&cp->list,&hdw->i2c_clients);
410 hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT;
411 } while (0); mutex_unlock(&hdw->i2c_list_lock);
412 if (fl) queue_work(hdw->workqueue,&hdw->worki2csync);
413}
414
415static void pvr2_i2c_client_disconnect(struct pvr2_i2c_client *cp)
416{
417 if (cp->handler && cp->handler->func_table->detach) {
418 cp->handler->func_table->detach(cp->handler->func_data);
419 }
420 list_del(&cp->list);
421 kfree(cp);
422}
423
424void pvr2_i2c_track_detach_inform(struct i2c_client *client)
425{
426 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data);
427 struct pvr2_i2c_client *cp, *ncp;
428 unsigned long amask = 0;
429 int foundfl = 0;
430 mutex_lock(&hdw->i2c_list_lock);
431 hdw->cropcap_stale = !0;
432 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
433 if (cp->client == client) {
434 trace_i2c("pvr2_i2c_detach"
435 " [client=%s @ 0x%x ctxt=%p]",
436 client->name,
437 client->addr, cp);
438 pvr2_i2c_client_disconnect(cp);
439 foundfl = !0;
440 continue;
441 }
442 amask |= cp->ctl_mask;
443 }
444 hdw->i2c_active_mask = amask;
445 mutex_unlock(&hdw->i2c_list_lock);
446 if (!foundfl) {
447 trace_i2c("pvr2_i2c_detach [client=%s @ 0x%x ctxt=<unknown>]",
448 client->name, client->addr);
449 }
450}
451
452/* This function is used to remove an i2c client from our tracking
453 structure if the client happens to be the specified v4l2 sub-device.
454 The idea here is to ensure that sub-devices are not also tracked with
455 the old tracking mechanism - it's one or the other not both. This is
456 only for debugging. In a "real" environment, only one of these two
457 mechanisms should even be compiled in. But by enabling both we can
458 incrementally test control of each sub-device. */
459void pvr2_i2c_untrack_subdev(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
460{
461 struct i2c_client *client;
462 struct pvr2_i2c_client *cp, *ncp;
463 unsigned long amask = 0;
464 mutex_lock(&hdw->i2c_list_lock);
465 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
466 client = cp->client;
467 if (i2c_get_clientdata(client) == sd) {
468 trace_i2c("pvr2_i2c_detach (subdev active)"
469 " [client=%s @ 0x%x ctxt=%p]",
470 client->name, client->addr, cp);
471 pvr2_i2c_client_disconnect(cp);
472 continue;
473 }
474 amask |= cp->ctl_mask;
475 }
476 hdw->i2c_active_mask = amask;
477 mutex_unlock(&hdw->i2c_list_lock);
478}
479
480void pvr2_i2c_track_init(struct pvr2_hdw *hdw)
481{
482 hdw->i2c_pend_mask = 0;
483 hdw->i2c_stale_mask = 0;
484 hdw->i2c_active_mask = 0;
485 INIT_LIST_HEAD(&hdw->i2c_clients);
486 mutex_init(&hdw->i2c_list_lock);
487}
488
489void pvr2_i2c_track_done(struct pvr2_hdw *hdw)
490{
491 /* Empty for now */
492}
493
494
495/*
496 Stuff for Emacs to see, in order to encourage consistent editing style:
497 *** Local Variables: ***
498 *** mode: c ***
499 *** fill-column: 75 ***
500 *** tab-width: 8 ***
501 *** c-basic-offset: 8 ***
502 *** End: ***
503 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-track.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-track.h
deleted file mode 100644
index eba48e4c958..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-track.h
+++ /dev/null
@@ -1,102 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20#ifndef __PVRUSB2_I2C_TRACK_H
21#define __PVRUSB2_I2C_TRACK_H
22
23#include <linux/list.h>
24#include <linux/i2c.h>
25#include <media/v4l2-device.h>
26
27
28struct pvr2_hdw;
29struct pvr2_i2c_client;
30struct pvr2_i2c_handler;
31struct pvr2_i2c_handler_functions;
32struct pvr2_i2c_op;
33struct pvr2_i2c_op_functions;
34
35struct pvr2_i2c_client {
36 struct i2c_client *client;
37 struct pvr2_i2c_handler *handler;
38 struct list_head list;
39 struct pvr2_hdw *hdw;
40 int detected_flag;
41 int recv_enable;
42 unsigned long pend_mask;
43 unsigned long ctl_mask;
44 void (*status_poll)(struct pvr2_i2c_client *);
45};
46
47struct pvr2_i2c_handler {
48 void *func_data;
49 const struct pvr2_i2c_handler_functions *func_table;
50};
51
52struct pvr2_i2c_handler_functions {
53 void (*detach)(void *);
54 int (*check)(void *);
55 void (*update)(void *);
56 unsigned int (*describe)(void *,char *,unsigned int);
57};
58
59struct pvr2_i2c_op {
60 int (*check)(struct pvr2_hdw *);
61 void (*update)(struct pvr2_hdw *);
62 const char *name;
63};
64
65void pvr2_i2c_track_init(struct pvr2_hdw *);
66void pvr2_i2c_track_done(struct pvr2_hdw *);
67void pvr2_i2c_track_attach_inform(struct i2c_client *);
68void pvr2_i2c_track_detach_inform(struct i2c_client *);
69
70int pvr2_i2c_client_cmd(struct pvr2_i2c_client *,unsigned int cmd,void *arg);
71int pvr2_i2c_core_cmd(struct pvr2_hdw *,unsigned int cmd,void *arg);
72
73int pvr2_i2c_core_check_stale(struct pvr2_hdw *);
74void pvr2_i2c_core_sync(struct pvr2_hdw *);
75void pvr2_i2c_core_status_poll(struct pvr2_hdw *);
76unsigned int pvr2_i2c_report(struct pvr2_hdw *,char *buf,unsigned int maxlen);
77#define PVR2_I2C_DETAIL_DEBUG 0x0001
78#define PVR2_I2C_DETAIL_HANDLER 0x0002
79#define PVR2_I2C_DETAIL_CTLMASK 0x0004
80#define PVR2_I2C_DETAIL_ALL (\
81 PVR2_I2C_DETAIL_DEBUG |\
82 PVR2_I2C_DETAIL_HANDLER |\
83 PVR2_I2C_DETAIL_CTLMASK)
84
85void pvr2_i2c_probe(struct pvr2_hdw *,struct pvr2_i2c_client *);
86const struct pvr2_i2c_op *pvr2_i2c_get_op(unsigned int idx);
87
88void pvr2_i2c_untrack_subdev(struct pvr2_hdw *, struct v4l2_subdev *sd);
89
90
91#endif /* __PVRUSB2_I2C_CORE_H */
92
93
94/*
95 Stuff for Emacs to see, in order to encourage consistent editing style:
96 *** Local Variables: ***
97 *** mode: c ***
98 *** fill-column: 75 ***
99 *** tab-width: 8 ***
100 *** c-basic-offset: 8 ***
101 *** End: ***
102 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-tuner.c b/drivers/media/video/pvrusb2/pvrusb2-tuner.c
deleted file mode 100644
index ee9c9c139a8..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-tuner.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/*
2 *
3 *
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.h"
23#include "pvrusb2-util.h"
24#include "pvrusb2-tuner.h"
25#include "pvrusb2-hdw-internal.h"
26#include "pvrusb2-debug.h"
27#include <linux/videodev2.h>
28#include <media/tuner.h>
29#include <media/v4l2-common.h>
30
31
32struct pvr2_tuner_handler {
33 struct pvr2_hdw *hdw;
34 struct pvr2_i2c_client *client;
35 struct pvr2_i2c_handler i2c_handler;
36 int type_update_fl;
37};
38
39
40static void set_type(struct pvr2_tuner_handler *ctxt)
41{
42 struct pvr2_hdw *hdw = ctxt->hdw;
43 struct tuner_setup setup;
44 pvr2_trace(PVR2_TRACE_CHIPS,"i2c tuner set_type(%d)",hdw->tuner_type);
45 if (((int)(hdw->tuner_type)) < 0) return;
46
47 setup.addr = ADDR_UNSET;
48 setup.type = hdw->tuner_type;
49 setup.mode_mask = T_RADIO | T_ANALOG_TV;
50 /* We may really want mode_mask to be T_ANALOG_TV for now */
51 pvr2_i2c_client_cmd(ctxt->client,TUNER_SET_TYPE_ADDR,&setup);
52 ctxt->type_update_fl = 0;
53}
54
55
56static int tuner_check(struct pvr2_tuner_handler *ctxt)
57{
58 struct pvr2_hdw *hdw = ctxt->hdw;
59 if (hdw->tuner_updated) ctxt->type_update_fl = !0;
60 return ctxt->type_update_fl != 0;
61}
62
63
64static void tuner_update(struct pvr2_tuner_handler *ctxt)
65{
66 if (ctxt->type_update_fl) set_type(ctxt);
67}
68
69
70static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
71{
72 ctxt->client->handler = NULL;
73 kfree(ctxt);
74}
75
76
77static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
78{
79 return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
80}
81
82
83static const struct pvr2_i2c_handler_functions tuner_funcs = {
84 .detach = (void (*)(void *))pvr2_tuner_detach,
85 .check = (int (*)(void *))tuner_check,
86 .update = (void (*)(void *))tuner_update,
87 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_tuner_describe,
88};
89
90
91int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
92{
93 struct pvr2_tuner_handler *ctxt;
94 if (cp->handler) return 0;
95
96 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
97 if (!ctxt) return 0;
98
99 ctxt->i2c_handler.func_data = ctxt;
100 ctxt->i2c_handler.func_table = &tuner_funcs;
101 ctxt->type_update_fl = !0;
102 ctxt->client = cp;
103 ctxt->hdw = hdw;
104 cp->handler = &ctxt->i2c_handler;
105 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up",
106 cp->client->addr);
107 return !0;
108}
109
110
111
112
113/*
114 Stuff for Emacs to see, in order to encourage consistent editing style:
115 *** Local Variables: ***
116 *** mode: c ***
117 *** fill-column: 70 ***
118 *** tab-width: 8 ***
119 *** c-basic-offset: 8 ***
120 *** End: ***
121 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-tuner.h b/drivers/media/video/pvrusb2/pvrusb2-tuner.h
deleted file mode 100644
index 3643e2c7880..00000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-tuner.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20#ifndef __PVRUSB2_TUNER_H
21#define __PVRUSB2_TUNER_H
22
23#include "pvrusb2-i2c-track.h"
24
25int pvr2_i2c_tuner_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
26
27#endif /* __PVRUSB2_TUNER_H */
28
29/*
30 Stuff for Emacs to see, in order to encourage consistent editing style:
31 *** Local Variables: ***
32 *** mode: c ***
33 *** fill-column: 70 ***
34 *** tab-width: 8 ***
35 *** c-basic-offset: 8 ***
36 *** End: ***
37 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 4e0c0881b7b..ce8332dd9cc 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -30,7 +30,6 @@
30#include "pvrusb2-video-v4l.h" 30#include "pvrusb2-video-v4l.h"
31 31
32 32
33#include "pvrusb2-i2c-cmd-v4l2.h"
34 33
35#include "pvrusb2-hdw-internal.h" 34#include "pvrusb2-hdw-internal.h"
36#include "pvrusb2-debug.h" 35#include "pvrusb2-debug.h"
@@ -62,191 +61,6 @@ static const struct routing_scheme routing_schemes[] = {
62 }, 61 },
63}; 62};
64 63
65struct pvr2_v4l_decoder {
66 struct pvr2_i2c_handler handler;
67 struct pvr2_decoder_ctrl ctrl;
68 struct pvr2_i2c_client *client;
69 struct pvr2_hdw *hdw;
70 unsigned long stale_mask;
71};
72
73
74
75static void set_input(struct pvr2_v4l_decoder *ctxt)
76{
77 struct pvr2_hdw *hdw = ctxt->hdw;
78 struct v4l2_routing route;
79 const struct routing_scheme *sp;
80 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
81
82 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_input(%d)",hdw->input_val);
83
84 if ((sid < ARRAY_SIZE(routing_schemes)) &&
85 ((sp = routing_schemes + sid) != NULL) &&
86 (hdw->input_val >= 0) &&
87 (hdw->input_val < sp->cnt)) {
88 route.input = sp->def[hdw->input_val];
89 } else {
90 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
91 "*** WARNING *** i2c v4l2 set_input:"
92 " Invalid routing scheme (%u) and/or input (%d)",
93 sid,hdw->input_val);
94 return;
95 }
96
97 route.output = 0;
98 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route);
99}
100
101
102static int check_input(struct pvr2_v4l_decoder *ctxt)
103{
104 struct pvr2_hdw *hdw = ctxt->hdw;
105 return hdw->input_dirty != 0;
106}
107
108
109static void set_audio(struct pvr2_v4l_decoder *ctxt)
110{
111 u32 val;
112 struct pvr2_hdw *hdw = ctxt->hdw;
113
114 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_audio %d",
115 hdw->srate_val);
116 switch (hdw->srate_val) {
117 default:
118 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
119 val = 48000;
120 break;
121 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
122 val = 44100;
123 break;
124 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
125 val = 32000;
126 break;
127 }
128 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_AUDIO_CLOCK_FREQ,&val);
129}
130
131
132static int check_audio(struct pvr2_v4l_decoder *ctxt)
133{
134 struct pvr2_hdw *hdw = ctxt->hdw;
135 return hdw->srate_dirty != 0;
136}
137
138
139struct pvr2_v4l_decoder_ops {
140 void (*update)(struct pvr2_v4l_decoder *);
141 int (*check)(struct pvr2_v4l_decoder *);
142};
143
144
145static const struct pvr2_v4l_decoder_ops decoder_ops[] = {
146 { .update = set_input, .check = check_input},
147 { .update = set_audio, .check = check_audio},
148};
149
150
151static void decoder_detach(struct pvr2_v4l_decoder *ctxt)
152{
153 ctxt->client->handler = NULL;
154 pvr2_hdw_set_decoder(ctxt->hdw,NULL);
155 kfree(ctxt);
156}
157
158
159static int decoder_check(struct pvr2_v4l_decoder *ctxt)
160{
161 unsigned long msk;
162 unsigned int idx;
163
164 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
165 msk = 1 << idx;
166 if (ctxt->stale_mask & msk) continue;
167 if (decoder_ops[idx].check(ctxt)) {
168 ctxt->stale_mask |= msk;
169 }
170 }
171 return ctxt->stale_mask != 0;
172}
173
174
175static void decoder_update(struct pvr2_v4l_decoder *ctxt)
176{
177 unsigned long msk;
178 unsigned int idx;
179
180 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
181 msk = 1 << idx;
182 if (!(ctxt->stale_mask & msk)) continue;
183 ctxt->stale_mask &= ~msk;
184 decoder_ops[idx].update(ctxt);
185 }
186}
187
188
189static int decoder_detect(struct pvr2_i2c_client *cp)
190{
191 /* Attempt to query the decoder - let's see if it will answer */
192 struct v4l2_tuner vt;
193 int ret;
194
195 memset(&vt,0,sizeof(vt));
196 ret = pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&vt);
197 return ret == 0; /* Return true if it answered */
198}
199
200
201static void decoder_enable(struct pvr2_v4l_decoder *ctxt,int fl)
202{
203 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 decoder_enable(%d)",fl);
204 pvr2_v4l2_cmd_stream(ctxt->client,fl);
205}
206
207
208static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,unsigned int cnt)
209{
210 return scnprintf(buf,cnt,"handler: pvrusb2-video-v4l");
211}
212
213
214static const struct pvr2_i2c_handler_functions hfuncs = {
215 .detach = (void (*)(void *))decoder_detach,
216 .check = (int (*)(void *))decoder_check,
217 .update = (void (*)(void *))decoder_update,
218 .describe = (unsigned int (*)(void *,char *,unsigned int))decoder_describe,
219};
220
221
222int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
223 struct pvr2_i2c_client *cp)
224{
225 struct pvr2_v4l_decoder *ctxt;
226
227 if (hdw->decoder_ctrl) return 0;
228 if (cp->handler) return 0;
229 if (!decoder_detect(cp)) return 0;
230
231 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
232 if (!ctxt) return 0;
233
234 ctxt->handler.func_data = ctxt;
235 ctxt->handler.func_table = &hfuncs;
236 ctxt->ctrl.ctxt = ctxt;
237 ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
238 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
239 ctxt->client = cp;
240 ctxt->hdw = hdw;
241 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
242 pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
243 cp->handler = &ctxt->handler;
244 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
245 cp->client->addr);
246 return !0;
247}
248
249
250void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) 64void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
251{ 65{
252 if (hdw->input_dirty || hdw->force_dirty) { 66 if (hdw->input_dirty || hdw->force_dirty) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h
index dac4b1ad366..3b0bd5db602 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h
@@ -32,11 +32,6 @@
32*/ 32*/
33 33
34 34
35
36#include "pvrusb2-i2c-track.h"
37
38int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
39
40#include "pvrusb2-hdw-internal.h" 35#include "pvrusb2-hdw-internal.h"
41void pvr2_saa7115_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); 36void pvr2_saa7115_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
42 37
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
index 0068566876e..1670aa4051c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
@@ -27,7 +27,6 @@
27*/ 27*/
28 28
29#include "pvrusb2-wm8775.h" 29#include "pvrusb2-wm8775.h"
30#include "pvrusb2-i2c-cmd-v4l2.h"
31 30
32 31
33#include "pvrusb2-hdw-internal.h" 32#include "pvrusb2-hdw-internal.h"
@@ -37,129 +36,6 @@
37#include <linux/errno.h> 36#include <linux/errno.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
39 38
40
41
42struct pvr2_v4l_wm8775 {
43 struct pvr2_i2c_handler handler;
44 struct pvr2_i2c_client *client;
45 struct pvr2_hdw *hdw;
46 unsigned long stale_mask;
47};
48
49
50static void set_input(struct pvr2_v4l_wm8775 *ctxt)
51{
52 struct v4l2_routing route;
53 struct pvr2_hdw *hdw = ctxt->hdw;
54
55 memset(&route,0,sizeof(route));
56
57 switch(hdw->input_val) {
58 case PVR2_CVAL_INPUT_RADIO:
59 route.input = 1;
60 break;
61 default:
62 /* All other cases just use the second input */
63 route.input = 2;
64 break;
65 }
66 pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d route=0x%x)",
67 hdw->input_val,route.input);
68
69 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
70}
71
72static int check_input(struct pvr2_v4l_wm8775 *ctxt)
73{
74 struct pvr2_hdw *hdw = ctxt->hdw;
75 return hdw->input_dirty != 0;
76}
77
78
79struct pvr2_v4l_wm8775_ops {
80 void (*update)(struct pvr2_v4l_wm8775 *);
81 int (*check)(struct pvr2_v4l_wm8775 *);
82};
83
84
85static const struct pvr2_v4l_wm8775_ops wm8775_ops[] = {
86 { .update = set_input, .check = check_input},
87};
88
89
90static unsigned int wm8775_describe(struct pvr2_v4l_wm8775 *ctxt,
91 char *buf,unsigned int cnt)
92{
93 return scnprintf(buf,cnt,"handler: pvrusb2-wm8775");
94}
95
96
97static void wm8775_detach(struct pvr2_v4l_wm8775 *ctxt)
98{
99 ctxt->client->handler = NULL;
100 kfree(ctxt);
101}
102
103
104static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
105{
106 unsigned long msk;
107 unsigned int idx;
108
109 for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); 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 < ARRAY_SIZE(wm8775_ops); idx++) {
126 msk = 1 << idx;
127 if (!(ctxt->stale_mask & msk)) continue;
128 ctxt->stale_mask &= ~msk;
129 wm8775_ops[idx].update(ctxt);
130 }
131}
132
133
134static const struct pvr2_i2c_handler_functions hfuncs = {
135 .detach = (void (*)(void *))wm8775_detach,
136 .check = (int (*)(void *))wm8775_check,
137 .update = (void (*)(void *))wm8775_update,
138 .describe = (unsigned int (*)(void *,char *,unsigned int))wm8775_describe,
139};
140
141
142int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
143{
144 struct pvr2_v4l_wm8775 *ctxt;
145
146 if (cp->handler) return 0;
147
148 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
149 if (!ctxt) return 0;
150
151 ctxt->handler.func_data = ctxt;
152 ctxt->handler.func_table = &hfuncs;
153 ctxt->client = cp;
154 ctxt->hdw = hdw;
155 ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1;
156 cp->handler = &ctxt->handler;
157 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
158 cp->client->addr);
159 return !0;
160}
161
162
163void pvr2_wm8775_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) 39void pvr2_wm8775_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
164{ 40{
165 if (hdw->input_dirty || hdw->force_dirty) { 41 if (hdw->input_dirty || hdw->force_dirty) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.h b/drivers/media/video/pvrusb2/pvrusb2-wm8775.h
index a304988b1e7..0577bc7246f 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.h
@@ -34,9 +34,6 @@
34 34
35 35
36 36
37#include "pvrusb2-i2c-track.h"
38
39int pvr2_i2c_wm8775_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
40#include "pvrusb2-hdw-internal.h" 37#include "pvrusb2-hdw-internal.h"
41 38
42void pvr2_wm8775_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd); 39void pvr2_wm8775_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd);