blob: 5861f346db49b7833601fb725e266e572bb0ad6f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Frontend driver for mobile DVB-T demodulator DiBcom 3000M-B
3 * DiBcom (http://www.dibcom.fr/)
4 *
Patrick Boettcher99e44da2016-01-24 12:56:58 -02005 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@posteo.de)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * based on GPL code from DibCom, which has
8 *
Patrick Boettcher99e44da2016-01-24 12:56:58 -02009 * Copyright (C) 2004 Amaury Demol for DiBcom
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, version 2.
14 *
15 * Acknowledgements
16 *
Patrick Boettcher99e44da2016-01-24 12:56:58 -020017 * Amaury Demol from DiBcom for providing specs and driver
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * sources, on which this driver (and the dvb-dibusb) are based.
19 *
Mauro Carvalho Chehab670d7adb2018-05-08 18:29:30 -030020 * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 */
23
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -030024#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/init.h>
29#include <linux/delay.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080030#include <linux/string.h>
31#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -050033#include <media/dvb_frontend.h>
Patrick Boettcher74340b02006-07-04 13:47:16 -030034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "dib3000.h"
Patrick Boettcher74340b02006-07-04 13:47:16 -030036#include "dib3000mb_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38/* Version information */
39#define DRIVER_VERSION "0.1"
40#define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
Patrick Boettcher99e44da2016-01-24 12:56:58 -020041#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@posteo.de"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static int debug;
44module_param(debug, int, 0644);
45MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
Christoph Egger9059cd42010-01-15 08:49:41 -030046
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -030047#define deb_info(args...) dprintk(0x01, args)
48#define deb_i2c(args...) dprintk(0x02, args)
49#define deb_srch(args...) dprintk(0x04, args)
50#define deb_info(args...) dprintk(0x01, args)
51#define deb_xfer(args...) dprintk(0x02, args)
52#define deb_setf(args...) dprintk(0x04, args)
53#define deb_getf(args...) dprintk(0x08, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Patrick Boettcher74340b02006-07-04 13:47:16 -030055static int dib3000_read_reg(struct dib3000_state *state, u16 reg)
56{
57 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
58 u8 rb[2];
59 struct i2c_msg msg[] = {
60 { .addr = state->config.demod_address, .flags = 0, .buf = wb, .len = 2 },
61 { .addr = state->config.demod_address, .flags = I2C_M_RD, .buf = rb, .len = 2 },
62 };
63
64 if (i2c_transfer(state->i2c, msg, 2) != 2)
65 deb_i2c("i2c read error\n");
66
67 deb_i2c("reading i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,
68 (rb[0] << 8) | rb[1],(rb[0] << 8) | rb[1]);
69
70 return (rb[0] << 8) | rb[1];
71}
72
73static int dib3000_write_reg(struct dib3000_state *state, u16 reg, u16 val)
74{
75 u8 b[] = {
76 (reg >> 8) & 0xff, reg & 0xff,
77 (val >> 8) & 0xff, val & 0xff,
78 };
79 struct i2c_msg msg[] = {
80 { .addr = state->config.demod_address, .flags = 0, .buf = b, .len = 4 }
81 };
82 deb_i2c("writing i2c bus (reg: %5d 0x%04x, val: %5d 0x%04x)\n",reg,reg,val,val);
83
84 return i2c_transfer(state->i2c,msg, 1) != 1 ? -EREMOTEIO : 0;
85}
86
87static int dib3000_search_status(u16 irq,u16 lock)
88{
89 if (irq & 0x02) {
90 if (lock & 0x01) {
91 deb_srch("auto search succeeded\n");
92 return 1; // auto search succeeded
93 } else {
94 deb_srch("auto search not successful\n");
95 return 0; // auto search failed
96 }
97 } else if (irq & 0x01) {
98 deb_srch("auto search failed\n");
99 return 0; // auto search failed
100 }
101 return -1; // try again
102}
103
104/* for auto search */
105static u16 dib3000_seq[2][2][2] = /* fft,gua, inv */
106 { /* fft */
107 { /* gua */
108 { 0, 1 }, /* 0 0 { 0,1 } */
109 { 3, 9 }, /* 0 1 { 0,1 } */
110 },
111 {
112 { 2, 5 }, /* 1 0 { 0,1 } */
113 { 6, 11 }, /* 1 1 { 0,1 } */
114 }
115 };
116
Mauro Carvalho Chehab7e3e68b2016-02-04 12:58:30 -0200117static int dib3000mb_get_frontend(struct dvb_frontend* fe,
118 struct dtv_frontend_properties *c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300120static int dib3000mb_set_frontend(struct dvb_frontend *fe, int tuner)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700122 struct dib3000_state* state = fe->demodulator_priv;
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300123 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Mauro Carvalho Chehab0df289a2015-06-07 14:53:52 -0300124 enum fe_code_rate fe_cr = FEC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 int search_state, seq;
126
Patrick Boettcherdea74862006-05-14 05:01:31 -0300127 if (tuner && fe->ops.tuner_ops.set_params) {
Mauro Carvalho Chehab14d24d12011-12-24 12:24:33 -0300128 fe->ops.tuner_ops.set_params(fe);
Patrick Boettcherdea74862006-05-14 05:01:31 -0300129 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300131 switch (c->bandwidth_hz) {
132 case 8000000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[2]);
134 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_8mhz);
135 break;
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300136 case 7000000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[1]);
138 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_7mhz);
139 break;
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300140 case 6000000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[0]);
142 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_6mhz);
143 break;
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300144 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return -EOPNOTSUPP;
146 default:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300147 pr_err("unknown bandwidth value.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return -EINVAL;
149 }
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300150 deb_setf("bandwidth: %d MHZ\n", c->bandwidth_hz / 1000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152 wr(DIB3000MB_REG_LOCK1_MASK, DIB3000MB_LOCK1_SEARCH_4);
153
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300154 switch (c->transmission_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 case TRANSMISSION_MODE_2K:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300156 deb_setf("transmission mode: 2k\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 wr(DIB3000MB_REG_FFT, DIB3000_TRANSMISSION_MODE_2K);
158 break;
159 case TRANSMISSION_MODE_8K:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300160 deb_setf("transmission mode: 8k\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 wr(DIB3000MB_REG_FFT, DIB3000_TRANSMISSION_MODE_8K);
162 break;
163 case TRANSMISSION_MODE_AUTO:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300164 deb_setf("transmission mode: auto\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
166 default:
167 return -EINVAL;
168 }
169
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300170 switch (c->guard_interval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 case GUARD_INTERVAL_1_32:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300172 deb_setf("guard 1_32\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_32);
174 break;
175 case GUARD_INTERVAL_1_16:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300176 deb_setf("guard 1_16\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_16);
178 break;
179 case GUARD_INTERVAL_1_8:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300180 deb_setf("guard 1_8\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_8);
182 break;
183 case GUARD_INTERVAL_1_4:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300184 deb_setf("guard 1_4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 wr(DIB3000MB_REG_GUARD_TIME, DIB3000_GUARD_TIME_1_4);
186 break;
187 case GUARD_INTERVAL_AUTO:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300188 deb_setf("guard auto\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 break;
190 default:
191 return -EINVAL;
192 }
193
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300194 switch (c->inversion) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 case INVERSION_OFF:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300196 deb_setf("inversion off\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 wr(DIB3000MB_REG_DDS_INV, DIB3000_DDS_INVERSION_OFF);
198 break;
199 case INVERSION_AUTO:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300200 deb_setf("inversion auto\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 break;
202 case INVERSION_ON:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300203 deb_setf("inversion on\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 wr(DIB3000MB_REG_DDS_INV, DIB3000_DDS_INVERSION_ON);
205 break;
206 default:
207 return -EINVAL;
208 }
209
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300210 switch (c->modulation) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 case QPSK:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300212 deb_setf("modulation: qpsk\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 wr(DIB3000MB_REG_QAM, DIB3000_CONSTELLATION_QPSK);
214 break;
215 case QAM_16:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300216 deb_setf("modulation: qam16\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 wr(DIB3000MB_REG_QAM, DIB3000_CONSTELLATION_16QAM);
218 break;
219 case QAM_64:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300220 deb_setf("modulation: qam64\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 wr(DIB3000MB_REG_QAM, DIB3000_CONSTELLATION_64QAM);
222 break;
223 case QAM_AUTO:
224 break;
225 default:
226 return -EINVAL;
227 }
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300228 switch (c->hierarchy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 case HIERARCHY_NONE:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300230 deb_setf("hierarchy: none\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* fall through */
232 case HIERARCHY_1:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300233 deb_setf("hierarchy: alpha=1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 wr(DIB3000MB_REG_VIT_ALPHA, DIB3000_ALPHA_1);
235 break;
236 case HIERARCHY_2:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300237 deb_setf("hierarchy: alpha=2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 wr(DIB3000MB_REG_VIT_ALPHA, DIB3000_ALPHA_2);
239 break;
240 case HIERARCHY_4:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300241 deb_setf("hierarchy: alpha=4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 wr(DIB3000MB_REG_VIT_ALPHA, DIB3000_ALPHA_4);
243 break;
244 case HIERARCHY_AUTO:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300245 deb_setf("hierarchy: alpha=auto\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 break;
247 default:
248 return -EINVAL;
249 }
250
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300251 if (c->hierarchy == HIERARCHY_NONE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 wr(DIB3000MB_REG_VIT_HRCH, DIB3000_HRCH_OFF);
253 wr(DIB3000MB_REG_VIT_HP, DIB3000_SELECT_HP);
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300254 fe_cr = c->code_rate_HP;
255 } else if (c->hierarchy != HIERARCHY_AUTO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 wr(DIB3000MB_REG_VIT_HRCH, DIB3000_HRCH_ON);
257 wr(DIB3000MB_REG_VIT_HP, DIB3000_SELECT_LP);
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300258 fe_cr = c->code_rate_LP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 switch (fe_cr) {
261 case FEC_1_2:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300262 deb_setf("fec: 1_2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_1_2);
264 break;
265 case FEC_2_3:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300266 deb_setf("fec: 2_3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_2_3);
268 break;
269 case FEC_3_4:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300270 deb_setf("fec: 3_4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_3_4);
272 break;
273 case FEC_5_6:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300274 deb_setf("fec: 5_6\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_5_6);
276 break;
277 case FEC_7_8:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300278 deb_setf("fec: 7_8\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 wr(DIB3000MB_REG_VIT_CODE_RATE, DIB3000_FEC_7_8);
280 break;
281 case FEC_NONE:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300282 deb_setf("fec: none\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 break;
284 case FEC_AUTO:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300285 deb_setf("fec: auto\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 break;
287 default:
288 return -EINVAL;
289 }
290
291 seq = dib3000_seq
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300292 [c->transmission_mode == TRANSMISSION_MODE_AUTO]
293 [c->guard_interval == GUARD_INTERVAL_AUTO]
294 [c->inversion == INVERSION_AUTO];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 deb_setf("seq? %d\n", seq);
297
298 wr(DIB3000MB_REG_SEQ, seq);
299
300 wr(DIB3000MB_REG_ISI, seq ? DIB3000MB_ISI_INHIBIT : DIB3000MB_ISI_ACTIVATE);
301
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300302 if (c->transmission_mode == TRANSMISSION_MODE_2K) {
303 if (c->guard_interval == GUARD_INTERVAL_1_8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 wr(DIB3000MB_REG_SYNC_IMPROVEMENT, DIB3000MB_SYNC_IMPROVE_2K_1_8);
305 } else {
306 wr(DIB3000MB_REG_SYNC_IMPROVEMENT, DIB3000MB_SYNC_IMPROVE_DEFAULT);
307 }
308
309 wr(DIB3000MB_REG_UNK_121, DIB3000MB_UNK_121_2K);
310 } else {
311 wr(DIB3000MB_REG_UNK_121, DIB3000MB_UNK_121_DEFAULT);
312 }
313
314 wr(DIB3000MB_REG_MOBILE_ALGO, DIB3000MB_MOBILE_ALGO_OFF);
315 wr(DIB3000MB_REG_MOBILE_MODE_QAM, DIB3000MB_MOBILE_MODE_QAM_OFF);
316 wr(DIB3000MB_REG_MOBILE_MODE, DIB3000MB_MOBILE_MODE_OFF);
317
318 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_high);
319
320 wr(DIB3000MB_REG_ISI, DIB3000MB_ISI_ACTIVATE);
321
322 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_AGC + DIB3000MB_RESTART_CTRL);
323 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_OFF);
324
325 /* wait for AGC lock */
326 msleep(70);
327
328 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_low);
329
330 /* something has to be auto searched */
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300331 if (c->modulation == QAM_AUTO ||
332 c->hierarchy == HIERARCHY_AUTO ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 fe_cr == FEC_AUTO ||
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300334 c->inversion == INVERSION_AUTO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 int as_count=0;
336
337 deb_setf("autosearch enabled.\n");
338
339 wr(DIB3000MB_REG_ISI, DIB3000MB_ISI_INHIBIT);
340
341 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_AUTO_SEARCH);
342 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_OFF);
343
344 while ((search_state =
345 dib3000_search_status(
346 rd(DIB3000MB_REG_AS_IRQ_PENDING),
347 rd(DIB3000MB_REG_LOCK2_VALUE))) < 0 && as_count++ < 100)
348 msleep(1);
349
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300350 deb_setf("search_state after autosearch %d after %d checks\n",
351 search_state, as_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 if (search_state == 1) {
Mauro Carvalho Chehab7e3e68b2016-02-04 12:58:30 -0200354 if (dib3000mb_get_frontend(fe, c) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 deb_setf("reading tuning data from frontend succeeded.\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300356 return dib3000mb_set_frontend(fe, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358 }
359
360 } else {
361 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_CTRL);
362 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_OFF);
363 }
364
365 return 0;
366}
367
368static int dib3000mb_fe_init(struct dvb_frontend* fe, int mobile_mode)
369{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700370 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 deb_info("dib3000mb is getting up.\n");
373 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_UP);
374
375 wr(DIB3000MB_REG_RESTART, DIB3000MB_RESTART_AGC);
376
377 wr(DIB3000MB_REG_RESET_DEVICE, DIB3000MB_RESET_DEVICE);
378 wr(DIB3000MB_REG_RESET_DEVICE, DIB3000MB_RESET_DEVICE_RST);
379
380 wr(DIB3000MB_REG_CLOCK, DIB3000MB_CLOCK_DEFAULT);
381
382 wr(DIB3000MB_REG_ELECT_OUT_MODE, DIB3000MB_ELECT_OUT_MODE_ON);
383
384 wr(DIB3000MB_REG_DDS_FREQ_MSB, DIB3000MB_DDS_FREQ_MSB);
385 wr(DIB3000MB_REG_DDS_FREQ_LSB, DIB3000MB_DDS_FREQ_LSB);
386
387 wr_foreach(dib3000mb_reg_timing_freq, dib3000mb_timing_freq[2]);
388
389 wr_foreach(dib3000mb_reg_impulse_noise,
390 dib3000mb_impulse_noise_values[DIB3000MB_IMPNOISE_OFF]);
391
392 wr_foreach(dib3000mb_reg_agc_gain, dib3000mb_default_agc_gain);
393
394 wr(DIB3000MB_REG_PHASE_NOISE, DIB3000MB_PHASE_NOISE_DEFAULT);
395
396 wr_foreach(dib3000mb_reg_phase_noise, dib3000mb_default_noise_phase);
397
398 wr_foreach(dib3000mb_reg_lock_duration, dib3000mb_default_lock_duration);
399
400 wr_foreach(dib3000mb_reg_agc_bandwidth, dib3000mb_agc_bandwidth_low);
401
402 wr(DIB3000MB_REG_LOCK0_MASK, DIB3000MB_LOCK0_DEFAULT);
403 wr(DIB3000MB_REG_LOCK1_MASK, DIB3000MB_LOCK1_SEARCH_4);
404 wr(DIB3000MB_REG_LOCK2_MASK, DIB3000MB_LOCK2_DEFAULT);
405 wr(DIB3000MB_REG_SEQ, dib3000_seq[1][1][1]);
406
407 wr_foreach(dib3000mb_reg_bandwidth, dib3000mb_bandwidth_8mhz);
408
409 wr(DIB3000MB_REG_UNK_68, DIB3000MB_UNK_68);
410 wr(DIB3000MB_REG_UNK_69, DIB3000MB_UNK_69);
411 wr(DIB3000MB_REG_UNK_71, DIB3000MB_UNK_71);
412 wr(DIB3000MB_REG_UNK_77, DIB3000MB_UNK_77);
413 wr(DIB3000MB_REG_UNK_78, DIB3000MB_UNK_78);
414 wr(DIB3000MB_REG_ISI, DIB3000MB_ISI_INHIBIT);
415 wr(DIB3000MB_REG_UNK_92, DIB3000MB_UNK_92);
416 wr(DIB3000MB_REG_UNK_96, DIB3000MB_UNK_96);
417 wr(DIB3000MB_REG_UNK_97, DIB3000MB_UNK_97);
418 wr(DIB3000MB_REG_UNK_106, DIB3000MB_UNK_106);
419 wr(DIB3000MB_REG_UNK_107, DIB3000MB_UNK_107);
420 wr(DIB3000MB_REG_UNK_108, DIB3000MB_UNK_108);
421 wr(DIB3000MB_REG_UNK_122, DIB3000MB_UNK_122);
422 wr(DIB3000MB_REG_MOBILE_MODE_QAM, DIB3000MB_MOBILE_MODE_QAM_OFF);
423 wr(DIB3000MB_REG_BERLEN, DIB3000MB_BERLEN_DEFAULT);
424
425 wr_foreach(dib3000mb_reg_filter_coeffs, dib3000mb_filter_coeffs);
426
427 wr(DIB3000MB_REG_MOBILE_ALGO, DIB3000MB_MOBILE_ALGO_ON);
428 wr(DIB3000MB_REG_MULTI_DEMOD_MSB, DIB3000MB_MULTI_DEMOD_MSB);
429 wr(DIB3000MB_REG_MULTI_DEMOD_LSB, DIB3000MB_MULTI_DEMOD_LSB);
430
431 wr(DIB3000MB_REG_OUTPUT_MODE, DIB3000MB_OUTPUT_MODE_SLAVE);
432
433 wr(DIB3000MB_REG_FIFO_142, DIB3000MB_FIFO_142);
434 wr(DIB3000MB_REG_MPEG2_OUT_MODE, DIB3000MB_MPEG2_OUT_MODE_188);
435 wr(DIB3000MB_REG_PID_PARSE, DIB3000MB_PID_PARSE_ACTIVATE);
436 wr(DIB3000MB_REG_FIFO, DIB3000MB_FIFO_INHIBIT);
437 wr(DIB3000MB_REG_FIFO_146, DIB3000MB_FIFO_146);
438 wr(DIB3000MB_REG_FIFO_147, DIB3000MB_FIFO_147);
439
440 wr(DIB3000MB_REG_DATA_IN_DIVERSITY, DIB3000MB_DATA_DIVERSITY_IN_OFF);
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return 0;
443}
444
Mauro Carvalho Chehab7e3e68b2016-02-04 12:58:30 -0200445static int dib3000mb_get_frontend(struct dvb_frontend* fe,
446 struct dtv_frontend_properties *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700448 struct dib3000_state* state = fe->demodulator_priv;
Mauro Carvalho Chehab0df289a2015-06-07 14:53:52 -0300449 enum fe_code_rate *cr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 u16 tps_val;
451 int inv_test1,inv_test2;
452 u32 dds_val, threshold = 0x800000;
453
454 if (!rd(DIB3000MB_REG_TPS_LOCK))
455 return 0;
456
457 dds_val = ((rd(DIB3000MB_REG_DDS_VALUE_MSB) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_VALUE_LSB);
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300458 deb_getf("DDS_VAL: %x %x %x\n", dds_val, rd(DIB3000MB_REG_DDS_VALUE_MSB), rd(DIB3000MB_REG_DDS_VALUE_LSB));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (dds_val < threshold)
460 inv_test1 = 0;
461 else if (dds_val == threshold)
462 inv_test1 = 1;
463 else
464 inv_test1 = 2;
465
466 dds_val = ((rd(DIB3000MB_REG_DDS_FREQ_MSB) & 0xff) << 16) + rd(DIB3000MB_REG_DDS_FREQ_LSB);
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300467 deb_getf("DDS_FREQ: %x %x %x\n", dds_val, rd(DIB3000MB_REG_DDS_FREQ_MSB), rd(DIB3000MB_REG_DDS_FREQ_LSB));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (dds_val < threshold)
469 inv_test2 = 0;
470 else if (dds_val == threshold)
471 inv_test2 = 1;
472 else
473 inv_test2 = 2;
474
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300475 c->inversion =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 ((inv_test2 == 2) && (inv_test1==1 || inv_test1==0)) ||
477 ((inv_test2 == 0) && (inv_test1==1 || inv_test1==2)) ?
478 INVERSION_ON : INVERSION_OFF;
479
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300480 deb_getf("inversion %d %d, %d\n", inv_test2, inv_test1, c->inversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 switch ((tps_val = rd(DIB3000MB_REG_TPS_QAM))) {
483 case DIB3000_CONSTELLATION_QPSK:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300484 deb_getf("QPSK\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300485 c->modulation = QPSK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
487 case DIB3000_CONSTELLATION_16QAM:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300488 deb_getf("QAM16\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300489 c->modulation = QAM_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491 case DIB3000_CONSTELLATION_64QAM:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300492 deb_getf("QAM64\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300493 c->modulation = QAM_64;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 break;
495 default:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300496 pr_err("Unexpected constellation returned by TPS (%d)\n", tps_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 break;
498 }
499 deb_getf("TPS: %d\n", tps_val);
500
501 if (rd(DIB3000MB_REG_TPS_HRCH)) {
502 deb_getf("HRCH ON\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300503 cr = &c->code_rate_LP;
504 c->code_rate_HP = FEC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 switch ((tps_val = rd(DIB3000MB_REG_TPS_VIT_ALPHA))) {
506 case DIB3000_ALPHA_0:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300507 deb_getf("HIERARCHY_NONE\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300508 c->hierarchy = HIERARCHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 break;
510 case DIB3000_ALPHA_1:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300511 deb_getf("HIERARCHY_1\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300512 c->hierarchy = HIERARCHY_1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514 case DIB3000_ALPHA_2:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300515 deb_getf("HIERARCHY_2\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300516 c->hierarchy = HIERARCHY_2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 break;
518 case DIB3000_ALPHA_4:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300519 deb_getf("HIERARCHY_4\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300520 c->hierarchy = HIERARCHY_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 break;
522 default:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300523 pr_err("Unexpected ALPHA value returned by TPS (%d)\n", tps_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 break;
525 }
526 deb_getf("TPS: %d\n", tps_val);
527
528 tps_val = rd(DIB3000MB_REG_TPS_CODE_RATE_LP);
529 } else {
530 deb_getf("HRCH OFF\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300531 cr = &c->code_rate_HP;
532 c->code_rate_LP = FEC_NONE;
533 c->hierarchy = HIERARCHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 tps_val = rd(DIB3000MB_REG_TPS_CODE_RATE_HP);
536 }
537
538 switch (tps_val) {
539 case DIB3000_FEC_1_2:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300540 deb_getf("FEC_1_2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 *cr = FEC_1_2;
542 break;
543 case DIB3000_FEC_2_3:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300544 deb_getf("FEC_2_3\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 *cr = FEC_2_3;
546 break;
547 case DIB3000_FEC_3_4:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300548 deb_getf("FEC_3_4\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 *cr = FEC_3_4;
550 break;
551 case DIB3000_FEC_5_6:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300552 deb_getf("FEC_5_6\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 *cr = FEC_4_5;
554 break;
555 case DIB3000_FEC_7_8:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300556 deb_getf("FEC_7_8\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 *cr = FEC_7_8;
558 break;
559 default:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300560 pr_err("Unexpected FEC returned by TPS (%d)\n", tps_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 break;
562 }
563 deb_getf("TPS: %d\n",tps_val);
564
565 switch ((tps_val = rd(DIB3000MB_REG_TPS_GUARD_TIME))) {
566 case DIB3000_GUARD_TIME_1_32:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300567 deb_getf("GUARD_INTERVAL_1_32\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300568 c->guard_interval = GUARD_INTERVAL_1_32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 break;
570 case DIB3000_GUARD_TIME_1_16:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300571 deb_getf("GUARD_INTERVAL_1_16\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300572 c->guard_interval = GUARD_INTERVAL_1_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 break;
574 case DIB3000_GUARD_TIME_1_8:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300575 deb_getf("GUARD_INTERVAL_1_8\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300576 c->guard_interval = GUARD_INTERVAL_1_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 break;
578 case DIB3000_GUARD_TIME_1_4:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300579 deb_getf("GUARD_INTERVAL_1_4\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300580 c->guard_interval = GUARD_INTERVAL_1_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 break;
582 default:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300583 pr_err("Unexpected Guard Time returned by TPS (%d)\n", tps_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 break;
585 }
586 deb_getf("TPS: %d\n", tps_val);
587
588 switch ((tps_val = rd(DIB3000MB_REG_TPS_FFT))) {
589 case DIB3000_TRANSMISSION_MODE_2K:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300590 deb_getf("TRANSMISSION_MODE_2K\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300591 c->transmission_mode = TRANSMISSION_MODE_2K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 break;
593 case DIB3000_TRANSMISSION_MODE_8K:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300594 deb_getf("TRANSMISSION_MODE_8K\n");
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300595 c->transmission_mode = TRANSMISSION_MODE_8K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 break;
597 default:
Mauro Carvalho Chehab585e3222016-10-14 08:44:10 -0300598 pr_err("unexpected transmission mode return by TPS (%d)\n", tps_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 break;
600 }
601 deb_getf("TPS: %d\n", tps_val);
602
603 return 0;
604}
605
Mauro Carvalho Chehab0df289a2015-06-07 14:53:52 -0300606static int dib3000mb_read_status(struct dvb_frontend *fe,
607 enum fe_status *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700609 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 *stat = 0;
612
613 if (rd(DIB3000MB_REG_AGC_LOCK))
614 *stat |= FE_HAS_SIGNAL;
615 if (rd(DIB3000MB_REG_CARRIER_LOCK))
616 *stat |= FE_HAS_CARRIER;
617 if (rd(DIB3000MB_REG_VIT_LCK))
618 *stat |= FE_HAS_VITERBI;
619 if (rd(DIB3000MB_REG_TS_SYNC_LOCK))
620 *stat |= (FE_HAS_SYNC | FE_HAS_LOCK);
621
622 deb_getf("actual status is %2x\n",*stat);
623
624 deb_getf("autoval: tps: %d, qam: %d, hrch: %d, alpha: %d, hp: %d, lp: %d, guard: %d, fft: %d cell: %d\n",
625 rd(DIB3000MB_REG_TPS_LOCK),
626 rd(DIB3000MB_REG_TPS_QAM),
627 rd(DIB3000MB_REG_TPS_HRCH),
628 rd(DIB3000MB_REG_TPS_VIT_ALPHA),
629 rd(DIB3000MB_REG_TPS_CODE_RATE_HP),
630 rd(DIB3000MB_REG_TPS_CODE_RATE_LP),
631 rd(DIB3000MB_REG_TPS_GUARD_TIME),
632 rd(DIB3000MB_REG_TPS_FFT),
633 rd(DIB3000MB_REG_TPS_CELL_ID));
634
635 //*stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
636 return 0;
637}
638
639static int dib3000mb_read_ber(struct dvb_frontend* fe, u32 *ber)
640{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700641 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643 *ber = ((rd(DIB3000MB_REG_BER_MSB) << 16) | rd(DIB3000MB_REG_BER_LSB));
644 return 0;
645}
646
647/* see dib3000-watch dvb-apps for exact calcuations of signal_strength and snr */
648static int dib3000mb_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
649{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700650 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 *strength = rd(DIB3000MB_REG_SIGNAL_POWER) * 0xffff / 0x170;
653 return 0;
654}
655
656static int dib3000mb_read_snr(struct dvb_frontend* fe, u16 *snr)
657{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700658 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 short sigpow = rd(DIB3000MB_REG_SIGNAL_POWER);
660 int icipow = ((rd(DIB3000MB_REG_NOISE_POWER_MSB) & 0xff) << 16) |
661 rd(DIB3000MB_REG_NOISE_POWER_LSB);
662 *snr = (sigpow << 8) / ((icipow > 0) ? icipow : 1);
663 return 0;
664}
665
666static int dib3000mb_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
667{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700668 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700670 *unc = rd(DIB3000MB_REG_PACKET_ERROR_RATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 return 0;
672}
673
674static int dib3000mb_sleep(struct dvb_frontend* fe)
675{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700676 struct dib3000_state* state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 deb_info("dib3000mb is going to bed.\n");
678 wr(DIB3000MB_REG_POWER_CONTROL, DIB3000MB_POWER_DOWN);
679 return 0;
680}
681
682static int dib3000mb_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
683{
684 tune->min_delay_ms = 800;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 return 0;
686}
687
688static int dib3000mb_fe_init_nonmobile(struct dvb_frontend* fe)
689{
690 return dib3000mb_fe_init(fe, 0);
691}
692
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300693static int dib3000mb_set_frontend_and_tuner(struct dvb_frontend *fe)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300695 return dib3000mb_set_frontend(fe, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
697
698static void dib3000mb_release(struct dvb_frontend* fe)
699{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700700 struct dib3000_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 kfree(state);
702}
703
704/* pid filter and transfer stuff */
705static int dib3000mb_pid_control(struct dvb_frontend *fe,int index, int pid,int onoff)
706{
707 struct dib3000_state *state = fe->demodulator_priv;
708 pid = (onoff ? pid | DIB3000_ACTIVATE_PID_FILTERING : 0);
709 wr(index+DIB3000MB_REG_FIRST_PID,pid);
710 return 0;
711}
712
713static int dib3000mb_fifo_control(struct dvb_frontend *fe, int onoff)
714{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700715 struct dib3000_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 deb_xfer("%s fifo\n",onoff ? "enabling" : "disabling");
718 if (onoff) {
719 wr(DIB3000MB_REG_FIFO, DIB3000MB_FIFO_ACTIVATE);
720 } else {
721 wr(DIB3000MB_REG_FIFO, DIB3000MB_FIFO_INHIBIT);
722 }
723 return 0;
724}
725
726static int dib3000mb_pid_parse(struct dvb_frontend *fe, int onoff)
727{
728 struct dib3000_state *state = fe->demodulator_priv;
729 deb_xfer("%s pid parsing\n",onoff ? "enabling" : "disabling");
730 wr(DIB3000MB_REG_PID_PARSE,onoff);
731 return 0;
732}
733
734static int dib3000mb_tuner_pass_ctrl(struct dvb_frontend *fe, int onoff, u8 pll_addr)
735{
Johannes Stezenbachb8742702005-05-16 21:54:31 -0700736 struct dib3000_state *state = fe->demodulator_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 if (onoff) {
738 wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_ENABLE(pll_addr));
739 } else {
740 wr(DIB3000MB_REG_TUNER, DIB3000_TUNER_WRITE_DISABLE(pll_addr));
741 }
742 return 0;
743}
744
Max Kellermannbd336e62016-08-09 18:32:21 -0300745static const struct dvb_frontend_ops dib3000mb_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
748 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
749{
750 struct dib3000_state* state = NULL;
751
752 /* allocate memory for the internal state */
Panagiotis Issaris74081872006-01-11 19:40:56 -0200753 state = kzalloc(sizeof(struct dib3000_state), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 if (state == NULL)
755 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 /* setup the state */
758 state->i2c = i2c;
759 memcpy(&state->config,config,sizeof(struct dib3000_config));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /* check for the correct demod */
762 if (rd(DIB3000_REG_MANUFACTOR_ID) != DIB3000_I2C_ID_DIBCOM)
763 goto error;
764
765 if (rd(DIB3000_REG_DEVICE_ID) != DIB3000MB_DEVICE_ID)
766 goto error;
767
768 /* create dvb_frontend */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300769 memcpy(&state->frontend.ops, &dib3000mb_ops, sizeof(struct dvb_frontend_ops));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 state->frontend.demodulator_priv = state;
771
772 /* set the xfer operations */
773 xfer_ops->pid_parse = dib3000mb_pid_parse;
774 xfer_ops->fifo_ctrl = dib3000mb_fifo_control;
775 xfer_ops->pid_ctrl = dib3000mb_pid_control;
776 xfer_ops->tuner_pass_ctrl = dib3000mb_tuner_pass_ctrl;
777
778 return &state->frontend;
779
780error:
781 kfree(state);
782 return NULL;
783}
784
Max Kellermannbd336e62016-08-09 18:32:21 -0300785static const struct dvb_frontend_ops dib3000mb_ops = {
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300786 .delsys = { SYS_DVBT },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .info = {
788 .name = "DiBcom 3000M-B DVB-T",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .frequency_min = 44250000,
790 .frequency_max = 867250000,
791 .frequency_stepsize = 62500,
792 .caps = FE_CAN_INVERSION_AUTO |
793 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
794 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
795 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
796 FE_CAN_TRANSMISSION_MODE_AUTO |
797 FE_CAN_GUARD_INTERVAL_AUTO |
798 FE_CAN_RECOVER |
799 FE_CAN_HIERARCHY_AUTO,
800 },
801
802 .release = dib3000mb_release,
803
804 .init = dib3000mb_fe_init_nonmobile,
805 .sleep = dib3000mb_sleep,
806
Mauro Carvalho Chehabfe084922011-12-22 20:34:47 -0300807 .set_frontend = dib3000mb_set_frontend_and_tuner,
808 .get_frontend = dib3000mb_get_frontend,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 .get_tune_settings = dib3000mb_fe_get_tune_settings,
810
811 .read_status = dib3000mb_read_status,
812 .read_ber = dib3000mb_read_ber,
813 .read_signal_strength = dib3000mb_read_signal_strength,
814 .read_snr = dib3000mb_read_snr,
815 .read_ucblocks = dib3000mb_read_unc_blocks,
816};
817
818MODULE_AUTHOR(DRIVER_AUTHOR);
819MODULE_DESCRIPTION(DRIVER_DESC);
820MODULE_LICENSE("GPL");
821
822EXPORT_SYMBOL(dib3000mb_attach);