blob: 5fadee79b325680b7d78692c1ee34d833beed3d6 [file] [log] [blame]
Antti Palosaari4b64bb22012-03-30 08:21:25 -03001/*
2 * Afatech AF9033 demodulator driver
3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
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, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "af9033_priv.h"
23
24struct af9033_state {
25 struct i2c_adapter *i2c;
26 struct dvb_frontend fe;
27 struct af9033_config cfg;
28
29 u32 bandwidth_hz;
30 bool ts_mode_parallel;
31 bool ts_mode_serial;
32};
33
34/* write multiple registers */
35static int af9033_wr_regs(struct af9033_state *state, u32 reg, const u8 *val,
36 int len)
37{
38 int ret;
39 u8 buf[3 + len];
40 struct i2c_msg msg[1] = {
41 {
42 .addr = state->cfg.i2c_addr,
43 .flags = 0,
44 .len = sizeof(buf),
45 .buf = buf,
46 }
47 };
48
49 buf[0] = (reg >> 16) & 0xff;
50 buf[1] = (reg >> 8) & 0xff;
51 buf[2] = (reg >> 0) & 0xff;
52 memcpy(&buf[3], val, len);
53
54 ret = i2c_transfer(state->i2c, msg, 1);
55 if (ret == 1) {
56 ret = 0;
57 } else {
58 printk(KERN_WARNING "%s: i2c wr failed=%d reg=%06x len=%d\n",
59 __func__, ret, reg, len);
60 ret = -EREMOTEIO;
61 }
62
63 return ret;
64}
65
66/* read multiple registers */
67static int af9033_rd_regs(struct af9033_state *state, u32 reg, u8 *val, int len)
68{
69 int ret;
70 u8 buf[3] = { (reg >> 16) & 0xff, (reg >> 8) & 0xff,
71 (reg >> 0) & 0xff };
72 struct i2c_msg msg[2] = {
73 {
74 .addr = state->cfg.i2c_addr,
75 .flags = 0,
76 .len = sizeof(buf),
77 .buf = buf
78 }, {
79 .addr = state->cfg.i2c_addr,
80 .flags = I2C_M_RD,
81 .len = len,
82 .buf = val
83 }
84 };
85
86 ret = i2c_transfer(state->i2c, msg, 2);
87 if (ret == 2) {
88 ret = 0;
89 } else {
90 printk(KERN_WARNING "%s: i2c rd failed=%d reg=%06x len=%d\n",
91 __func__, ret, reg, len);
92 ret = -EREMOTEIO;
93 }
94
95 return ret;
96}
97
98
99/* write single register */
100static int af9033_wr_reg(struct af9033_state *state, u32 reg, u8 val)
101{
102 return af9033_wr_regs(state, reg, &val, 1);
103}
104
105/* read single register */
106static int af9033_rd_reg(struct af9033_state *state, u32 reg, u8 *val)
107{
108 return af9033_rd_regs(state, reg, val, 1);
109}
110
111/* write single register with mask */
112static int af9033_wr_reg_mask(struct af9033_state *state, u32 reg, u8 val,
113 u8 mask)
114{
115 int ret;
116 u8 tmp;
117
118 /* no need for read if whole reg is written */
119 if (mask != 0xff) {
120 ret = af9033_rd_regs(state, reg, &tmp, 1);
121 if (ret)
122 return ret;
123
124 val &= mask;
125 tmp &= ~mask;
126 val |= tmp;
127 }
128
129 return af9033_wr_regs(state, reg, &val, 1);
130}
131
132/* read single register with mask */
133static int af9033_rd_reg_mask(struct af9033_state *state, u32 reg, u8 *val,
134 u8 mask)
135{
136 int ret, i;
137 u8 tmp;
138
139 ret = af9033_rd_regs(state, reg, &tmp, 1);
140 if (ret)
141 return ret;
142
143 tmp &= mask;
144
145 /* find position of the first bit */
146 for (i = 0; i < 8; i++) {
147 if ((mask >> i) & 0x01)
148 break;
149 }
150 *val = tmp >> i;
151
152 return 0;
153}
154
155static u32 af9033_div(u32 a, u32 b, u32 x)
156{
157 u32 r = 0, c = 0, i;
158
159 pr_debug("%s: a=%d b=%d x=%d\n", __func__, a, b, x);
160
161 if (a > b) {
162 c = a / b;
163 a = a - c * b;
164 }
165
166 for (i = 0; i < x; i++) {
167 if (a >= b) {
168 r += 1;
169 a -= b;
170 }
171 a <<= 1;
172 r <<= 1;
173 }
174 r = (c << (u32)x) + r;
175
176 pr_debug("%s: a=%d b=%d x=%d r=%d r=%x\n", __func__, a, b, x, r, r);
177
178 return r;
179}
180
181static void af9033_release(struct dvb_frontend *fe)
182{
183 struct af9033_state *state = fe->demodulator_priv;
184
185 kfree(state);
186}
187
188static int af9033_init(struct dvb_frontend *fe)
189{
190 struct af9033_state *state = fe->demodulator_priv;
191 int ret, i, len;
192 const struct reg_val *init;
193 u8 buf[4];
194 u32 adc_cw, clock_cw;
195 struct reg_val_mask tab[] = {
196 { 0x80fb24, 0x00, 0x08 },
197 { 0x80004c, 0x00, 0xff },
198 { 0x00f641, state->cfg.tuner, 0xff },
199 { 0x80f5ca, 0x01, 0x01 },
200 { 0x80f715, 0x01, 0x01 },
201 { 0x00f41f, 0x04, 0x04 },
202 { 0x00f41a, 0x01, 0x01 },
203 { 0x80f731, 0x00, 0x01 },
204 { 0x00d91e, 0x00, 0x01 },
205 { 0x00d919, 0x00, 0x01 },
206 { 0x80f732, 0x00, 0x01 },
207 { 0x00d91f, 0x00, 0x01 },
208 { 0x00d91a, 0x00, 0x01 },
209 { 0x80f730, 0x00, 0x01 },
210 { 0x80f778, 0x00, 0xff },
211 { 0x80f73c, 0x01, 0x01 },
212 { 0x80f776, 0x00, 0x01 },
213 { 0x00d8fd, 0x01, 0xff },
214 { 0x00d830, 0x01, 0xff },
215 { 0x00d831, 0x00, 0xff },
216 { 0x00d832, 0x00, 0xff },
217 { 0x80f985, state->ts_mode_serial, 0x01 },
218 { 0x80f986, state->ts_mode_parallel, 0x01 },
219 { 0x00d827, 0x00, 0xff },
220 { 0x00d829, 0x00, 0xff },
221 };
222
223 /* program clock control */
224 clock_cw = af9033_div(state->cfg.clock, 1000000ul, 19ul);
225 buf[0] = (clock_cw >> 0) & 0xff;
226 buf[1] = (clock_cw >> 8) & 0xff;
227 buf[2] = (clock_cw >> 16) & 0xff;
228 buf[3] = (clock_cw >> 24) & 0xff;
229
230 pr_debug("%s: clock=%d clock_cw=%08x\n", __func__, state->cfg.clock,
231 clock_cw);
232
233 ret = af9033_wr_regs(state, 0x800025, buf, 4);
234 if (ret < 0)
235 goto err;
236
237 /* program ADC control */
238 for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) {
239 if (clock_adc_lut[i].clock == state->cfg.clock)
240 break;
241 }
242
243 adc_cw = af9033_div(clock_adc_lut[i].adc, 1000000ul, 19ul);
244 buf[0] = (adc_cw >> 0) & 0xff;
245 buf[1] = (adc_cw >> 8) & 0xff;
246 buf[2] = (adc_cw >> 16) & 0xff;
247
248 pr_debug("%s: adc=%d adc_cw=%06x\n", __func__, clock_adc_lut[i].adc,
249 adc_cw);
250
251 ret = af9033_wr_regs(state, 0x80f1cd, buf, 3);
252 if (ret < 0)
253 goto err;
254
255 /* program register table */
256 for (i = 0; i < ARRAY_SIZE(tab); i++) {
257 ret = af9033_wr_reg_mask(state, tab[i].reg, tab[i].val,
258 tab[i].mask);
259 if (ret < 0)
260 goto err;
261 }
262
263 /* settings for TS interface */
264 if (state->cfg.ts_mode == AF9033_TS_MODE_USB) {
265 ret = af9033_wr_reg_mask(state, 0x80f9a5, 0x00, 0x01);
266 if (ret < 0)
267 goto err;
268
269 ret = af9033_wr_reg_mask(state, 0x80f9b5, 0x01, 0x01);
270 if (ret < 0)
271 goto err;
272 } else {
273 ret = af9033_wr_reg_mask(state, 0x80f990, 0x00, 0x01);
274 if (ret < 0)
275 goto err;
276
277 ret = af9033_wr_reg_mask(state, 0x80f9b5, 0x00, 0x01);
278 if (ret < 0)
279 goto err;
280 }
281
282 /* load OFSM settings */
283 pr_debug("%s: load ofsm settings\n", __func__);
284 len = ARRAY_SIZE(ofsm_init);
285 init = ofsm_init;
286 for (i = 0; i < len; i++) {
287 ret = af9033_wr_reg(state, init[i].reg, init[i].val);
288 if (ret < 0)
289 goto err;
290 }
291
292 /* load tuner specific settings */
293 pr_debug("%s: load tuner specific settings\n",
294 __func__);
295 switch (state->cfg.tuner) {
296 case AF9033_TUNER_TUA9001:
297 len = ARRAY_SIZE(tuner_init_tua9001);
298 init = tuner_init_tua9001;
299 break;
Michael Büschffc501f2012-04-02 12:18:36 -0300300 case AF9033_TUNER_FC0011:
301 len = ARRAY_SIZE(tuner_init_fc0011);
302 init = tuner_init_fc0011;
303 break;
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300304 case AF9033_TUNER_MXL5007T:
305 len = ARRAY_SIZE(tuner_init_mxl5007t);
306 init = tuner_init_mxl5007t;
307 break;
Gianluca Gennarice1fe372012-04-02 17:25:14 -0300308 case AF9033_TUNER_TDA18218:
309 len = ARRAY_SIZE(tuner_init_tda18218);
310 init = tuner_init_tda18218;
311 break;
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300312 default:
313 pr_debug("%s: unsupported tuner ID=%d\n", __func__,
314 state->cfg.tuner);
315 ret = -ENODEV;
316 goto err;
317 }
318
319 for (i = 0; i < len; i++) {
320 ret = af9033_wr_reg(state, init[i].reg, init[i].val);
321 if (ret < 0)
322 goto err;
323 }
324
325 state->bandwidth_hz = 0; /* force to program all parameters */
326
327 return 0;
328
329err:
330 pr_debug("%s: failed=%d\n", __func__, ret);
331
332 return ret;
333}
334
335static int af9033_sleep(struct dvb_frontend *fe)
336{
337 struct af9033_state *state = fe->demodulator_priv;
338 int ret, i;
339 u8 tmp;
340
341 ret = af9033_wr_reg(state, 0x80004c, 1);
342 if (ret < 0)
343 goto err;
344
345 ret = af9033_wr_reg(state, 0x800000, 0);
346 if (ret < 0)
347 goto err;
348
349 for (i = 100, tmp = 1; i && tmp; i--) {
350 ret = af9033_rd_reg(state, 0x80004c, &tmp);
351 if (ret < 0)
352 goto err;
353
354 usleep_range(200, 10000);
355 }
356
Antti Palosaari3a871ca2012-04-01 11:14:59 -0300357 pr_debug("%s: loop=%d\n", __func__, i);
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300358
359 if (i == 0) {
360 ret = -ETIMEDOUT;
361 goto err;
362 }
363
364 ret = af9033_wr_reg_mask(state, 0x80fb24, 0x08, 0x08);
365 if (ret < 0)
366 goto err;
367
368 /* prevent current leak (?) */
369 if (state->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
370 /* enable parallel TS */
371 ret = af9033_wr_reg_mask(state, 0x00d917, 0x00, 0x01);
372 if (ret < 0)
373 goto err;
374
375 ret = af9033_wr_reg_mask(state, 0x00d916, 0x01, 0x01);
376 if (ret < 0)
377 goto err;
378 }
379
380 return 0;
381
382err:
383 pr_debug("%s: failed=%d\n", __func__, ret);
384
385 return ret;
386}
387
388static int af9033_get_tune_settings(struct dvb_frontend *fe,
389 struct dvb_frontend_tune_settings *fesettings)
390{
391 fesettings->min_delay_ms = 800;
392 fesettings->step_size = 0;
393 fesettings->max_drift = 0;
394
395 return 0;
396}
397
398static int af9033_set_frontend(struct dvb_frontend *fe)
399{
400 struct af9033_state *state = fe->demodulator_priv;
401 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300402 int ret, i, spec_inv;
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300403 u8 tmp, buf[3], bandwidth_reg_val;
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300404 u32 if_frequency, freq_cw, adc_freq;
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300405
406 pr_debug("%s: frequency=%d bandwidth_hz=%d\n", __func__, c->frequency,
407 c->bandwidth_hz);
408
409 /* check bandwidth */
410 switch (c->bandwidth_hz) {
411 case 6000000:
412 bandwidth_reg_val = 0x00;
413 break;
414 case 7000000:
415 bandwidth_reg_val = 0x01;
416 break;
417 case 8000000:
418 bandwidth_reg_val = 0x02;
419 break;
420 default:
421 pr_debug("%s: invalid bandwidth_hz\n", __func__);
422 ret = -EINVAL;
423 goto err;
424 }
425
426 /* program tuner */
427 if (fe->ops.tuner_ops.set_params)
428 fe->ops.tuner_ops.set_params(fe);
429
430 /* program CFOE coefficients */
431 if (c->bandwidth_hz != state->bandwidth_hz) {
432 for (i = 0; i < ARRAY_SIZE(coeff_lut); i++) {
433 if (coeff_lut[i].clock == state->cfg.clock &&
434 coeff_lut[i].bandwidth_hz == c->bandwidth_hz) {
435 break;
436 }
437 }
438 ret = af9033_wr_regs(state, 0x800001,
439 coeff_lut[i].val, sizeof(coeff_lut[i].val));
440 }
441
442 /* program frequency control */
443 if (c->bandwidth_hz != state->bandwidth_hz) {
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300444 spec_inv = state->cfg.spec_inv ? -1 : 1;
445
446 for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) {
447 if (clock_adc_lut[i].clock == state->cfg.clock)
448 break;
449 }
450 adc_freq = clock_adc_lut[i].adc;
451
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300452 /* get used IF frequency */
453 if (fe->ops.tuner_ops.get_if_frequency)
454 fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency);
455 else
456 if_frequency = 0;
457
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300458 while (if_frequency > (adc_freq / 2))
459 if_frequency -= adc_freq;
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300460
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300461 if (if_frequency >= 0)
462 spec_inv *= -1;
463 else
464 if_frequency *= -1;
465
466 freq_cw = af9033_div(if_frequency, adc_freq, 23ul);
467
468 if (spec_inv == -1)
469 freq_cw *= -1;
470
471 /* get adc multiplies */
472 ret = af9033_rd_reg(state, 0x800045, &tmp);
473 if (ret < 0)
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300474 goto err;
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300475
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300476 if (tmp == 1)
477 freq_cw /= 2;
478
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300479 buf[0] = (freq_cw >> 0) & 0xff;
480 buf[1] = (freq_cw >> 8) & 0xff;
481 buf[2] = (freq_cw >> 16) & 0x7f;
482 ret = af9033_wr_regs(state, 0x800029, buf, 3);
483 if (ret < 0)
484 goto err;
485
486 state->bandwidth_hz = c->bandwidth_hz;
487 }
488
489 ret = af9033_wr_reg_mask(state, 0x80f904, bandwidth_reg_val, 0x03);
490 if (ret < 0)
491 goto err;
492
493 ret = af9033_wr_reg(state, 0x800040, 0x00);
494 if (ret < 0)
495 goto err;
496
497 ret = af9033_wr_reg(state, 0x800047, 0x00);
498 if (ret < 0)
499 goto err;
500
501 ret = af9033_wr_reg_mask(state, 0x80f999, 0x00, 0x01);
502 if (ret < 0)
503 goto err;
504
505 if (c->frequency <= 230000000)
506 tmp = 0x00; /* VHF */
507 else
508 tmp = 0x01; /* UHF */
509
510 ret = af9033_wr_reg(state, 0x80004b, tmp);
511 if (ret < 0)
512 goto err;
513
514 ret = af9033_wr_reg(state, 0x800000, 0x00);
515 if (ret < 0)
516 goto err;
517
518 return 0;
519
520err:
521 pr_debug("%s: failed=%d\n", __func__, ret);
522
523 return ret;
524}
525
526static int af9033_read_status(struct dvb_frontend *fe, fe_status_t *status)
527{
528 struct af9033_state *state = fe->demodulator_priv;
529 int ret;
530 u8 tmp;
531
532 *status = 0;
533
534 /* radio channel status, 0=no result, 1=has signal, 2=no signal */
535 ret = af9033_rd_reg(state, 0x800047, &tmp);
536 if (ret < 0)
537 goto err;
538
539 /* has signal */
540 if (tmp == 0x01)
541 *status |= FE_HAS_SIGNAL;
542
543 if (tmp != 0x02) {
544 /* TPS lock */
545 ret = af9033_rd_reg_mask(state, 0x80f5a9, &tmp, 0x01);
546 if (ret < 0)
547 goto err;
548
549 if (tmp)
550 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
551 FE_HAS_VITERBI;
552
553 /* full lock */
554 ret = af9033_rd_reg_mask(state, 0x80f999, &tmp, 0x01);
555 if (ret < 0)
556 goto err;
557
558 if (tmp)
559 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
560 FE_HAS_VITERBI | FE_HAS_SYNC |
561 FE_HAS_LOCK;
562 }
563
564 return 0;
565
566err:
567 pr_debug("%s: failed=%d\n", __func__, ret);
568
569 return ret;
570}
571
572static int af9033_read_snr(struct dvb_frontend *fe, u16 *snr)
573{
Antti Palosaarie898ef62012-04-01 12:50:02 -0300574 struct af9033_state *state = fe->demodulator_priv;
575 int ret, i, len;
576 u8 buf[3], tmp;
577 u32 snr_val;
578 const struct val_snr *uninitialized_var(snr_lut);
579
580 /* read value */
581 ret = af9033_rd_regs(state, 0x80002c, buf, 3);
582 if (ret < 0)
583 goto err;
584
585 snr_val = (buf[2] << 16) | (buf[1] << 8) | buf[0];
586
587 /* read current modulation */
588 ret = af9033_rd_reg(state, 0x80f903, &tmp);
589 if (ret < 0)
590 goto err;
591
592 switch ((tmp >> 0) & 3) {
593 case 0:
594 len = ARRAY_SIZE(qpsk_snr_lut);
595 snr_lut = qpsk_snr_lut;
596 break;
597 case 1:
598 len = ARRAY_SIZE(qam16_snr_lut);
599 snr_lut = qam16_snr_lut;
600 break;
601 case 2:
602 len = ARRAY_SIZE(qam64_snr_lut);
603 snr_lut = qam64_snr_lut;
604 break;
605 default:
606 goto err;
607 }
608
609 for (i = 0; i < len; i++) {
610 tmp = snr_lut[i].snr;
611
612 if (snr_val < snr_lut[i].val)
613 break;
614 }
615
616 *snr = tmp * 10; /* dB/10 */
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300617
618 return 0;
Antti Palosaarie898ef62012-04-01 12:50:02 -0300619
620err:
621 pr_debug("%s: failed=%d\n", __func__, ret);
622
623 return ret;
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300624}
625
626static int af9033_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
627{
628 struct af9033_state *state = fe->demodulator_priv;
629 int ret;
630 u8 strength2;
631
632 /* read signal strength of 0-100 scale */
633 ret = af9033_rd_reg(state, 0x800048, &strength2);
634 if (ret < 0)
635 goto err;
636
637 /* scale value to 0x0000-0xffff */
638 *strength = strength2 * 0xffff / 100;
639
640 return 0;
641
642err:
643 pr_debug("%s: failed=%d\n", __func__, ret);
644
645 return ret;
646}
647
648static int af9033_read_ber(struct dvb_frontend *fe, u32 *ber)
649{
650 *ber = 0;
651
652 return 0;
653}
654
655static int af9033_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
656{
657 *ucblocks = 0;
658
659 return 0;
660}
661
662static int af9033_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
663{
664 struct af9033_state *state = fe->demodulator_priv;
665 int ret;
666
667 pr_debug("%s: enable=%d\n", __func__, enable);
668
669 ret = af9033_wr_reg_mask(state, 0x00fa04, enable, 0x01);
670 if (ret < 0)
671 goto err;
672
673 return 0;
674
675err:
676 pr_debug("%s: failed=%d\n", __func__, ret);
677
678 return ret;
679}
680
681static struct dvb_frontend_ops af9033_ops;
682
683struct dvb_frontend *af9033_attach(const struct af9033_config *config,
684 struct i2c_adapter *i2c)
685{
686 int ret;
687 struct af9033_state *state;
688 u8 buf[8];
689
690 pr_debug("%s:\n", __func__);
691
692 /* allocate memory for the internal state */
693 state = kzalloc(sizeof(struct af9033_state), GFP_KERNEL);
694 if (state == NULL)
695 goto err;
696
697 /* setup the state */
698 state->i2c = i2c;
699 memcpy(&state->cfg, config, sizeof(struct af9033_config));
700
Antti Palosaari8e8a5ac2012-04-01 14:13:36 -0300701 if (state->cfg.clock != 12000000) {
702 printk(KERN_INFO "af9033: unsupported clock=%d, only " \
703 "12000000 Hz is supported currently\n",
704 state->cfg.clock);
705 goto err;
706 }
707
Antti Palosaari4b64bb22012-03-30 08:21:25 -0300708 /* firmware version */
709 ret = af9033_rd_regs(state, 0x0083e9, &buf[0], 4);
710 if (ret < 0)
711 goto err;
712
713 ret = af9033_rd_regs(state, 0x804191, &buf[4], 4);
714 if (ret < 0)
715 goto err;
716
717 printk(KERN_INFO "af9033: firmware version: LINK=%d.%d.%d.%d " \
718 "OFDM=%d.%d.%d.%d\n", buf[0], buf[1], buf[2], buf[3],
719 buf[4], buf[5], buf[6], buf[7]);
720
721 /* configure internal TS mode */
722 switch (state->cfg.ts_mode) {
723 case AF9033_TS_MODE_PARALLEL:
724 state->ts_mode_parallel = true;
725 break;
726 case AF9033_TS_MODE_SERIAL:
727 state->ts_mode_serial = true;
728 break;
729 case AF9033_TS_MODE_USB:
730 /* usb mode for AF9035 */
731 default:
732 break;
733 }
734
735 /* create dvb_frontend */
736 memcpy(&state->fe.ops, &af9033_ops, sizeof(struct dvb_frontend_ops));
737 state->fe.demodulator_priv = state;
738
739 return &state->fe;
740
741err:
742 kfree(state);
743 return NULL;
744}
745EXPORT_SYMBOL(af9033_attach);
746
747static struct dvb_frontend_ops af9033_ops = {
748 .delsys = { SYS_DVBT },
749 .info = {
750 .name = "Afatech AF9033 (DVB-T)",
751 .frequency_min = 174000000,
752 .frequency_max = 862000000,
753 .frequency_stepsize = 250000,
754 .frequency_tolerance = 0,
755 .caps = FE_CAN_FEC_1_2 |
756 FE_CAN_FEC_2_3 |
757 FE_CAN_FEC_3_4 |
758 FE_CAN_FEC_5_6 |
759 FE_CAN_FEC_7_8 |
760 FE_CAN_FEC_AUTO |
761 FE_CAN_QPSK |
762 FE_CAN_QAM_16 |
763 FE_CAN_QAM_64 |
764 FE_CAN_QAM_AUTO |
765 FE_CAN_TRANSMISSION_MODE_AUTO |
766 FE_CAN_GUARD_INTERVAL_AUTO |
767 FE_CAN_HIERARCHY_AUTO |
768 FE_CAN_RECOVER |
769 FE_CAN_MUTE_TS
770 },
771
772 .release = af9033_release,
773
774 .init = af9033_init,
775 .sleep = af9033_sleep,
776
777 .get_tune_settings = af9033_get_tune_settings,
778 .set_frontend = af9033_set_frontend,
779
780 .read_status = af9033_read_status,
781 .read_snr = af9033_read_snr,
782 .read_signal_strength = af9033_read_signal_strength,
783 .read_ber = af9033_read_ber,
784 .read_ucblocks = af9033_read_ucblocks,
785
786 .i2c_gate_ctrl = af9033_i2c_gate_ctrl,
787};
788
789MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
790MODULE_DESCRIPTION("Afatech AF9033 DVB-T demodulator driver");
791MODULE_LICENSE("GPL");