2 * E3C EC100 demodulator driver
4 * Copyright (C) 2009 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.
18 #include <media/dvb_frontend.h>
22 struct i2c_adapter
*i2c
;
23 struct dvb_frontend frontend
;
24 struct ec100_config config
;
29 /* write single register */
30 static int ec100_write_reg(struct ec100_state
*state
, u8 reg
, u8 val
)
33 u8 buf
[2] = {reg
, val
};
34 struct i2c_msg msg
[1] = {
36 .addr
= state
->config
.demod_address
,
43 ret
= i2c_transfer(state
->i2c
, msg
, 1);
47 dev_warn(&state
->i2c
->dev
, "%s: i2c wr failed=%d reg=%02x\n",
48 KBUILD_MODNAME
, ret
, reg
);
55 /* read single register */
56 static int ec100_read_reg(struct ec100_state
*state
, u8 reg
, u8
*val
)
59 struct i2c_msg msg
[2] = {
61 .addr
= state
->config
.demod_address
,
66 .addr
= state
->config
.demod_address
,
73 ret
= i2c_transfer(state
->i2c
, msg
, 2);
77 dev_warn(&state
->i2c
->dev
, "%s: i2c rd failed=%d reg=%02x\n",
78 KBUILD_MODNAME
, ret
, reg
);
85 static int ec100_set_frontend(struct dvb_frontend
*fe
)
87 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
88 struct ec100_state
*state
= fe
->demodulator_priv
;
92 dev_dbg(&state
->i2c
->dev
, "%s: frequency=%d bandwidth_hz=%d\n",
93 __func__
, c
->frequency
, c
->bandwidth_hz
);
96 if (fe
->ops
.tuner_ops
.set_params
)
97 fe
->ops
.tuner_ops
.set_params(fe
);
99 ret
= ec100_write_reg(state
, 0x04, 0x06);
102 ret
= ec100_write_reg(state
, 0x67, 0x58);
105 ret
= ec100_write_reg(state
, 0x05, 0x18);
109 /* reg/bw | 6 | 7 | 8
110 -------+------+------+------
111 A 0x1b | 0xa1 | 0xe7 | 0x2c
112 A 0x1c | 0x55 | 0x63 | 0x72
113 -------+------+------+------
114 B 0x1b | 0xb7 | 0x00 | 0x49
115 B 0x1c | 0x55 | 0x64 | 0x72 */
117 switch (c
->bandwidth_hz
) {
132 ret
= ec100_write_reg(state
, 0x1b, tmp
);
135 ret
= ec100_write_reg(state
, 0x1c, tmp2
);
139 ret
= ec100_write_reg(state
, 0x0c, 0xbb); /* if freq */
142 ret
= ec100_write_reg(state
, 0x0d, 0x31); /* if freq */
146 ret
= ec100_write_reg(state
, 0x08, 0x24);
150 ret
= ec100_write_reg(state
, 0x00, 0x00); /* go */
153 ret
= ec100_write_reg(state
, 0x00, 0x20); /* go */
159 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
163 static int ec100_get_tune_settings(struct dvb_frontend
*fe
,
164 struct dvb_frontend_tune_settings
*fesettings
)
166 fesettings
->min_delay_ms
= 300;
167 fesettings
->step_size
= 0;
168 fesettings
->max_drift
= 0;
173 static int ec100_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
175 struct ec100_state
*state
= fe
->demodulator_priv
;
180 ret
= ec100_read_reg(state
, 0x42, &tmp
);
185 /* bit7 set - have lock */
186 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
| FE_HAS_VITERBI
|
187 FE_HAS_SYNC
| FE_HAS_LOCK
;
189 ret
= ec100_read_reg(state
, 0x01, &tmp
);
194 /* bit4 set - have signal */
195 *status
|= FE_HAS_SIGNAL
;
197 /* bit0 clear - have ~valid signal */
198 *status
|= FE_HAS_CARRIER
| FE_HAS_VITERBI
;
205 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
209 static int ec100_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
211 struct ec100_state
*state
= fe
->demodulator_priv
;
218 ret
= ec100_read_reg(state
, 0x65, &tmp
);
221 ret
= ec100_read_reg(state
, 0x66, &tmp2
);
225 ber2
= (tmp2
<< 8) | tmp
;
227 /* if counter overflow or clear */
228 if (ber2
< state
->ber
)
231 *ber
= ber2
- state
->ber
;
237 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
241 static int ec100_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
243 struct ec100_state
*state
= fe
->demodulator_priv
;
247 ret
= ec100_read_reg(state
, 0x24, &tmp
);
253 *strength
= ((tmp
<< 8) | tmp
);
257 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
261 static int ec100_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
267 static int ec100_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
273 static void ec100_release(struct dvb_frontend
*fe
)
275 struct ec100_state
*state
= fe
->demodulator_priv
;
279 static const struct dvb_frontend_ops ec100_ops
;
281 struct dvb_frontend
*ec100_attach(const struct ec100_config
*config
,
282 struct i2c_adapter
*i2c
)
285 struct ec100_state
*state
= NULL
;
288 /* allocate memory for the internal state */
289 state
= kzalloc(sizeof(struct ec100_state
), GFP_KERNEL
);
293 /* setup the state */
295 memcpy(&state
->config
, config
, sizeof(struct ec100_config
));
297 /* check if the demod is there */
298 ret
= ec100_read_reg(state
, 0x33, &tmp
);
299 if (ret
|| tmp
!= 0x0b)
302 /* create dvb_frontend */
303 memcpy(&state
->frontend
.ops
, &ec100_ops
,
304 sizeof(struct dvb_frontend_ops
));
305 state
->frontend
.demodulator_priv
= state
;
307 return &state
->frontend
;
312 EXPORT_SYMBOL(ec100_attach
);
314 static const struct dvb_frontend_ops ec100_ops
= {
315 .delsys
= { SYS_DVBT
},
317 .name
= "E3C EC100 DVB-T",
319 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
320 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
321 FE_CAN_QPSK
| FE_CAN_QAM_16
|
322 FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
323 FE_CAN_TRANSMISSION_MODE_AUTO
|
324 FE_CAN_GUARD_INTERVAL_AUTO
|
325 FE_CAN_HIERARCHY_AUTO
|
329 .release
= ec100_release
,
330 .set_frontend
= ec100_set_frontend
,
331 .get_tune_settings
= ec100_get_tune_settings
,
332 .read_status
= ec100_read_status
,
333 .read_ber
= ec100_read_ber
,
334 .read_signal_strength
= ec100_read_signal_strength
,
335 .read_snr
= ec100_read_snr
,
336 .read_ucblocks
= ec100_read_ucblocks
,
339 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
340 MODULE_DESCRIPTION("E3C EC100 DVB-T demodulator driver");
341 MODULE_LICENSE("GPL");