diff options
-rw-r--r-- | drivers/media/dvb/frontends/Kconfig | 8 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/au8522.c | 448 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/au8522.h | 55 | ||||
-rw-r--r-- | drivers/media/video/Kconfig | 2 | ||||
-rw-r--r-- | drivers/media/video/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/video/au0828/Kconfig | 10 | ||||
-rw-r--r-- | drivers/media/video/au0828/Makefile | 9 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-cards.c | 144 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-cards.h | 25 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-core.c | 252 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-dvb.c | 371 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-i2c.c | 402 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828-reg.h | 35 | ||||
-rw-r--r-- | drivers/media/video/au0828/au0828.h | 117 |
15 files changed, 1881 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig index 4284a3092c14..ae3659be323f 100644 --- a/drivers/media/dvb/frontends/Kconfig +++ b/drivers/media/dvb/frontends/Kconfig | |||
@@ -291,6 +291,14 @@ config DVB_S5H1409 | |||
291 | An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want | 291 | An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want |
292 | to support this frontend. | 292 | to support this frontend. |
293 | 293 | ||
294 | config DVB_AU8522 | ||
295 | tristate "Auvitek AU8522 based" | ||
296 | depends on DVB_CORE && I2C | ||
297 | default m if DVB_FE_CUSTOMISE | ||
298 | help | ||
299 | An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want | ||
300 | to support this frontend. | ||
301 | |||
294 | comment "Tuners/PLL support" | 302 | comment "Tuners/PLL support" |
295 | depends on DVB_CORE | 303 | depends on DVB_CORE |
296 | 304 | ||
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile index 129367886bcc..8e23a30ed3be 100644 --- a/drivers/media/dvb/frontends/Makefile +++ b/drivers/media/dvb/frontends/Makefile | |||
@@ -53,3 +53,4 @@ obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o | |||
53 | obj-$(CONFIG_DVB_S5H1409) += s5h1409.o | 53 | obj-$(CONFIG_DVB_S5H1409) += s5h1409.o |
54 | obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o | 54 | obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o |
55 | obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o | 55 | obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o |
56 | obj-$(CONFIG_DVB_AU8522) += au8522.o | ||
diff --git a/drivers/media/dvb/frontends/au8522.c b/drivers/media/dvb/frontends/au8522.c new file mode 100644 index 000000000000..d3c44b95e240 --- /dev/null +++ b/drivers/media/dvb/frontends/au8522.c | |||
@@ -0,0 +1,448 @@ | |||
1 | /* | ||
2 | Auvitek AU8522 QAM/8VSB demodulator driver | ||
3 | |||
4 | Copyright (C) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | (at your option) any later version. | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | |||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/string.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include "dvb_frontend.h" | ||
29 | #include "dvb-pll.h" | ||
30 | #include "au8522.h" | ||
31 | |||
32 | struct au8522_state { | ||
33 | |||
34 | struct i2c_adapter* i2c; | ||
35 | |||
36 | /* configuration settings */ | ||
37 | const struct au8522_config* config; | ||
38 | |||
39 | struct dvb_frontend frontend; | ||
40 | |||
41 | u32 current_frequency; | ||
42 | fe_modulation_t current_modulation; | ||
43 | |||
44 | }; | ||
45 | |||
46 | static int debug = 0; | ||
47 | #define dprintk if (debug) printk | ||
48 | |||
49 | /* 16 bit registers, 8 bit values */ | ||
50 | static int au8522_writereg(struct au8522_state* state, u16 reg, u8 data) | ||
51 | { | ||
52 | int ret; | ||
53 | u8 buf [] = { reg >> 8, reg & 0xff, data }; | ||
54 | |||
55 | struct i2c_msg msg = { .addr = state->config->demod_address, | ||
56 | .flags = 0, .buf = buf, .len = 3 }; | ||
57 | |||
58 | ret = i2c_transfer(state->i2c, &msg, 1); | ||
59 | |||
60 | if (ret != 1) | ||
61 | printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, " | ||
62 | "ret == %i)\n", __FUNCTION__, reg, data, ret); | ||
63 | |||
64 | return (ret != 1) ? -1 : 0; | ||
65 | } | ||
66 | |||
67 | static u8 au8522_readreg(struct au8522_state* state, u16 reg) | ||
68 | { | ||
69 | int ret; | ||
70 | u8 b0 [] = { reg >> 8, reg & 0xff }; | ||
71 | u8 b1 [] = { 0 }; | ||
72 | |||
73 | struct i2c_msg msg [] = { | ||
74 | { .addr = state->config->demod_address, .flags = 0, | ||
75 | .buf = b0, .len = 2 }, | ||
76 | { .addr = state->config->demod_address, .flags = I2C_M_RD, | ||
77 | .buf = b1, .len = 1 } }; | ||
78 | |||
79 | ret = i2c_transfer(state->i2c, msg, 2); | ||
80 | |||
81 | if (ret != 2) | ||
82 | printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); | ||
83 | return b1[0]; | ||
84 | } | ||
85 | |||
86 | static int au8522_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) | ||
87 | { | ||
88 | struct au8522_state* state = fe->demodulator_priv; | ||
89 | |||
90 | dprintk("%s(%d)\n", __FUNCTION__, enable); | ||
91 | |||
92 | if (enable) | ||
93 | return au8522_writereg(state, 0x106, 1); | ||
94 | else | ||
95 | return au8522_writereg(state, 0x106, 0); | ||
96 | } | ||
97 | |||
98 | static int au8522_enable_modulation(struct dvb_frontend* fe, | ||
99 | fe_modulation_t m) | ||
100 | { | ||
101 | struct au8522_state* state = fe->demodulator_priv; | ||
102 | |||
103 | dprintk("%s(0x%08x)\n", __FUNCTION__, m); | ||
104 | |||
105 | switch(m) { | ||
106 | case VSB_8: | ||
107 | dprintk("%s() VSB_8\n", __FUNCTION__); | ||
108 | |||
109 | //au8522_writereg(state, 0x410b, 0x84); // Serial | ||
110 | |||
111 | //au8522_writereg(state, 0x8090, 0x82); | ||
112 | au8522_writereg(state, 0x8090, 0x84); | ||
113 | au8522_writereg(state, 0x4092, 0x11); | ||
114 | au8522_writereg(state, 0x2005, 0x00); | ||
115 | au8522_writereg(state, 0x8091, 0x80); | ||
116 | |||
117 | au8522_writereg(state, 0x80a3, 0x0c); | ||
118 | au8522_writereg(state, 0x80a4, 0xe8); | ||
119 | au8522_writereg(state, 0x8081, 0xc4); | ||
120 | au8522_writereg(state, 0x80a5, 0x40); | ||
121 | au8522_writereg(state, 0x80a7, 0x40); | ||
122 | au8522_writereg(state, 0x80a6, 0x67); | ||
123 | au8522_writereg(state, 0x8262, 0x20); | ||
124 | au8522_writereg(state, 0x821c, 0x30); | ||
125 | au8522_writereg(state, 0x80d8, 0x1a); | ||
126 | au8522_writereg(state, 0x8227, 0xa0); | ||
127 | au8522_writereg(state, 0x8121, 0xff); | ||
128 | au8522_writereg(state, 0x80a8, 0xf0); | ||
129 | au8522_writereg(state, 0x80a9, 0x05); | ||
130 | au8522_writereg(state, 0x80aa, 0x77); | ||
131 | au8522_writereg(state, 0x80ab, 0xf0); | ||
132 | au8522_writereg(state, 0x80ac, 0x05); | ||
133 | au8522_writereg(state, 0x80ad, 0x77); | ||
134 | au8522_writereg(state, 0x80ae, 0x41); | ||
135 | au8522_writereg(state, 0x80af, 0x66); | ||
136 | au8522_writereg(state, 0x821b, 0xcc); | ||
137 | au8522_writereg(state, 0x821d, 0x80); | ||
138 | au8522_writereg(state, 0x80b5, 0xfb); | ||
139 | au8522_writereg(state, 0x80b6, 0x8e); | ||
140 | au8522_writereg(state, 0x80b7, 0x39); | ||
141 | au8522_writereg(state, 0x80a4, 0xe8); | ||
142 | au8522_writereg(state, 0x8231, 0x13); | ||
143 | break; | ||
144 | case QAM_64: | ||
145 | case QAM_256: | ||
146 | au8522_writereg(state, 0x80a3, 0x09); | ||
147 | au8522_writereg(state, 0x80a4, 0x00); | ||
148 | au8522_writereg(state, 0x8081, 0xc4); | ||
149 | au8522_writereg(state, 0x80a5, 0x40); | ||
150 | au8522_writereg(state, 0x80b5, 0xfb); | ||
151 | au8522_writereg(state, 0x80b6, 0x8e); | ||
152 | au8522_writereg(state, 0x80b7, 0x39); | ||
153 | au8522_writereg(state, 0x80aa, 0x77); | ||
154 | au8522_writereg(state, 0x80ad, 0x77); | ||
155 | au8522_writereg(state, 0x80a6, 0x67); | ||
156 | au8522_writereg(state, 0x8262, 0x20); | ||
157 | au8522_writereg(state, 0x821c, 0x30); | ||
158 | au8522_writereg(state, 0x80b8, 0x3e); | ||
159 | au8522_writereg(state, 0x80b9, 0xf0); | ||
160 | au8522_writereg(state, 0x80ba, 0x01); | ||
161 | au8522_writereg(state, 0x80bb, 0x18); | ||
162 | au8522_writereg(state, 0x80bc, 0x50); | ||
163 | au8522_writereg(state, 0x80bd, 0x00); | ||
164 | au8522_writereg(state, 0x80be, 0xea); | ||
165 | au8522_writereg(state, 0x80bf, 0xef); | ||
166 | au8522_writereg(state, 0x80c0, 0xfc); | ||
167 | au8522_writereg(state, 0x80c1, 0xbd); | ||
168 | au8522_writereg(state, 0x80c2, 0x1f); | ||
169 | au8522_writereg(state, 0x80c3, 0xfc); | ||
170 | au8522_writereg(state, 0x80c4, 0xdd); | ||
171 | au8522_writereg(state, 0x80c5, 0xaf); | ||
172 | au8522_writereg(state, 0x80c6, 0x00); | ||
173 | au8522_writereg(state, 0x80c7, 0x38); | ||
174 | au8522_writereg(state, 0x80c8, 0x30); | ||
175 | au8522_writereg(state, 0x80c9, 0x05); | ||
176 | au8522_writereg(state, 0x80ca, 0x4a); | ||
177 | au8522_writereg(state, 0x80cb, 0xd0); | ||
178 | au8522_writereg(state, 0x80cc, 0x01); | ||
179 | au8522_writereg(state, 0x80cd, 0xd9); | ||
180 | au8522_writereg(state, 0x80ce, 0x6f); | ||
181 | au8522_writereg(state, 0x80cf, 0xf9); | ||
182 | au8522_writereg(state, 0x80d0, 0x70); | ||
183 | au8522_writereg(state, 0x80d1, 0xdf); | ||
184 | au8522_writereg(state, 0x80d2, 0xf7); | ||
185 | au8522_writereg(state, 0x80d3, 0xc2); | ||
186 | au8522_writereg(state, 0x80d4, 0xdf); | ||
187 | au8522_writereg(state, 0x80d5, 0x02); | ||
188 | au8522_writereg(state, 0x80d6, 0x9a); | ||
189 | au8522_writereg(state, 0x80d7, 0xd0); | ||
190 | au8522_writereg(state, 0x8250, 0x0d); | ||
191 | au8522_writereg(state, 0x8251, 0xcd); | ||
192 | au8522_writereg(state, 0x8252, 0xe0); | ||
193 | au8522_writereg(state, 0x8253, 0x05); | ||
194 | au8522_writereg(state, 0x8254, 0xa7); | ||
195 | au8522_writereg(state, 0x8255, 0xff); | ||
196 | au8522_writereg(state, 0x8256, 0xed); | ||
197 | au8522_writereg(state, 0x8257, 0x5b); | ||
198 | au8522_writereg(state, 0x8258, 0xae); | ||
199 | au8522_writereg(state, 0x8259, 0xe6); | ||
200 | au8522_writereg(state, 0x825a, 0x3d); | ||
201 | au8522_writereg(state, 0x825b, 0x0f); | ||
202 | au8522_writereg(state, 0x825c, 0x0d); | ||
203 | au8522_writereg(state, 0x825d, 0xea); | ||
204 | au8522_writereg(state, 0x825e, 0xf2); | ||
205 | au8522_writereg(state, 0x825f, 0x51); | ||
206 | au8522_writereg(state, 0x8260, 0xf5); | ||
207 | au8522_writereg(state, 0x8261, 0x06); | ||
208 | au8522_writereg(state, 0x821a, 0x00); | ||
209 | au8522_writereg(state, 0x8546, 0x40); | ||
210 | au8522_writereg(state, 0x8210, 0x26); | ||
211 | au8522_writereg(state, 0x8211, 0xf6); | ||
212 | au8522_writereg(state, 0x8212, 0x84); | ||
213 | au8522_writereg(state, 0x8213, 0x02); | ||
214 | au8522_writereg(state, 0x8502, 0x01); | ||
215 | au8522_writereg(state, 0x8121, 0x04); | ||
216 | au8522_writereg(state, 0x8122, 0x04); | ||
217 | au8522_writereg(state, 0x852e, 0x10); | ||
218 | au8522_writereg(state, 0x80a4, 0xca); | ||
219 | au8522_writereg(state, 0x80a7, 0x40); | ||
220 | au8522_writereg(state, 0x8526, 0x01); | ||
221 | break; | ||
222 | default: | ||
223 | dprintk("%s() Invalid modulation\n", __FUNCTION__); | ||
224 | return -EINVAL; | ||
225 | } | ||
226 | |||
227 | state->current_modulation = m; | ||
228 | |||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | /* Talk to the demod, set the FEC, GUARD, QAM settings etc */ | ||
233 | static int au8522_set_frontend (struct dvb_frontend* fe, | ||
234 | struct dvb_frontend_parameters *p) | ||
235 | { | ||
236 | struct au8522_state* state = fe->demodulator_priv; | ||
237 | |||
238 | dprintk("%s(frequency=%d)\n", __FUNCTION__, p->frequency); | ||
239 | |||
240 | state->current_frequency = p->frequency; | ||
241 | |||
242 | au8522_enable_modulation(fe, p->u.vsb.modulation); | ||
243 | |||
244 | /* Allow the demod to settle */ | ||
245 | msleep(100); | ||
246 | |||
247 | if (fe->ops.tuner_ops.set_params) { | ||
248 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 1); | ||
249 | fe->ops.tuner_ops.set_params(fe, p); | ||
250 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); | ||
251 | } | ||
252 | |||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | /* Reset the demod hardware and reset all of the configuration registers | ||
257 | to a default state. */ | ||
258 | static int au8522_init(struct dvb_frontend* fe) | ||
259 | { | ||
260 | struct au8522_state* state = fe->demodulator_priv; | ||
261 | dprintk("%s()\n", __FUNCTION__); | ||
262 | |||
263 | au8522_writereg(state, 0xa4, 1 << 5); | ||
264 | |||
265 | au8522_i2c_gate_ctrl(fe, 1); | ||
266 | |||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | static int au8522_read_status(struct dvb_frontend* fe, fe_status_t* status) | ||
271 | { | ||
272 | struct au8522_state* state = fe->demodulator_priv; | ||
273 | u8 reg; | ||
274 | u32 tuner_status = 0; | ||
275 | |||
276 | *status = 0; | ||
277 | |||
278 | if (state->current_modulation == VSB_8) { | ||
279 | dprintk("%s() Checking VSB_8\n", __FUNCTION__); | ||
280 | //au8522_writereg(state, 0x80a4, 0x20); | ||
281 | reg = au8522_readreg(state, 0x4088); | ||
282 | if(reg & 0x01) | ||
283 | *status |= FE_HAS_VITERBI; | ||
284 | if(reg & 0x02) | ||
285 | *status |= FE_HAS_LOCK | FE_HAS_SYNC; | ||
286 | } else { | ||
287 | dprintk("%s() Checking QAM\n", __FUNCTION__); | ||
288 | reg = au8522_readreg(state, 0x4541); | ||
289 | if(reg & 0x80) | ||
290 | *status |= FE_HAS_VITERBI; | ||
291 | if(reg & 0x20) | ||
292 | *status |= FE_HAS_LOCK | FE_HAS_SYNC; | ||
293 | } | ||
294 | |||
295 | switch(state->config->status_mode) { | ||
296 | case AU8522_DEMODLOCKING: | ||
297 | dprintk("%s() DEMODLOCKING\n", __FUNCTION__); | ||
298 | if (*status & FE_HAS_VITERBI) | ||
299 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; | ||
300 | break; | ||
301 | case AU8522_TUNERLOCKING: | ||
302 | /* Get the tuner status */ | ||
303 | dprintk("%s() TUNERLOCKING\n", __FUNCTION__); | ||
304 | if (fe->ops.tuner_ops.get_status) { | ||
305 | if (fe->ops.i2c_gate_ctrl) | ||
306 | fe->ops.i2c_gate_ctrl(fe, 1); | ||
307 | |||
308 | fe->ops.tuner_ops.get_status(fe, &tuner_status); | ||
309 | |||
310 | if (fe->ops.i2c_gate_ctrl) | ||
311 | fe->ops.i2c_gate_ctrl(fe, 0); | ||
312 | } | ||
313 | if (tuner_status) | ||
314 | *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; | ||
315 | break; | ||
316 | } | ||
317 | |||
318 | dprintk("%s() status 0x%08x\n", __FUNCTION__, *status); | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | static int au8522_read_snr(struct dvb_frontend* fe, u16* snr) | ||
324 | { | ||
325 | dprintk("%s()\n", __FUNCTION__); | ||
326 | |||
327 | *snr = 0; | ||
328 | |||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static int au8522_read_signal_strength(struct dvb_frontend* fe, | ||
333 | u16* signal_strength) | ||
334 | { | ||
335 | return au8522_read_snr(fe, signal_strength); | ||
336 | } | ||
337 | |||
338 | static int au8522_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) | ||
339 | { | ||
340 | struct au8522_state* state = fe->demodulator_priv; | ||
341 | |||
342 | *ucblocks = au8522_readreg(state, 0x4087); | ||
343 | |||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | static int au8522_read_ber(struct dvb_frontend* fe, u32* ber) | ||
348 | { | ||
349 | return au8522_read_ucblocks(fe, ber); | ||
350 | } | ||
351 | |||
352 | static int au8522_get_frontend(struct dvb_frontend* fe, | ||
353 | struct dvb_frontend_parameters *p) | ||
354 | { | ||
355 | struct au8522_state* state = fe->demodulator_priv; | ||
356 | |||
357 | p->frequency = state->current_frequency; | ||
358 | p->u.vsb.modulation = state->current_modulation; | ||
359 | |||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | static int au8522_get_tune_settings(struct dvb_frontend* fe, | ||
364 | struct dvb_frontend_tune_settings *tune) | ||
365 | { | ||
366 | tune->min_delay_ms = 1000; | ||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static void au8522_release(struct dvb_frontend* fe) | ||
371 | { | ||
372 | struct au8522_state* state = fe->demodulator_priv; | ||
373 | kfree(state); | ||
374 | } | ||
375 | |||
376 | static struct dvb_frontend_ops au8522_ops; | ||
377 | |||
378 | struct dvb_frontend* au8522_attach(const struct au8522_config* config, | ||
379 | struct i2c_adapter* i2c) | ||
380 | { | ||
381 | struct au8522_state* state = NULL; | ||
382 | |||
383 | /* allocate memory for the internal state */ | ||
384 | state = kmalloc(sizeof(struct au8522_state), GFP_KERNEL); | ||
385 | if (state == NULL) | ||
386 | goto error; | ||
387 | |||
388 | /* setup the state */ | ||
389 | state->config = config; | ||
390 | state->i2c = i2c; | ||
391 | /* create dvb_frontend */ | ||
392 | memcpy(&state->frontend.ops, &au8522_ops, | ||
393 | sizeof(struct dvb_frontend_ops)); | ||
394 | state->frontend.demodulator_priv = state; | ||
395 | |||
396 | if (au8522_init(&state->frontend) != 0) { | ||
397 | printk(KERN_ERR "%s: Failed to initialize correctly\n", | ||
398 | __FUNCTION__); | ||
399 | goto error; | ||
400 | } | ||
401 | |||
402 | /* Note: Leaving the I2C gate open here. */ | ||
403 | au8522_i2c_gate_ctrl(&state->frontend, 1); | ||
404 | |||
405 | return &state->frontend; | ||
406 | |||
407 | error: | ||
408 | kfree(state); | ||
409 | return NULL; | ||
410 | } | ||
411 | |||
412 | static struct dvb_frontend_ops au8522_ops = { | ||
413 | |||
414 | .info = { | ||
415 | .name = "Auvitek AU8522 QAM/8VSB Frontend", | ||
416 | .type = FE_ATSC, | ||
417 | .frequency_min = 54000000, | ||
418 | .frequency_max = 858000000, | ||
419 | .frequency_stepsize = 62500, | ||
420 | .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB | ||
421 | }, | ||
422 | |||
423 | .init = au8522_init, | ||
424 | .i2c_gate_ctrl = au8522_i2c_gate_ctrl, | ||
425 | .set_frontend = au8522_set_frontend, | ||
426 | .get_frontend = au8522_get_frontend, | ||
427 | .get_tune_settings = au8522_get_tune_settings, | ||
428 | .read_status = au8522_read_status, | ||
429 | .read_ber = au8522_read_ber, | ||
430 | .read_signal_strength = au8522_read_signal_strength, | ||
431 | .read_snr = au8522_read_snr, | ||
432 | .read_ucblocks = au8522_read_ucblocks, | ||
433 | .release = au8522_release, | ||
434 | }; | ||
435 | |||
436 | module_param(debug, int, 0644); | ||
437 | MODULE_PARM_DESC(debug, "Enable verbose debug messages"); | ||
438 | |||
439 | MODULE_DESCRIPTION("Auvitek AU8522 QAM-B/ATSC Demodulator driver"); | ||
440 | MODULE_AUTHOR("Steven Toth"); | ||
441 | MODULE_LICENSE("GPL"); | ||
442 | |||
443 | EXPORT_SYMBOL(au8522_attach); | ||
444 | |||
445 | /* | ||
446 | * Local variables: | ||
447 | * c-basic-offset: 8 | ||
448 | */ | ||
diff --git a/drivers/media/dvb/frontends/au8522.h b/drivers/media/dvb/frontends/au8522.h new file mode 100644 index 000000000000..a75627155fed --- /dev/null +++ b/drivers/media/dvb/frontends/au8522.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | Auvitek AU8522 QAM/8VSB demodulator driver | ||
3 | |||
4 | Copyright (C) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | (at your option) any later version. | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | |||
20 | */ | ||
21 | |||
22 | #ifndef __AU8522_H__ | ||
23 | #define __AU8522_H__ | ||
24 | |||
25 | #include <linux/dvb/frontend.h> | ||
26 | |||
27 | struct au8522_config | ||
28 | { | ||
29 | /* the demodulator's i2c address */ | ||
30 | u8 demod_address; | ||
31 | |||
32 | /* Return lock status based on tuner lock, or demod lock */ | ||
33 | #define AU8522_TUNERLOCKING 0 | ||
34 | #define AU8522_DEMODLOCKING 1 | ||
35 | u8 status_mode; | ||
36 | }; | ||
37 | |||
38 | #if defined(CONFIG_DVB_AU8522) || (defined(CONFIG_DVB_AU8522_MODULE) && defined(MODULE)) | ||
39 | extern struct dvb_frontend* au8522_attach(const struct au8522_config* config, | ||
40 | struct i2c_adapter* i2c); | ||
41 | #else | ||
42 | static inline struct dvb_frontend* au8522_attach(const struct au8522_config* config, | ||
43 | struct i2c_adapter* i2c) | ||
44 | { | ||
45 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); | ||
46 | return NULL; | ||
47 | } | ||
48 | #endif /* CONFIG_DVB_AU8522 */ | ||
49 | |||
50 | #endif /* __AU8522_H__ */ | ||
51 | |||
52 | /* | ||
53 | * Local variables: | ||
54 | * c-basic-offset: 8 | ||
55 | */ | ||
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 54b9f84e9a3e..fe9a4cc14141 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig | |||
@@ -698,6 +698,8 @@ source "drivers/media/video/cx88/Kconfig" | |||
698 | 698 | ||
699 | source "drivers/media/video/cx23885/Kconfig" | 699 | source "drivers/media/video/cx23885/Kconfig" |
700 | 700 | ||
701 | source "drivers/media/video/au0828/Kconfig" | ||
702 | |||
701 | source "drivers/media/video/ivtv/Kconfig" | 703 | source "drivers/media/video/ivtv/Kconfig" |
702 | 704 | ||
703 | config VIDEO_M32R_AR | 705 | config VIDEO_M32R_AR |
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index fe3be94afd10..be14227f3726 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
@@ -143,5 +143,7 @@ obj-$(CONFIG_SOC_CAMERA) += soc_camera.o | |||
143 | obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o | 143 | obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o |
144 | obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o | 144 | obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o |
145 | 145 | ||
146 | obj-$(CONFIG_VIDEO_AU0828) += au0828/ | ||
147 | |||
146 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | 148 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core |
147 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends | 149 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends |
diff --git a/drivers/media/video/au0828/Kconfig b/drivers/media/video/au0828/Kconfig new file mode 100644 index 000000000000..38d68ee8026a --- /dev/null +++ b/drivers/media/video/au0828/Kconfig | |||
@@ -0,0 +1,10 @@ | |||
1 | |||
2 | config VIDEO_AU0828 | ||
3 | tristate "Auvitek AU0828 support" | ||
4 | depends on VIDEO_DEV && I2C && INPUT | ||
5 | select I2C_ALGOBIT | ||
6 | ---help--- | ||
7 | This is a video4linux driver for Auvitek's USB device. | ||
8 | |||
9 | To compile this driver as a module, choose M here: the | ||
10 | module will be called ambarella | ||
diff --git a/drivers/media/video/au0828/Makefile b/drivers/media/video/au0828/Makefile new file mode 100644 index 000000000000..9f4f572c89c5 --- /dev/null +++ b/drivers/media/video/au0828/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o | ||
2 | |||
3 | obj-$(CONFIG_VIDEO_AU0828) += au0828.o | ||
4 | |||
5 | EXTRA_CFLAGS += -Idrivers/media/video | ||
6 | EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core | ||
7 | EXTRA_CFLAGS += -Idrivers/media/dvb/frontends | ||
8 | |||
9 | EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m) | ||
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c new file mode 100644 index 000000000000..c4cb11e9d6fc --- /dev/null +++ b/drivers/media/video/au0828/au0828-cards.c | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include "au0828.h" | ||
23 | #include "au0828-cards.h" | ||
24 | |||
25 | #define _dbg(level, fmt, arg...)\ | ||
26 | do {\ | ||
27 | if (debug >= level) \ | ||
28 | printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\ | ||
29 | } while (0) | ||
30 | |||
31 | struct au0828_board au0828_boards[] = { | ||
32 | [AU0828_BOARD_UNKNOWN] = { | ||
33 | .name = "Unknown board", | ||
34 | }, | ||
35 | [AU0828_BOARD_HAUPPAUGE_HVR850] = { | ||
36 | .name = "Hauppauge HVR850", | ||
37 | }, | ||
38 | [AU0828_BOARD_HAUPPAUGE_HVR950Q] = { | ||
39 | .name = "Hauppauge HVR950Q", | ||
40 | }, | ||
41 | [AU0828_BOARD_DVICO_FUSIONHDTV7] = { | ||
42 | .name = "DViCO FusionHDTV USB", | ||
43 | }, | ||
44 | }; | ||
45 | const unsigned int au0828_bcount = ARRAY_SIZE(au0828_boards); | ||
46 | |||
47 | /* Tuner callback function for au0828 boards. Currently only needed | ||
48 | * for HVR1500Q, which has an xc5000 tuner. | ||
49 | */ | ||
50 | int au0828_tuner_callback(void *priv, int command, int arg) | ||
51 | { | ||
52 | struct au0828_dev *dev = priv; | ||
53 | |||
54 | switch(dev->board) { | ||
55 | case AU0828_BOARD_HAUPPAUGE_HVR850: | ||
56 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: | ||
57 | case AU0828_BOARD_DVICO_FUSIONHDTV7: | ||
58 | if(command == 0) { | ||
59 | /* Tuner Reset Command from xc5000 */ | ||
60 | /* Drive the tuner into reset and out */ | ||
61 | au0828_clear(dev, REG_001, 2); | ||
62 | mdelay(200); | ||
63 | au0828_set(dev, REG_001, 2); | ||
64 | mdelay(50); | ||
65 | return 0; | ||
66 | } | ||
67 | else { | ||
68 | printk(KERN_ERR | ||
69 | "%s(): Unknown command.\n", __FUNCTION__); | ||
70 | return -EINVAL; | ||
71 | } | ||
72 | break; | ||
73 | } | ||
74 | |||
75 | return 0; /* Should never be here */ | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * The bridge has between 8 and 12 gpios. | ||
80 | * Regs 1 and 0 deal with output enables. | ||
81 | * Regs 3 and 2 * deal with direction. | ||
82 | */ | ||
83 | void au0828_gpio_setup(struct au0828_dev *dev) | ||
84 | { | ||
85 | switch(dev->board) { | ||
86 | case AU0828_BOARD_HAUPPAUGE_HVR850: | ||
87 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: | ||
88 | /* GPIO's | ||
89 | * 4 - CS5340 | ||
90 | * 5 - AU8522 Demodulator | ||
91 | * 6 - eeprom W/P | ||
92 | * 9 - XC5000 Tuner | ||
93 | */ | ||
94 | |||
95 | /* Into reset */ | ||
96 | au0828_write(dev, REG_003, 0x02); | ||
97 | au0828_write(dev, REG_002, 0x88 | 0x20); | ||
98 | au0828_write(dev, REG_001, 0x0); | ||
99 | au0828_write(dev, REG_000, 0x0); | ||
100 | msleep(100); | ||
101 | |||
102 | /* Out of reset */ | ||
103 | au0828_write(dev, REG_003, 0x02); | ||
104 | au0828_write(dev, REG_001, 0x02); | ||
105 | au0828_write(dev, REG_002, 0x88 | 0x20); | ||
106 | au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40); | ||
107 | msleep(250); | ||
108 | break; | ||
109 | case AU0828_BOARD_DVICO_FUSIONHDTV7: | ||
110 | /* GPIO's | ||
111 | * 6 - ? | ||
112 | * 8 - AU8522 Demodulator | ||
113 | * 9 - XC5000 Tuner | ||
114 | */ | ||
115 | |||
116 | /* Into reset */ | ||
117 | au0828_write(dev, REG_003, 0x02); | ||
118 | au0828_write(dev, REG_002, 0xa0); | ||
119 | au0828_write(dev, REG_001, 0x0); | ||
120 | au0828_write(dev, REG_000, 0x0); | ||
121 | msleep(100); | ||
122 | |||
123 | /* Out of reset */ | ||
124 | au0828_write(dev, REG_003, 0x02); | ||
125 | au0828_write(dev, REG_002, 0xa0); | ||
126 | au0828_write(dev, REG_001, 0x02); | ||
127 | au0828_write(dev, REG_000, 0xa0); | ||
128 | msleep(250); | ||
129 | break; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | /* table of devices that work with this driver */ | ||
134 | struct usb_device_id au0828_usb_id_table [] = { | ||
135 | { USB_DEVICE(0x2040, 0x7200), | ||
136 | .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q }, | ||
137 | { USB_DEVICE(0x2040, 0x7240), | ||
138 | .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 }, | ||
139 | { USB_DEVICE(0x0fe9, 0xd620), | ||
140 | .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 }, | ||
141 | { }, | ||
142 | }; | ||
143 | |||
144 | MODULE_DEVICE_TABLE(usb, au0828_usb_id_table); | ||
diff --git a/drivers/media/video/au0828/au0828-cards.h b/drivers/media/video/au0828/au0828-cards.h new file mode 100644 index 000000000000..e26f54a961d0 --- /dev/null +++ b/drivers/media/video/au0828/au0828-cards.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #define AU0828_BOARD_UNKNOWN 0 | ||
23 | #define AU0828_BOARD_HAUPPAUGE_HVR950Q 1 | ||
24 | #define AU0828_BOARD_HAUPPAUGE_HVR850 2 | ||
25 | #define AU0828_BOARD_DVICO_FUSIONHDTV7 3 | ||
diff --git a/drivers/media/video/au0828/au0828-core.c b/drivers/media/video/au0828/au0828-core.c new file mode 100644 index 000000000000..8d0b8a8b06bd --- /dev/null +++ b/drivers/media/video/au0828/au0828-core.c | |||
@@ -0,0 +1,252 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/videodev2.h> | ||
24 | #include <media/v4l2-common.h> | ||
25 | #include <linux/mutex.h> | ||
26 | |||
27 | #include "au0828.h" | ||
28 | |||
29 | static unsigned int debug; | ||
30 | module_param(debug, int, 0644); | ||
31 | MODULE_PARM_DESC(debug, "enable debug messages"); | ||
32 | |||
33 | #define _err(fmt, arg...)\ | ||
34 | do {\ | ||
35 | printk(KERN_ERR DRIVER_NAME "/0: " fmt, ## arg);\ | ||
36 | } while (0) | ||
37 | |||
38 | #define _info(fmt, arg...)\ | ||
39 | do {\ | ||
40 | printk(KERN_INFO DRIVER_NAME "/0: " fmt, ## arg);\ | ||
41 | } while (0) | ||
42 | |||
43 | #define _dbg(level, fmt, arg...)\ | ||
44 | do {\ | ||
45 | if (debug >= level) \ | ||
46 | printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\ | ||
47 | } while (0) | ||
48 | |||
49 | #define _AU0828_BULKPIPE 0x03 | ||
50 | #define _BULKPIPESIZE 0xffff | ||
51 | |||
52 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, | ||
53 | u16 index, unsigned char *cp, u16 size); | ||
54 | static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, | ||
55 | u16 index, unsigned char *cp, u16 size); | ||
56 | |||
57 | /* USB Direction */ | ||
58 | #define CMD_REQUEST_IN 0x00 | ||
59 | #define CMD_REQUEST_OUT 0x01 | ||
60 | |||
61 | u32 au0828_readreg(struct au0828_dev *dev, u16 reg) | ||
62 | { | ||
63 | recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1); | ||
64 | _dbg(3,"%s(0x%x) = 0x%x\n", __FUNCTION__, reg, dev->ctrlmsg[0]); | ||
65 | return dev->ctrlmsg[0]; | ||
66 | } | ||
67 | |||
68 | u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val) | ||
69 | { | ||
70 | _dbg(3,"%s(0x%x, 0x%x)\n", __FUNCTION__, reg, val); | ||
71 | return send_control_msg(dev, CMD_REQUEST_OUT, val, reg, dev->ctrlmsg, 0); | ||
72 | } | ||
73 | |||
74 | static void cmd_msg_dump(struct au0828_dev *dev) | ||
75 | { | ||
76 | int i; | ||
77 | |||
78 | for (i = 0;i < sizeof(dev->ctrlmsg); i+=16) | ||
79 | _dbg(1,"%s() %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x " | ||
80 | "%02x %02x %02x %02x %02x %02x\n", | ||
81 | __FUNCTION__, | ||
82 | dev->ctrlmsg[i+0], dev->ctrlmsg[i+1], | ||
83 | dev->ctrlmsg[i+2], dev->ctrlmsg[i+3], | ||
84 | dev->ctrlmsg[i+4], dev->ctrlmsg[i+5], | ||
85 | dev->ctrlmsg[i+6], dev->ctrlmsg[i+7], | ||
86 | dev->ctrlmsg[i+8], dev->ctrlmsg[i+9], | ||
87 | dev->ctrlmsg[i+10], dev->ctrlmsg[i+11], | ||
88 | dev->ctrlmsg[i+12], dev->ctrlmsg[i+13], | ||
89 | dev->ctrlmsg[i+14], dev->ctrlmsg[i+15]); | ||
90 | } | ||
91 | |||
92 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, | ||
93 | u16 index, unsigned char *cp, u16 size) | ||
94 | { | ||
95 | int status = -ENODEV; | ||
96 | mutex_lock(&dev->mutex); | ||
97 | if (dev->usbdev) { | ||
98 | |||
99 | /* cp must be memory that has been allocated by kmalloc */ | ||
100 | status = usb_control_msg(dev->usbdev, | ||
101 | usb_sndctrlpipe(dev->usbdev, 0), | ||
102 | request, | ||
103 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
104 | value, index, | ||
105 | cp, size, 1000); | ||
106 | |||
107 | status = min(status, 0); | ||
108 | |||
109 | if (status < 0) { | ||
110 | _err("%s() Failed sending control message, error %d.\n", | ||
111 | __FUNCTION__, | ||
112 | status); | ||
113 | } | ||
114 | |||
115 | } | ||
116 | mutex_unlock(&dev->mutex); | ||
117 | return status; | ||
118 | } | ||
119 | |||
120 | static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, | ||
121 | u16 index, unsigned char *cp, u16 size) | ||
122 | { | ||
123 | int status = -ENODEV; | ||
124 | mutex_lock(&dev->mutex); | ||
125 | if (dev->usbdev) { | ||
126 | |||
127 | memset(dev->ctrlmsg, 0, sizeof(dev->ctrlmsg)); | ||
128 | |||
129 | /* cp must be memory that has been allocated by kmalloc */ | ||
130 | status = usb_control_msg(dev->usbdev, | ||
131 | usb_rcvctrlpipe(dev->usbdev, 0), | ||
132 | request, | ||
133 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
134 | value, index, | ||
135 | cp, size, 1000); | ||
136 | |||
137 | status = min(status, 0); | ||
138 | |||
139 | if (status < 0) { | ||
140 | _err("%s() Failed receiving ctrl msg, error %d.\n", | ||
141 | __FUNCTION__, | ||
142 | status); | ||
143 | } | ||
144 | else | ||
145 | if (debug > 4) | ||
146 | cmd_msg_dump(dev); | ||
147 | } | ||
148 | mutex_unlock(&dev->mutex); | ||
149 | return status; | ||
150 | } | ||
151 | static void au0828_usb_disconnect(struct usb_interface *interface) | ||
152 | { | ||
153 | struct au0828_dev *dev = usb_get_intfdata(interface); | ||
154 | |||
155 | _dbg(1,"%s()\n", __FUNCTION__); | ||
156 | |||
157 | /* Digital TV */ | ||
158 | au0828_dvb_unregister(dev); | ||
159 | |||
160 | /* I2C */ | ||
161 | au0828_i2c_unregister(dev); | ||
162 | |||
163 | usb_set_intfdata(interface, NULL); | ||
164 | |||
165 | mutex_lock(&dev->mutex); | ||
166 | dev->usbdev = NULL; | ||
167 | mutex_unlock(&dev->mutex); | ||
168 | |||
169 | kfree(dev); | ||
170 | |||
171 | } | ||
172 | |||
173 | static int au0828_usb_probe (struct usb_interface *interface, | ||
174 | const struct usb_device_id *id) | ||
175 | { | ||
176 | int ifnum; | ||
177 | struct au0828_dev *dev; | ||
178 | struct usb_device *usbdev = interface_to_usbdev(interface); | ||
179 | |||
180 | ifnum = interface->altsetting->desc.bInterfaceNumber; | ||
181 | |||
182 | if (ifnum != 0) | ||
183 | return -ENODEV; | ||
184 | |||
185 | _dbg(1,"%s() vendor id 0x%x device id 0x%x ifnum:%d\n", | ||
186 | __FUNCTION__, | ||
187 | le16_to_cpu(usbdev->descriptor.idVendor), | ||
188 | le16_to_cpu(usbdev->descriptor.idProduct), | ||
189 | ifnum); | ||
190 | |||
191 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
192 | if (dev == NULL) { | ||
193 | _err("Unable to allocate memory\n"); | ||
194 | return -ENOMEM; | ||
195 | } | ||
196 | |||
197 | mutex_init(&dev->mutex); | ||
198 | mutex_init(&dev->dvb.lock); | ||
199 | dev->usbdev = usbdev; | ||
200 | dev->board = id->driver_info; | ||
201 | |||
202 | usb_set_intfdata(interface, dev); | ||
203 | |||
204 | /* Power Up the bridge */ | ||
205 | au0828_write(dev, REG_600, 1 << 4); | ||
206 | |||
207 | /* Bring up the GPIO's and supporting devices */ | ||
208 | au0828_gpio_setup(dev); | ||
209 | |||
210 | /* I2C */ | ||
211 | au0828_i2c_register(dev); | ||
212 | |||
213 | /* Digital TV */ | ||
214 | au0828_dvb_register(dev); | ||
215 | |||
216 | _info("Registered device AU0828 [%s]\n", | ||
217 | au0828_boards[dev->board].name); | ||
218 | |||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | static struct usb_driver au0828_usb_driver = { | ||
223 | .name = DRIVER_NAME, | ||
224 | .probe = au0828_usb_probe, | ||
225 | .disconnect = au0828_usb_disconnect, | ||
226 | .id_table = au0828_usb_id_table, | ||
227 | }; | ||
228 | |||
229 | static int __init au0828_init(void) | ||
230 | { | ||
231 | int ret; | ||
232 | |||
233 | _info("au0828 driver loaded\n"); | ||
234 | |||
235 | ret = usb_register(&au0828_usb_driver); | ||
236 | if (ret) | ||
237 | _err("usb_register failed, error = %d\n", ret); | ||
238 | |||
239 | return ret; | ||
240 | } | ||
241 | |||
242 | static void __exit au0828_exit(void) | ||
243 | { | ||
244 | usb_deregister(&au0828_usb_driver); | ||
245 | } | ||
246 | |||
247 | module_init(au0828_init); | ||
248 | module_exit(au0828_exit); | ||
249 | |||
250 | MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products"); | ||
251 | MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>"); | ||
252 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c new file mode 100644 index 000000000000..3c8a29eafc2d --- /dev/null +++ b/drivers/media/video/au0828/au0828-dvb.c | |||
@@ -0,0 +1,371 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/suspend.h> | ||
26 | #include <media/v4l2-common.h> | ||
27 | |||
28 | #include "au0828.h" | ||
29 | |||
30 | #include "au8522.h" | ||
31 | #include "xc5000.h" | ||
32 | |||
33 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
34 | |||
35 | unsigned int dvb_debug = 1; | ||
36 | |||
37 | #define _dbg(level, fmt, arg...)\ | ||
38 | do { if (dvb_debug >= level)\ | ||
39 | printk(KERN_DEBUG "%s/0: " fmt, DRIVER_NAME, ## arg);\ | ||
40 | } while (0) | ||
41 | |||
42 | static struct au8522_config hauppauge_hvr950q_config = { | ||
43 | .demod_address = 0x8e >> 1, | ||
44 | .status_mode = AU8522_DEMODLOCKING, | ||
45 | }; | ||
46 | |||
47 | static struct xc5000_config hauppauge_hvr950q_tunerconfig = { | ||
48 | .i2c_address = 0x61, | ||
49 | .if_khz = 6000, | ||
50 | .tuner_callback = au0828_tuner_callback | ||
51 | }; | ||
52 | |||
53 | /*-------------------------------------------------------------------*/ | ||
54 | static void urb_completion(struct urb *purb) | ||
55 | { | ||
56 | u8 *ptr; | ||
57 | struct au0828_dev *dev = purb->context; | ||
58 | int ptype = usb_pipetype(purb->pipe); | ||
59 | |||
60 | if (dev->urb_streaming == 0) | ||
61 | return; | ||
62 | |||
63 | if (ptype != PIPE_BULK) { | ||
64 | printk(KERN_ERR "%s() Unsupported URB type %d\n", __FUNCTION__, ptype); | ||
65 | return; | ||
66 | } | ||
67 | |||
68 | ptr = (u8 *)purb->transfer_buffer; | ||
69 | |||
70 | /* Feed the transport payload into the kernel demux */ | ||
71 | dvb_dmx_swfilter_packets(&dev->dvb.demux, purb->transfer_buffer, purb->actual_length / 188); | ||
72 | |||
73 | /* Clean the buffer before we requeue */ | ||
74 | memset(purb->transfer_buffer, 0, URB_BUFSIZE); | ||
75 | |||
76 | /* Requeue URB */ | ||
77 | usb_submit_urb(purb, GFP_ATOMIC); | ||
78 | } | ||
79 | |||
80 | static int stop_urb_transfer(struct au0828_dev *dev) | ||
81 | { | ||
82 | int i; | ||
83 | |||
84 | printk(KERN_INFO "%s()\n", __FUNCTION__); | ||
85 | |||
86 | /* FIXME: Do we need to free the transfer_buffers? */ | ||
87 | for (i = 0; i < URB_COUNT; i++) { | ||
88 | usb_kill_urb(dev->urbs[i]); | ||
89 | kfree(dev->urbs[i]->transfer_buffer); | ||
90 | usb_free_urb(dev->urbs[i]); | ||
91 | } | ||
92 | |||
93 | dev->urb_streaming = 0; | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | #define _AU0828_BULKPIPE 0x83 | ||
99 | #define _BULKPIPESIZE 0xe522 | ||
100 | |||
101 | static int start_urb_transfer(struct au0828_dev *dev) | ||
102 | { | ||
103 | struct urb *purb; | ||
104 | int i, ret = -ENOMEM; | ||
105 | unsigned int pipe = usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE); | ||
106 | int pipesize = usb_maxpacket(dev->usbdev, pipe, usb_pipeout(pipe)); | ||
107 | int packets = _BULKPIPESIZE / pipesize; | ||
108 | int transfer_buflen = packets * pipesize; | ||
109 | |||
110 | printk(KERN_INFO "%s() transfer_buflen = %d\n", __FUNCTION__, transfer_buflen); | ||
111 | |||
112 | if (dev->urb_streaming) { | ||
113 | printk("%s: iso xfer already running!\n", __FUNCTION__); | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | for (i = 0; i < URB_COUNT; i++) { | ||
118 | |||
119 | dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL); | ||
120 | if (!dev->urbs[i]) { | ||
121 | goto err; | ||
122 | } | ||
123 | |||
124 | purb = dev->urbs[i]; | ||
125 | |||
126 | purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL); | ||
127 | if (!purb->transfer_buffer) { | ||
128 | usb_free_urb(purb); | ||
129 | dev->urbs[i] = 0; | ||
130 | goto err; | ||
131 | } | ||
132 | |||
133 | purb->status = -EINPROGRESS; | ||
134 | usb_fill_bulk_urb(purb, | ||
135 | dev->usbdev, | ||
136 | usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE), | ||
137 | purb->transfer_buffer, | ||
138 | URB_BUFSIZE, | ||
139 | urb_completion, | ||
140 | dev); | ||
141 | |||
142 | } | ||
143 | |||
144 | for (i = 0; i < URB_COUNT; i++) { | ||
145 | ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC); | ||
146 | if (ret != 0) { | ||
147 | stop_urb_transfer(dev); | ||
148 | printk("%s: failed urb submission, err = %d\n", __FUNCTION__, ret); | ||
149 | return ret; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | dev->urb_streaming = 1; | ||
154 | ret = 0; | ||
155 | |||
156 | err: | ||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | static int au0828_dvb_start_feed(struct dvb_demux_feed *feed) | ||
161 | { | ||
162 | struct dvb_demux *demux = feed->demux; | ||
163 | struct au0828_dev *dev = (struct au0828_dev *) demux->priv; | ||
164 | struct au0828_dvb *dvb = &dev->dvb; | ||
165 | int ret = 0; | ||
166 | |||
167 | printk(KERN_INFO "%s() pid = 0x%x index = %d\n", __FUNCTION__, feed->pid, feed->index); | ||
168 | |||
169 | if (!demux->dmx.frontend) | ||
170 | return -EINVAL; | ||
171 | |||
172 | printk(KERN_INFO "%s() Preparing, feeding = %d\n", __FUNCTION__, dvb->feeding); | ||
173 | if (dvb) { | ||
174 | mutex_lock(&dvb->lock); | ||
175 | if (dvb->feeding++ == 0) { | ||
176 | printk(KERN_INFO "%s() Starting Transport DMA\n", | ||
177 | __FUNCTION__); | ||
178 | au0828_write(dev, 0x608, 0x90); | ||
179 | au0828_write(dev, 0x609, 0x72); | ||
180 | au0828_write(dev, 0x60a, 0x71); | ||
181 | au0828_write(dev, 0x60b, 0x01); | ||
182 | ret = start_urb_transfer(dev); | ||
183 | } | ||
184 | mutex_unlock(&dvb->lock); | ||
185 | } | ||
186 | |||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed) | ||
191 | { | ||
192 | struct dvb_demux *demux = feed->demux; | ||
193 | struct au0828_dev *dev = (struct au0828_dev *) demux->priv; | ||
194 | struct au0828_dvb *dvb = &dev->dvb; | ||
195 | int ret = 0; | ||
196 | |||
197 | printk(KERN_INFO "%s() pid = 0x%x index = %d\n", __FUNCTION__, feed->pid, feed->index); | ||
198 | |||
199 | if (dvb) { | ||
200 | mutex_lock(&dvb->lock); | ||
201 | if (--dvb->feeding == 0) { | ||
202 | printk(KERN_INFO "%s() Stopping Transport DMA\n", | ||
203 | __FUNCTION__); | ||
204 | au0828_write(dev, 0x608, 0x00); | ||
205 | au0828_write(dev, 0x609, 0x00); | ||
206 | au0828_write(dev, 0x60a, 0x00); | ||
207 | au0828_write(dev, 0x60b, 0x00); | ||
208 | ret = stop_urb_transfer(dev); | ||
209 | } | ||
210 | mutex_unlock(&dvb->lock); | ||
211 | } | ||
212 | |||
213 | return ret; | ||
214 | } | ||
215 | |||
216 | int dvb_register(struct au0828_dev *dev) | ||
217 | { | ||
218 | struct au0828_dvb *dvb = &dev->dvb; | ||
219 | int result; | ||
220 | |||
221 | /* register adapter */ | ||
222 | result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE, | ||
223 | &dev->usbdev->dev, adapter_nr); | ||
224 | if (result < 0) { | ||
225 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", | ||
226 | DRIVER_NAME, result); | ||
227 | goto fail_adapter; | ||
228 | } | ||
229 | dvb->adapter.priv = dev; | ||
230 | |||
231 | /* register frontend */ | ||
232 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); | ||
233 | if (result < 0) { | ||
234 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", | ||
235 | DRIVER_NAME, result); | ||
236 | goto fail_frontend; | ||
237 | } | ||
238 | |||
239 | /* register demux stuff */ | ||
240 | dvb->demux.dmx.capabilities = | ||
241 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | | ||
242 | DMX_MEMORY_BASED_FILTERING; | ||
243 | dvb->demux.priv = dev; | ||
244 | dvb->demux.filternum = 256; | ||
245 | dvb->demux.feednum = 256; | ||
246 | dvb->demux.start_feed = au0828_dvb_start_feed; | ||
247 | dvb->demux.stop_feed = au0828_dvb_stop_feed; | ||
248 | result = dvb_dmx_init(&dvb->demux); | ||
249 | if (result < 0) { | ||
250 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", | ||
251 | DRIVER_NAME, result); | ||
252 | goto fail_dmx; | ||
253 | } | ||
254 | |||
255 | dvb->dmxdev.filternum = 256; | ||
256 | dvb->dmxdev.demux = &dvb->demux.dmx; | ||
257 | dvb->dmxdev.capabilities = 0; | ||
258 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); | ||
259 | if (result < 0) { | ||
260 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", | ||
261 | DRIVER_NAME, result); | ||
262 | goto fail_dmxdev; | ||
263 | } | ||
264 | |||
265 | dvb->fe_hw.source = DMX_FRONTEND_0; | ||
266 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
267 | if (result < 0) { | ||
268 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", | ||
269 | DRIVER_NAME, result); | ||
270 | goto fail_fe_hw; | ||
271 | } | ||
272 | |||
273 | dvb->fe_mem.source = DMX_MEMORY_FE; | ||
274 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
275 | if (result < 0) { | ||
276 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", | ||
277 | DRIVER_NAME, result); | ||
278 | goto fail_fe_mem; | ||
279 | } | ||
280 | |||
281 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
282 | if (result < 0) { | ||
283 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", | ||
284 | DRIVER_NAME, result); | ||
285 | goto fail_fe_conn; | ||
286 | } | ||
287 | |||
288 | /* register network adapter */ | ||
289 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); | ||
290 | return 0; | ||
291 | |||
292 | fail_fe_conn: | ||
293 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
294 | fail_fe_mem: | ||
295 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
296 | fail_fe_hw: | ||
297 | dvb_dmxdev_release(&dvb->dmxdev); | ||
298 | fail_dmxdev: | ||
299 | dvb_dmx_release(&dvb->demux); | ||
300 | fail_dmx: | ||
301 | dvb_unregister_frontend(dvb->frontend); | ||
302 | fail_frontend: | ||
303 | dvb_frontend_detach(dvb->frontend); | ||
304 | dvb_unregister_adapter(&dvb->adapter); | ||
305 | fail_adapter: | ||
306 | return result; | ||
307 | } | ||
308 | |||
309 | void au0828_dvb_unregister(struct au0828_dev *dev) | ||
310 | { | ||
311 | struct au0828_dvb *dvb = &dev->dvb; | ||
312 | |||
313 | dvb_net_release(&dvb->net); | ||
314 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | ||
315 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | ||
316 | dvb_dmxdev_release(&dvb->dmxdev); | ||
317 | dvb_dmx_release(&dvb->demux); | ||
318 | dvb_unregister_frontend(dvb->frontend); | ||
319 | dvb_frontend_detach(dvb->frontend); | ||
320 | dvb_unregister_adapter(&dvb->adapter); | ||
321 | } | ||
322 | |||
323 | /* All the DVB attach calls go here, this function get's modified | ||
324 | * for each new card. No other function in this file needs | ||
325 | * to change. | ||
326 | */ | ||
327 | int au0828_dvb_register(struct au0828_dev *dev) | ||
328 | { | ||
329 | struct au0828_dvb *dvb = &dev->dvb; | ||
330 | int ret; | ||
331 | |||
332 | /* init frontend */ | ||
333 | switch (dev->board) { | ||
334 | case AU0828_BOARD_HAUPPAUGE_HVR850: | ||
335 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: | ||
336 | case AU0828_BOARD_DVICO_FUSIONHDTV7: | ||
337 | dvb->frontend = dvb_attach(au8522_attach, | ||
338 | &hauppauge_hvr950q_config, | ||
339 | &dev->i2c_adap); | ||
340 | if (dvb->frontend != NULL) { | ||
341 | hauppauge_hvr950q_tunerconfig.priv = dev; | ||
342 | dvb_attach(xc5000_attach, dvb->frontend, | ||
343 | &dev->i2c_adap, | ||
344 | &hauppauge_hvr950q_tunerconfig); | ||
345 | } | ||
346 | break; | ||
347 | default: | ||
348 | printk("The frontend of your DVB/ATSC card isn't supported yet\n"); | ||
349 | break; | ||
350 | } | ||
351 | if (NULL == dvb->frontend) { | ||
352 | printk("Frontend initialization failed\n"); | ||
353 | return -1; | ||
354 | } | ||
355 | |||
356 | /* Put the analog decoder in standby to keep it quiet */ | ||
357 | au0828_call_i2c_clients(dev, TUNER_SET_STANDBY, NULL); | ||
358 | |||
359 | if (dvb->frontend->ops.analog_ops.standby) | ||
360 | dvb->frontend->ops.analog_ops.standby(dvb->frontend); | ||
361 | |||
362 | /* register everything */ | ||
363 | ret = dvb_register(dev); | ||
364 | if (ret < 0) { | ||
365 | if (dvb->frontend->ops.release) | ||
366 | dvb->frontend->ops.release(dvb->frontend); | ||
367 | return ret; | ||
368 | } | ||
369 | |||
370 | return 0; | ||
371 | } | ||
diff --git a/drivers/media/video/au0828/au0828-i2c.c b/drivers/media/video/au0828/au0828-i2c.c new file mode 100644 index 000000000000..3e7482481152 --- /dev/null +++ b/drivers/media/video/au0828/au0828-i2c.c | |||
@@ -0,0 +1,402 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek AU0828 USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/moduleparam.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <asm/io.h> | ||
27 | |||
28 | #include "au0828.h" | ||
29 | |||
30 | #include <media/v4l2-common.h> | ||
31 | |||
32 | static unsigned int i2c_debug; | ||
33 | module_param(i2c_debug, int, 0644); | ||
34 | MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); | ||
35 | |||
36 | static unsigned int i2c_scan = 0; | ||
37 | module_param(i2c_scan, int, 0444); | ||
38 | MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); | ||
39 | |||
40 | #define dprintk(level, fmt, arg...)\ | ||
41 | do { if (i2c_debug >= level)\ | ||
42 | printk(KERN_DEBUG "%s/0: " fmt, DRIVER_NAME, ## arg);\ | ||
43 | } while (0) | ||
44 | |||
45 | #define I2C_WAIT_DELAY 512 | ||
46 | #define I2C_WAIT_RETRY 64 | ||
47 | |||
48 | static inline int i2c_slave_did_write_ack(struct i2c_adapter *i2c_adap) | ||
49 | { | ||
50 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
51 | return au0828_read(dev, REG_201) & 0x08 ? 0 : 1; | ||
52 | } | ||
53 | |||
54 | static inline int i2c_slave_did_read_ack(struct i2c_adapter *i2c_adap) | ||
55 | { | ||
56 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
57 | return au0828_read(dev, REG_201) & 0x02 ? 0 : 1; | ||
58 | } | ||
59 | |||
60 | static int i2c_wait_read_ack(struct i2c_adapter *i2c_adap) | ||
61 | { | ||
62 | int count; | ||
63 | |||
64 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
65 | if (!i2c_slave_did_read_ack(i2c_adap)) | ||
66 | break; | ||
67 | udelay(I2C_WAIT_DELAY); | ||
68 | } | ||
69 | |||
70 | if (I2C_WAIT_RETRY == count) | ||
71 | return 0; | ||
72 | |||
73 | return 1; | ||
74 | } | ||
75 | |||
76 | static inline int i2c_is_read_busy(struct i2c_adapter *i2c_adap) | ||
77 | { | ||
78 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
79 | return au0828_read(dev, REG_201) & 0x01 ? 0 : 1; | ||
80 | } | ||
81 | |||
82 | static int i2c_wait_read_done(struct i2c_adapter *i2c_adap) | ||
83 | { | ||
84 | int count; | ||
85 | |||
86 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
87 | if (!i2c_is_read_busy(i2c_adap)) | ||
88 | break; | ||
89 | udelay(I2C_WAIT_DELAY); | ||
90 | } | ||
91 | |||
92 | if (I2C_WAIT_RETRY == count) | ||
93 | return 0; | ||
94 | |||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | static inline int i2c_is_write_done(struct i2c_adapter *i2c_adap) | ||
99 | { | ||
100 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
101 | return au0828_read(dev, REG_201) & 0x04 ? 1 : 0; | ||
102 | } | ||
103 | |||
104 | static int i2c_wait_write_done(struct i2c_adapter *i2c_adap) | ||
105 | { | ||
106 | int count; | ||
107 | |||
108 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
109 | if (i2c_is_write_done(i2c_adap)) | ||
110 | break; | ||
111 | udelay(I2C_WAIT_DELAY); | ||
112 | } | ||
113 | |||
114 | if (I2C_WAIT_RETRY == count) | ||
115 | return 0; | ||
116 | |||
117 | return 1; | ||
118 | } | ||
119 | |||
120 | static inline int i2c_is_busy(struct i2c_adapter *i2c_adap) | ||
121 | { | ||
122 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
123 | return au0828_read(dev, REG_201) & 0x10 ? 1 : 0; | ||
124 | } | ||
125 | |||
126 | static int i2c_wait_done(struct i2c_adapter *i2c_adap) | ||
127 | { | ||
128 | int count; | ||
129 | |||
130 | for (count = 0; count < I2C_WAIT_RETRY; count++) { | ||
131 | if (!i2c_is_busy(i2c_adap)) | ||
132 | break; | ||
133 | udelay(I2C_WAIT_DELAY); | ||
134 | } | ||
135 | |||
136 | if (I2C_WAIT_RETRY == count) | ||
137 | return 0; | ||
138 | |||
139 | return 1; | ||
140 | } | ||
141 | |||
142 | /* FIXME: Implement join handling correctly */ | ||
143 | static int i2c_sendbytes(struct i2c_adapter *i2c_adap, | ||
144 | const struct i2c_msg *msg, int joined_rlen) | ||
145 | { | ||
146 | int i, strobe = 0; | ||
147 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
148 | |||
149 | dprintk(1, "%s()\n", __FUNCTION__); | ||
150 | |||
151 | au0828_write(dev, REG_2FF, 0x01); | ||
152 | au0828_write(dev, REG_202, 0x07); | ||
153 | |||
154 | /* Hardware needs 8 bit addresses */ | ||
155 | au0828_write(dev, REG_203, msg->addr << 1); | ||
156 | |||
157 | if (i2c_debug) | ||
158 | dprintk(1, "SEND: %02x\n", msg->addr); | ||
159 | |||
160 | for (i=0; i < msg->len;) { | ||
161 | |||
162 | if (i2c_debug) | ||
163 | dprintk(1, " %02x\n", msg->buf[i]); | ||
164 | |||
165 | au0828_write(dev, REG_205, msg->buf[i]); | ||
166 | |||
167 | strobe++; | ||
168 | i++; | ||
169 | |||
170 | if ((strobe >= 4) || (i >= msg->len)) { | ||
171 | |||
172 | /* Strobe the byte into the bus */ | ||
173 | if (i < msg->len) | ||
174 | au0828_write(dev, REG_200, 0x41); | ||
175 | else | ||
176 | au0828_write(dev, REG_200, 0x01); | ||
177 | |||
178 | /* Reset strobe trigger */ | ||
179 | strobe = 0; | ||
180 | |||
181 | if (!i2c_wait_write_done(i2c_adap)) | ||
182 | return -EIO; | ||
183 | |||
184 | } | ||
185 | |||
186 | } | ||
187 | if (!i2c_wait_done(i2c_adap)) | ||
188 | return -EIO; | ||
189 | |||
190 | if (i2c_debug) | ||
191 | dprintk(1, "\n"); | ||
192 | |||
193 | return msg->len; | ||
194 | } | ||
195 | |||
196 | /* FIXME: Implement join handling correctly */ | ||
197 | static int i2c_readbytes(struct i2c_adapter *i2c_adap, | ||
198 | const struct i2c_msg *msg, int joined) | ||
199 | { | ||
200 | struct au0828_dev *dev = i2c_adap->algo_data; | ||
201 | int i; | ||
202 | |||
203 | dprintk(1, "%s()\n", __FUNCTION__); | ||
204 | |||
205 | au0828_write(dev, REG_2FF, 0x01); | ||
206 | au0828_write(dev, REG_202, 0x07); | ||
207 | |||
208 | /* Hardware needs 8 bit addresses */ | ||
209 | au0828_write(dev, REG_203, msg->addr << 1); | ||
210 | |||
211 | if (i2c_debug) | ||
212 | dprintk(1, " RECV:\n"); | ||
213 | |||
214 | /* Deal with i2c_scan */ | ||
215 | if (msg->len == 0) { | ||
216 | au0828_write(dev, REG_200, 0x20); | ||
217 | if (i2c_wait_read_ack(i2c_adap)) | ||
218 | return -EIO; | ||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | for (i=0; i < msg->len;) { | ||
223 | |||
224 | i++; | ||
225 | |||
226 | if (i < msg->len) | ||
227 | au0828_write(dev, REG_200, 0x60); | ||
228 | else | ||
229 | au0828_write(dev, REG_200, 0x20); | ||
230 | |||
231 | if (!i2c_wait_read_done(i2c_adap)) | ||
232 | return -EIO; | ||
233 | |||
234 | msg->buf[i-1] = au0828_read(dev, REG_209) & 0xff; | ||
235 | |||
236 | if (i2c_debug) | ||
237 | dprintk(1, " %02x\n", msg->buf[i-1]); | ||
238 | } | ||
239 | if (!i2c_wait_done(i2c_adap)) | ||
240 | return -EIO; | ||
241 | |||
242 | if (i2c_debug) | ||
243 | dprintk(1, "\n"); | ||
244 | |||
245 | return msg->len; | ||
246 | } | ||
247 | |||
248 | static int i2c_xfer(struct i2c_adapter *i2c_adap, | ||
249 | struct i2c_msg *msgs, int num) | ||
250 | { | ||
251 | int i, retval = 0; | ||
252 | |||
253 | dprintk(1, "%s(num = %d)\n", __FUNCTION__, num); | ||
254 | |||
255 | for (i = 0 ; i < num; i++) { | ||
256 | dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n", | ||
257 | __FUNCTION__, num, msgs[i].addr, msgs[i].len); | ||
258 | if (msgs[i].flags & I2C_M_RD) { | ||
259 | /* read */ | ||
260 | retval = i2c_readbytes(i2c_adap, &msgs[i], 0); | ||
261 | } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && | ||
262 | msgs[i].addr == msgs[i + 1].addr) { | ||
263 | /* write then read from same address */ | ||
264 | retval = i2c_sendbytes(i2c_adap, &msgs[i], | ||
265 | msgs[i + 1].len); | ||
266 | if (retval < 0) | ||
267 | goto err; | ||
268 | i++; | ||
269 | retval = i2c_readbytes(i2c_adap, &msgs[i], 1); | ||
270 | } else { | ||
271 | /* write */ | ||
272 | retval = i2c_sendbytes(i2c_adap, &msgs[i], 0); | ||
273 | } | ||
274 | if (retval < 0) | ||
275 | goto err; | ||
276 | } | ||
277 | return num; | ||
278 | |||
279 | err: | ||
280 | return retval; | ||
281 | } | ||
282 | |||
283 | static int attach_inform(struct i2c_client *client) | ||
284 | { | ||
285 | dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", | ||
286 | client->driver->driver.name, client->addr, client->name); | ||
287 | |||
288 | if (!client->driver->command) | ||
289 | return 0; | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | static int detach_inform(struct i2c_client *client) | ||
295 | { | ||
296 | dprintk(1, "i2c detach [client=%s]\n", client->name); | ||
297 | |||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | void au0828_call_i2c_clients(struct au0828_dev *dev, | ||
302 | unsigned int cmd, void *arg) | ||
303 | { | ||
304 | if (dev->i2c_rc != 0) | ||
305 | return; | ||
306 | |||
307 | i2c_clients_command(&dev->i2c_adap, cmd, arg); | ||
308 | } | ||
309 | |||
310 | static u32 au0828_functionality(struct i2c_adapter *adap) | ||
311 | { | ||
312 | return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; | ||
313 | } | ||
314 | |||
315 | static struct i2c_algorithm au0828_i2c_algo_template = { | ||
316 | .master_xfer = i2c_xfer, | ||
317 | .functionality = au0828_functionality, | ||
318 | }; | ||
319 | |||
320 | /* ----------------------------------------------------------------------- */ | ||
321 | |||
322 | static struct i2c_adapter au0828_i2c_adap_template = { | ||
323 | .name = DRIVER_NAME, | ||
324 | .owner = THIS_MODULE, | ||
325 | .id = I2C_HW_B_AU0828, | ||
326 | .algo = &au0828_i2c_algo_template, | ||
327 | .class = I2C_CLASS_TV_ANALOG, | ||
328 | .client_register = attach_inform, | ||
329 | .client_unregister = detach_inform, | ||
330 | }; | ||
331 | |||
332 | static struct i2c_client au0828_i2c_client_template = { | ||
333 | .name = "au0828 internal", | ||
334 | }; | ||
335 | |||
336 | static char *i2c_devs[128] = { | ||
337 | [ 0x8e >> 1 ] = "au8522", | ||
338 | [ 0xa0 >> 1 ] = "eeprom", | ||
339 | [ 0xc2 >> 1 ] = "tuner/xc5000", | ||
340 | }; | ||
341 | |||
342 | static void do_i2c_scan(char *name, struct i2c_client *c) | ||
343 | { | ||
344 | unsigned char buf; | ||
345 | int i, rc; | ||
346 | |||
347 | for (i = 0; i < 128; i++) { | ||
348 | c->addr = i; | ||
349 | rc = i2c_master_recv(c, &buf, 0); | ||
350 | if (rc < 0) | ||
351 | continue; | ||
352 | printk("%s: i2c scan: found device @ 0x%x [%s]\n", | ||
353 | name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); | ||
354 | } | ||
355 | } | ||
356 | |||
357 | /* init + register i2c algo-bit adapter */ | ||
358 | int au0828_i2c_register(struct au0828_dev *dev) | ||
359 | { | ||
360 | dprintk(1, "%s()\n", __FUNCTION__); | ||
361 | |||
362 | memcpy(&dev->i2c_adap, &au0828_i2c_adap_template, | ||
363 | sizeof(dev->i2c_adap)); | ||
364 | memcpy(&dev->i2c_algo, &au0828_i2c_algo_template, | ||
365 | sizeof(dev->i2c_algo)); | ||
366 | memcpy(&dev->i2c_client, &au0828_i2c_client_template, | ||
367 | sizeof(dev->i2c_client)); | ||
368 | |||
369 | dev->i2c_adap.dev.parent = &dev->usbdev->dev; | ||
370 | |||
371 | strlcpy(dev->i2c_adap.name, DRIVER_NAME, | ||
372 | sizeof(dev->i2c_adap.name)); | ||
373 | |||
374 | dev->i2c_algo.data = dev; | ||
375 | dev->i2c_adap.algo_data = dev; | ||
376 | i2c_set_adapdata(&dev->i2c_adap, dev); | ||
377 | i2c_add_adapter(&dev->i2c_adap); | ||
378 | |||
379 | dev->i2c_client.adapter = &dev->i2c_adap; | ||
380 | |||
381 | if (0 == dev->i2c_rc) { | ||
382 | printk("%s: i2c bus registered\n", DRIVER_NAME); | ||
383 | if (i2c_scan) | ||
384 | do_i2c_scan(DRIVER_NAME, &dev->i2c_client); | ||
385 | } else | ||
386 | printk("%s: i2c bus register FAILED\n", DRIVER_NAME); | ||
387 | return dev->i2c_rc; | ||
388 | } | ||
389 | |||
390 | int au0828_i2c_unregister(struct au0828_dev *dev) | ||
391 | { | ||
392 | i2c_del_adapter(&dev->i2c_adap); | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | /* ----------------------------------------------------------------------- */ | ||
397 | |||
398 | /* | ||
399 | * Local variables: | ||
400 | * c-basic-offset: 8 | ||
401 | * End: | ||
402 | */ | ||
diff --git a/drivers/media/video/au0828/au0828-reg.h b/drivers/media/video/au0828/au0828-reg.h new file mode 100644 index 000000000000..c501f6a52af3 --- /dev/null +++ b/drivers/media/video/au0828/au0828-reg.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #define REG_000 0x000 | ||
23 | #define REG_001 0x001 | ||
24 | #define REG_002 0x002 | ||
25 | #define REG_003 0x003 | ||
26 | |||
27 | #define REG_200 0x200 | ||
28 | #define REG_201 0x201 | ||
29 | #define REG_202 0x202 | ||
30 | #define REG_203 0x203 | ||
31 | #define REG_205 0x205 | ||
32 | #define REG_209 0x209 | ||
33 | #define REG_2FF 0x2ff | ||
34 | |||
35 | #define REG_600 0x600 | ||
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h new file mode 100644 index 000000000000..517227667040 --- /dev/null +++ b/drivers/media/video/au0828/au0828.h | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * Driver for the Auvitek AU0828 USB bridge | ||
3 | * | ||
4 | * Copyright (c) 2008 Steven Toth <stoth@hauppauge.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, or | ||
9 | * (at your option) any later version. | ||
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 | * | ||
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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/usb.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/i2c-algo-bit.h> | ||
25 | |||
26 | /* DVB */ | ||
27 | #include "demux.h" | ||
28 | #include "dmxdev.h" | ||
29 | #include "dvb_demux.h" | ||
30 | #include "dvb_frontend.h" | ||
31 | #include "dvb_net.h" | ||
32 | #include "dvbdev.h" | ||
33 | |||
34 | #include "au0828-reg.h" | ||
35 | #include "au0828-cards.h" | ||
36 | |||
37 | #define DRIVER_NAME "au0828" | ||
38 | #define URB_COUNT 16 | ||
39 | //#define URB_BUFSIZE (312 * 188) | ||
40 | #define URB_BUFSIZE (0xe522) | ||
41 | |||
42 | struct au0828_board { | ||
43 | char *name; | ||
44 | }; | ||
45 | |||
46 | struct au0828_dvb { | ||
47 | struct mutex lock; | ||
48 | struct dvb_adapter adapter; | ||
49 | struct dvb_frontend *frontend; | ||
50 | struct dvb_demux demux; | ||
51 | struct dmxdev dmxdev; | ||
52 | struct dmx_frontend fe_hw; | ||
53 | struct dmx_frontend fe_mem; | ||
54 | struct dvb_net net; | ||
55 | int feeding; | ||
56 | }; | ||
57 | |||
58 | struct au0828_dev { | ||
59 | struct mutex mutex; | ||
60 | struct usb_device *usbdev; | ||
61 | int board; | ||
62 | u8 ctrlmsg[64]; | ||
63 | |||
64 | /* I2C */ | ||
65 | struct i2c_adapter i2c_adap; | ||
66 | struct i2c_algo_bit_data i2c_algo; | ||
67 | struct i2c_client i2c_client; | ||
68 | u32 i2c_rc; | ||
69 | |||
70 | /* Digital */ | ||
71 | struct au0828_dvb dvb; | ||
72 | |||
73 | /* USB / URB Related */ | ||
74 | int urb_streaming; | ||
75 | struct urb *urbs[URB_COUNT]; | ||
76 | |||
77 | }; | ||
78 | |||
79 | struct au0828_buff { | ||
80 | struct au0828_dev *dev; | ||
81 | struct urb *purb; | ||
82 | struct list_head buff_list; | ||
83 | }; | ||
84 | |||
85 | /* ----------------------------------------------------------- */ | ||
86 | #define au0828_read(dev,reg) au0828_readreg(dev,reg) | ||
87 | #define au0828_write(dev,reg,value) au0828_writereg(dev,reg,value) | ||
88 | #define au0828_andor(dev,reg,mask,value) \ | ||
89 | au0828_writereg(dev,reg,(au0828_readreg(dev,reg)&~(mask))|((value)&(mask))) | ||
90 | |||
91 | #define au0828_set(dev,reg,bit) au0828_andor(dev,(reg),(bit),(bit)) | ||
92 | #define au0828_clear(dev,reg,bit) au0828_andor(dev,(reg),(bit),0) | ||
93 | |||
94 | /* ----------------------------------------------------------- */ | ||
95 | /* au0828-core.c */ | ||
96 | extern u32 au0828_read(struct au0828_dev *dev, u16 reg); | ||
97 | extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val); | ||
98 | |||
99 | /* ----------------------------------------------------------- */ | ||
100 | /* au0828-cards.c */ | ||
101 | extern struct au0828_board au0828_boards[]; | ||
102 | extern struct usb_device_id au0828_usb_id_table[]; | ||
103 | extern const unsigned int au0828_bcount; | ||
104 | extern void au0828_gpio_setup(struct au0828_dev *dev); | ||
105 | extern int au0828_tuner_callback(void *priv, int command, int arg); | ||
106 | |||
107 | /* ----------------------------------------------------------- */ | ||
108 | /* au0828-i2c.c */ | ||
109 | extern int au0828_i2c_register(struct au0828_dev *dev); | ||
110 | extern int au0828_i2c_unregister(struct au0828_dev *dev); | ||
111 | extern void au0828_call_i2c_clients(struct au0828_dev *dev, | ||
112 | unsigned int cmd, void *arg); | ||
113 | |||
114 | /* ----------------------------------------------------------- */ | ||
115 | /* au0828-dvb.c */ | ||
116 | extern int au0828_dvb_register(struct au0828_dev *dev); | ||
117 | extern void au0828_dvb_unregister(struct au0828_dev *dev); | ||