aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends/cxd2820r_t2.c
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2011-04-07 15:27:43 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-05-20 08:30:10 -0400
commit27cfc85e3dae187a470f7aa54123689a487970f2 (patch)
treec49b86487a1e507eec82a5babd7cd05af081e814 /drivers/media/dvb/frontends/cxd2820r_t2.c
parentbc022694d7da1c848e395f18eaf856abc9dd0b09 (diff)
[media] Sony CXD2820R DVB-T/T2/C demodulator driver
It is very first DVB-T2 Linux driver! Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/frontends/cxd2820r_t2.c')
-rw-r--r--drivers/media/dvb/frontends/cxd2820r_t2.c421
1 files changed, 421 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/cxd2820r_t2.c b/drivers/media/dvb/frontends/cxd2820r_t2.c
new file mode 100644
index 000000000000..6ec94ea77f15
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r_t2.c
@@ -0,0 +1,421 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22static int cxd2820r_set_frontend_t2(struct dvb_frontend *fe,
23 struct dvb_frontend_parameters *params)
24{
25 struct cxd2820r_priv *priv = fe->demodulator_priv;
26 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
27 int ret, i;
28 u32 if_khz, if_ctl;
29 u64 num;
30 u8 buf[3], bw_param;
31 u8 bw_params1[][5] = {
32 { 0x1c, 0xb3, 0x33, 0x33, 0x33 }, /* 5 MHz */
33 { 0x17, 0xea, 0xaa, 0xaa, 0xaa }, /* 6 MHz */
34 { 0x14, 0x80, 0x00, 0x00, 0x00 }, /* 7 MHz */
35 { 0x11, 0xf0, 0x00, 0x00, 0x00 }, /* 8 MHz */
36 };
37 struct reg_val_mask tab[] = {
38 { 0x00080, 0x02, 0xff },
39 { 0x00081, 0x20, 0xff },
40 { 0x00085, 0x07, 0xff },
41 { 0x00088, 0x01, 0xff },
42 { 0x02069, 0x01, 0xff },
43
44 { 0x0207f, 0x2a, 0xff },
45 { 0x02082, 0x0a, 0xff },
46 { 0x02083, 0x0a, 0xff },
47 { 0x020cb, priv->cfg.if_agc_polarity << 6, 0x40 },
48 { 0x02070, priv->cfg.ts_mode, 0xff },
49 { 0x020b5, priv->cfg.spec_inv << 4, 0x10 },
50 { 0x02567, 0x07, 0x0f },
51 { 0x02569, 0x03, 0x03 },
52 { 0x02595, 0x1a, 0xff },
53 { 0x02596, 0x50, 0xff },
54 { 0x02a8c, 0x00, 0xff },
55 { 0x02a8d, 0x34, 0xff },
56 { 0x02a45, 0x06, 0x07 },
57 { 0x03f10, 0x0d, 0xff },
58 { 0x03f11, 0x02, 0xff },
59 { 0x03f12, 0x01, 0xff },
60 { 0x03f23, 0x2c, 0xff },
61 { 0x03f51, 0x13, 0xff },
62 { 0x03f52, 0x01, 0xff },
63 { 0x03f53, 0x00, 0xff },
64 { 0x027e6, 0x14, 0xff },
65 { 0x02786, 0x02, 0x07 },
66 { 0x02787, 0x40, 0xe0 },
67 { 0x027ef, 0x10, 0x18 },
68 };
69
70 dbg("%s: RF=%d BW=%d", __func__, c->frequency, c->bandwidth_hz);
71
72 /* update GPIOs */
73 ret = cxd2820r_gpio(fe);
74 if (ret)
75 goto error;
76
77 /* program tuner */
78 if (fe->ops.tuner_ops.set_params)
79 fe->ops.tuner_ops.set_params(fe, params);
80
81 if (priv->delivery_system != SYS_DVBT2) {
82 for (i = 0; i < ARRAY_SIZE(tab); i++) {
83 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg,
84 tab[i].val, tab[i].mask);
85 if (ret)
86 goto error;
87 }
88 }
89
90 priv->delivery_system = SYS_DVBT2;
91
92 switch (c->bandwidth_hz) {
93 case 5000000:
94 if_khz = priv->cfg.if_dvbt2_5;
95 i = 0;
96 bw_param = 3;
97 break;
98 case 6000000:
99 if_khz = priv->cfg.if_dvbt2_6;
100 i = 1;
101 bw_param = 2;
102 break;
103 case 7000000:
104 if_khz = priv->cfg.if_dvbt2_7;
105 i = 2;
106 bw_param = 1;
107 break;
108 case 8000000:
109 if_khz = priv->cfg.if_dvbt2_8;
110 i = 3;
111 bw_param = 0;
112 break;
113 default:
114 return -EINVAL;
115 }
116
117 num = if_khz;
118 num *= 0x1000000;
119 if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
120 buf[0] = ((if_ctl >> 16) & 0xff);
121 buf[1] = ((if_ctl >> 8) & 0xff);
122 buf[2] = ((if_ctl >> 0) & 0xff);
123
124 ret = cxd2820r_wr_regs(priv, 0x020b6, buf, 3);
125 if (ret)
126 goto error;
127
128 ret = cxd2820r_wr_regs(priv, 0x0209f, bw_params1[i], 5);
129 if (ret)
130 goto error;
131
132 ret = cxd2820r_wr_reg_mask(priv, 0x020d7, bw_param << 6, 0xc0);
133 if (ret)
134 goto error;
135
136 ret = cxd2820r_wr_reg(priv, 0x000ff, 0x08);
137 if (ret)
138 goto error;
139
140 ret = cxd2820r_wr_reg(priv, 0x000fe, 0x01);
141 if (ret)
142 goto error;
143
144 return ret;
145error:
146 dbg("%s: failed:%d", __func__, ret);
147 return ret;
148
149}
150
151static int cxd2820r_get_frontend_t2(struct dvb_frontend *fe,
152 struct dvb_frontend_parameters *p)
153{
154 struct cxd2820r_priv *priv = fe->demodulator_priv;
155 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
156 int ret;
157 u8 buf[2];
158
159 ret = cxd2820r_rd_regs(priv, 0x0205c, buf, 2);
160 if (ret)
161 goto error;
162
163 switch ((buf[0] >> 0) & 0x07) {
164 case 0:
165 c->transmission_mode = TRANSMISSION_MODE_2K;
166 break;
167 case 1:
168 c->transmission_mode = TRANSMISSION_MODE_8K;
169 break;
170 case 2:
171 c->transmission_mode = TRANSMISSION_MODE_4K;
172 break;
173 case 3:
174 c->transmission_mode = TRANSMISSION_MODE_1K;
175 break;
176 case 4:
177 c->transmission_mode = TRANSMISSION_MODE_16K;
178 break;
179 case 5:
180 c->transmission_mode = TRANSMISSION_MODE_32K;
181 break;
182 }
183
184 switch ((buf[1] >> 4) & 0x07) {
185 case 0:
186 c->guard_interval = GUARD_INTERVAL_1_32;
187 break;
188 case 1:
189 c->guard_interval = GUARD_INTERVAL_1_16;
190 break;
191 case 2:
192 c->guard_interval = GUARD_INTERVAL_1_8;
193 break;
194 case 3:
195 c->guard_interval = GUARD_INTERVAL_1_4;
196 break;
197 case 4:
198 c->guard_interval = GUARD_INTERVAL_1_128;
199 break;
200 case 5:
201 c->guard_interval = GUARD_INTERVAL_19_128;
202 break;
203 case 6:
204 c->guard_interval = GUARD_INTERVAL_19_256;
205 break;
206 }
207
208 ret = cxd2820r_rd_regs(priv, 0x0225b, buf, 2);
209 if (ret)
210 goto error;
211
212 switch ((buf[0] >> 0) & 0x07) {
213 case 0:
214 c->fec_inner = FEC_1_2;
215 break;
216 case 1:
217 c->fec_inner = FEC_3_5;
218 break;
219 case 2:
220 c->fec_inner = FEC_2_3;
221 break;
222 case 3:
223 c->fec_inner = FEC_3_4;
224 break;
225 case 4:
226 c->fec_inner = FEC_4_5;
227 break;
228 case 5:
229 c->fec_inner = FEC_5_6;
230 break;
231 }
232
233 switch ((buf[1] >> 0) & 0x07) {
234 case 0:
235 c->modulation = QPSK;
236 break;
237 case 1:
238 c->modulation = QAM_16;
239 break;
240 case 2:
241 c->modulation = QAM_64;
242 break;
243 case 3:
244 c->modulation = QAM_256;
245 break;
246 }
247
248 ret = cxd2820r_rd_reg(priv, 0x020b5, &buf[0]);
249 if (ret)
250 goto error;
251
252 switch ((buf[0] >> 4) & 0x01) {
253 case 0:
254 c->inversion = INVERSION_OFF;
255 break;
256 case 1:
257 c->inversion = INVERSION_ON;
258 break;
259 }
260
261 return ret;
262error:
263 dbg("%s: failed:%d", __func__, ret);
264 return ret;
265}
266
267static int cxd2820r_read_status_t2(struct dvb_frontend *fe, fe_status_t *status)
268{
269 struct cxd2820r_priv *priv = fe->demodulator_priv;
270 int ret;
271 u8 buf[1];
272 *status = 0;
273
274 ret = cxd2820r_rd_reg(priv, 0x02010 , &buf[0]);
275 if (ret)
276 goto error;
277
278 if ((buf[0] & 0x07) == 6) {
279 if (((buf[0] >> 5) & 0x01) == 1) {
280 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
281 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
282 } else {
283 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
284 FE_HAS_VITERBI | FE_HAS_SYNC;
285 }
286 }
287
288 dbg("%s: lock=%02x", __func__, buf[0]);
289
290 return ret;
291error:
292 dbg("%s: failed:%d", __func__, ret);
293 return ret;
294}
295
296static int cxd2820r_read_ber_t2(struct dvb_frontend *fe, u32 *ber)
297{
298 struct cxd2820r_priv *priv = fe->demodulator_priv;
299 int ret;
300 u8 buf[4];
301 unsigned int errbits;
302 *ber = 0;
303 /* FIXME: correct calculation */
304
305 ret = cxd2820r_rd_regs(priv, 0x02039, buf, sizeof(buf));
306 if (ret)
307 goto error;
308
309 if ((buf[0] >> 4) & 0x01) {
310 errbits = (buf[0] & 0x0f) << 24 | buf[1] << 16 |
311 buf[2] << 8 | buf[3];
312
313 if (errbits)
314 *ber = errbits * 64 / 16588800;
315 }
316
317 return ret;
318error:
319 dbg("%s: failed:%d", __func__, ret);
320 return ret;
321}
322
323static int cxd2820r_read_signal_strength_t2(struct dvb_frontend *fe,
324 u16 *strength)
325{
326 struct cxd2820r_priv *priv = fe->demodulator_priv;
327 int ret;
328 u8 buf[2];
329 u16 tmp;
330
331 ret = cxd2820r_rd_regs(priv, 0x02026, buf, sizeof(buf));
332 if (ret)
333 goto error;
334
335 tmp = (buf[0] & 0x0f) << 8 | buf[1];
336 tmp = ~tmp & 0x0fff;
337
338 /* scale value to 0x0000-0xffff from 0x0000-0x0fff */
339 *strength = tmp * 0xffff / 0x0fff;
340
341 return ret;
342error:
343 dbg("%s: failed:%d", __func__, ret);
344 return ret;
345}
346
347static int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr)
348{
349 struct cxd2820r_priv *priv = fe->demodulator_priv;
350 int ret;
351 u8 buf[2];
352 u16 tmp;
353 /* report SNR in dB * 10 */
354
355 ret = cxd2820r_rd_regs(priv, 0x02028, buf, sizeof(buf));
356 if (ret)
357 goto error;
358
359 tmp = (buf[0] & 0x0f) << 8 | buf[1];
360 #define CXD2820R_LOG10_8_24 15151336 /* log10(8) << 24 */
361 if (tmp)
362 *snr = (intlog10(tmp) - CXD2820R_LOG10_8_24) / ((1 << 24)
363 / 100);
364 else
365 *snr = 0;
366
367 dbg("%s: dBx10=%d val=%04x", __func__, *snr, tmp);
368
369 return ret;
370error:
371 dbg("%s: failed:%d", __func__, ret);
372 return ret;
373}
374
375static int cxd2820r_read_ucblocks_t2(struct dvb_frontend *fe, u32 *ucblocks)
376{
377 *ucblocks = 0;
378 /* no way to read ? */
379 return 0;
380}
381
382static int cxd2820r_sleep_t2(struct dvb_frontend *fe)
383{
384 struct cxd2820r_priv *priv = fe->demodulator_priv;
385 int ret, i;
386 struct reg_val_mask tab[] = {
387 { 0x000ff, 0x1f, 0xff },
388 { 0x00085, 0x00, 0xff },
389 { 0x00088, 0x01, 0xff },
390 { 0x02069, 0x00, 0xff },
391 { 0x00081, 0x00, 0xff },
392 { 0x00080, 0x00, 0xff },
393 };
394
395 dbg("%s", __func__);
396
397 for (i = 0; i < ARRAY_SIZE(tab); i++) {
398 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg, tab[i].val,
399 tab[i].mask);
400 if (ret)
401 goto error;
402 }
403
404 priv->delivery_system = SYS_UNDEFINED;
405
406 return ret;
407error:
408 dbg("%s: failed:%d", __func__, ret);
409 return ret;
410}
411
412static int cxd2820r_get_tune_settings_t2(struct dvb_frontend *fe,
413 struct dvb_frontend_tune_settings *s)
414{
415 s->min_delay_ms = 1500;
416 s->step_size = fe->ops.info.frequency_stepsize * 2;
417 s->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1;
418
419 return 0;
420}
421