2 * Sony CXD2820R demodulator driver
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
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.
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.
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.
22 #include "cxd2820r_priv.h"
24 int cxd2820r_set_frontend_t2(struct dvb_frontend
*fe
)
26 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
27 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
32 u8 bw_params1
[][5] = {
33 { 0x1c, 0xb3, 0x33, 0x33, 0x33 }, /* 5 MHz */
34 { 0x17, 0xea, 0xaa, 0xaa, 0xaa }, /* 6 MHz */
35 { 0x14, 0x80, 0x00, 0x00, 0x00 }, /* 7 MHz */
36 { 0x11, 0xf0, 0x00, 0x00, 0x00 }, /* 8 MHz */
38 struct reg_val_mask tab
[] = {
39 { 0x00080, 0x02, 0xff },
40 { 0x00081, 0x20, 0xff },
41 { 0x00085, 0x07, 0xff },
42 { 0x00088, 0x01, 0xff },
43 { 0x02069, 0x01, 0xff },
45 { 0x0207f, 0x2a, 0xff },
46 { 0x02082, 0x0a, 0xff },
47 { 0x02083, 0x0a, 0xff },
48 { 0x020cb, priv
->cfg
.if_agc_polarity
<< 6, 0x40 },
49 { 0x02070, priv
->cfg
.ts_mode
, 0xff },
50 { 0x020b5, priv
->cfg
.spec_inv
<< 4, 0x10 },
51 { 0x02567, 0x07, 0x0f },
52 { 0x02569, 0x03, 0x03 },
53 { 0x02595, 0x1a, 0xff },
54 { 0x02596, 0x50, 0xff },
55 { 0x02a8c, 0x00, 0xff },
56 { 0x02a8d, 0x34, 0xff },
57 { 0x02a45, 0x06, 0x07 },
58 { 0x03f10, 0x0d, 0xff },
59 { 0x03f11, 0x02, 0xff },
60 { 0x03f12, 0x01, 0xff },
61 { 0x03f23, 0x2c, 0xff },
62 { 0x03f51, 0x13, 0xff },
63 { 0x03f52, 0x01, 0xff },
64 { 0x03f53, 0x00, 0xff },
65 { 0x027e6, 0x14, 0xff },
66 { 0x02786, 0x02, 0x07 },
67 { 0x02787, 0x40, 0xe0 },
68 { 0x027ef, 0x10, 0x18 },
71 dbg("%s: RF=%d BW=%d", __func__
, c
->frequency
, c
->bandwidth_hz
);
73 switch (c
->bandwidth_hz
) {
95 ret
= cxd2820r_gpio(fe
);
100 if (fe
->ops
.tuner_ops
.set_params
)
101 fe
->ops
.tuner_ops
.set_params(fe
);
103 if (priv
->delivery_system
!= SYS_DVBT2
) {
104 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
105 ret
= cxd2820r_wr_reg_mask(priv
, tab
[i
].reg
,
106 tab
[i
].val
, tab
[i
].mask
);
112 priv
->delivery_system
= SYS_DVBT2
;
114 /* program IF frequency */
115 if (fe
->ops
.tuner_ops
.get_if_frequency
) {
116 ret
= fe
->ops
.tuner_ops
.get_if_frequency(fe
, &if_freq
);
122 dbg("%s: if_freq=%d", __func__
, if_freq
);
124 num
= if_freq
/ 1000; /* Hz => kHz */
126 if_ctl
= cxd2820r_div_u64_round_closest(num
, 41000);
127 buf
[0] = ((if_ctl
>> 16) & 0xff);
128 buf
[1] = ((if_ctl
>> 8) & 0xff);
129 buf
[2] = ((if_ctl
>> 0) & 0xff);
131 ret
= cxd2820r_wr_regs(priv
, 0x020b6, buf
, 3);
135 ret
= cxd2820r_wr_regs(priv
, 0x0209f, bw_params1
[bw_i
], 5);
139 ret
= cxd2820r_wr_reg_mask(priv
, 0x020d7, bw_param
<< 6, 0xc0);
143 ret
= cxd2820r_wr_reg(priv
, 0x000ff, 0x08);
147 ret
= cxd2820r_wr_reg(priv
, 0x000fe, 0x01);
153 dbg("%s: failed:%d", __func__
, ret
);
158 int cxd2820r_get_frontend_t2(struct dvb_frontend
*fe
)
160 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
161 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
165 ret
= cxd2820r_rd_regs(priv
, 0x0205c, buf
, 2);
169 switch ((buf
[0] >> 0) & 0x07) {
171 c
->transmission_mode
= TRANSMISSION_MODE_2K
;
174 c
->transmission_mode
= TRANSMISSION_MODE_8K
;
177 c
->transmission_mode
= TRANSMISSION_MODE_4K
;
180 c
->transmission_mode
= TRANSMISSION_MODE_1K
;
183 c
->transmission_mode
= TRANSMISSION_MODE_16K
;
186 c
->transmission_mode
= TRANSMISSION_MODE_32K
;
190 switch ((buf
[1] >> 4) & 0x07) {
192 c
->guard_interval
= GUARD_INTERVAL_1_32
;
195 c
->guard_interval
= GUARD_INTERVAL_1_16
;
198 c
->guard_interval
= GUARD_INTERVAL_1_8
;
201 c
->guard_interval
= GUARD_INTERVAL_1_4
;
204 c
->guard_interval
= GUARD_INTERVAL_1_128
;
207 c
->guard_interval
= GUARD_INTERVAL_19_128
;
210 c
->guard_interval
= GUARD_INTERVAL_19_256
;
214 ret
= cxd2820r_rd_regs(priv
, 0x0225b, buf
, 2);
218 switch ((buf
[0] >> 0) & 0x07) {
220 c
->fec_inner
= FEC_1_2
;
223 c
->fec_inner
= FEC_3_5
;
226 c
->fec_inner
= FEC_2_3
;
229 c
->fec_inner
= FEC_3_4
;
232 c
->fec_inner
= FEC_4_5
;
235 c
->fec_inner
= FEC_5_6
;
239 switch ((buf
[1] >> 0) & 0x07) {
241 c
->modulation
= QPSK
;
244 c
->modulation
= QAM_16
;
247 c
->modulation
= QAM_64
;
250 c
->modulation
= QAM_256
;
254 ret
= cxd2820r_rd_reg(priv
, 0x020b5, &buf
[0]);
258 switch ((buf
[0] >> 4) & 0x01) {
260 c
->inversion
= INVERSION_OFF
;
263 c
->inversion
= INVERSION_ON
;
269 dbg("%s: failed:%d", __func__
, ret
);
273 int cxd2820r_read_status_t2(struct dvb_frontend
*fe
, fe_status_t
*status
)
275 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
280 ret
= cxd2820r_rd_reg(priv
, 0x02010 , &buf
[0]);
284 if ((buf
[0] & 0x07) == 6) {
285 if (((buf
[0] >> 5) & 0x01) == 1) {
286 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
287 FE_HAS_VITERBI
| FE_HAS_SYNC
| FE_HAS_LOCK
;
289 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
290 FE_HAS_VITERBI
| FE_HAS_SYNC
;
294 dbg("%s: lock=%02x", __func__
, buf
[0]);
298 dbg("%s: failed:%d", __func__
, ret
);
302 int cxd2820r_read_ber_t2(struct dvb_frontend
*fe
, u32
*ber
)
304 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
307 unsigned int errbits
;
309 /* FIXME: correct calculation */
311 ret
= cxd2820r_rd_regs(priv
, 0x02039, buf
, sizeof(buf
));
315 if ((buf
[0] >> 4) & 0x01) {
316 errbits
= (buf
[0] & 0x0f) << 24 | buf
[1] << 16 |
317 buf
[2] << 8 | buf
[3];
320 *ber
= errbits
* 64 / 16588800;
325 dbg("%s: failed:%d", __func__
, ret
);
329 int cxd2820r_read_signal_strength_t2(struct dvb_frontend
*fe
,
332 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
337 ret
= cxd2820r_rd_regs(priv
, 0x02026, buf
, sizeof(buf
));
341 tmp
= (buf
[0] & 0x0f) << 8 | buf
[1];
344 /* scale value to 0x0000-0xffff from 0x0000-0x0fff */
345 *strength
= tmp
* 0xffff / 0x0fff;
349 dbg("%s: failed:%d", __func__
, ret
);
353 int cxd2820r_read_snr_t2(struct dvb_frontend
*fe
, u16
*snr
)
355 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
359 /* report SNR in dB * 10 */
361 ret
= cxd2820r_rd_regs(priv
, 0x02028, buf
, sizeof(buf
));
365 tmp
= (buf
[0] & 0x0f) << 8 | buf
[1];
366 #define CXD2820R_LOG10_8_24 15151336 /* log10(8) << 24 */
368 *snr
= (intlog10(tmp
) - CXD2820R_LOG10_8_24
) / ((1 << 24)
373 dbg("%s: dBx10=%d val=%04x", __func__
, *snr
, tmp
);
377 dbg("%s: failed:%d", __func__
, ret
);
381 int cxd2820r_read_ucblocks_t2(struct dvb_frontend
*fe
, u32
*ucblocks
)
384 /* no way to read ? */
388 int cxd2820r_sleep_t2(struct dvb_frontend
*fe
)
390 struct cxd2820r_priv
*priv
= fe
->demodulator_priv
;
392 struct reg_val_mask tab
[] = {
393 { 0x000ff, 0x1f, 0xff },
394 { 0x00085, 0x00, 0xff },
395 { 0x00088, 0x01, 0xff },
396 { 0x02069, 0x00, 0xff },
397 { 0x00081, 0x00, 0xff },
398 { 0x00080, 0x00, 0xff },
403 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
404 ret
= cxd2820r_wr_reg_mask(priv
, tab
[i
].reg
, tab
[i
].val
,
410 priv
->delivery_system
= SYS_UNDEFINED
;
414 dbg("%s: failed:%d", __func__
, ret
);
418 int cxd2820r_get_tune_settings_t2(struct dvb_frontend
*fe
,
419 struct dvb_frontend_tune_settings
*s
)
421 s
->min_delay_ms
= 1500;
422 s
->step_size
= fe
->ops
.info
.frequency_stepsize
* 2;
423 s
->max_drift
= (fe
->ops
.info
.frequency_stepsize
* 2) + 1;