13 #include <linux/i2c.h>
14 #include <linux/slab.h>
16 #include <linux/videodev2.h>
39 #define TEA5767_MUTE 0x80
40 #define TEA5767_SEARCH 0x40
49 #define TEA5767_SEARCH_UP 0x80
52 #define TEA5767_SRCH_HIGH_LVL 0x60
55 #define TEA5767_SRCH_MID_LVL 0x40
58 #define TEA5767_SRCH_LOW_LVL 0x20
61 #define TEA5767_HIGH_LO_INJECT 0x10
64 #define TEA5767_MONO 0x08
67 #define TEA5767_MUTE_RIGHT 0x04
70 #define TEA5767_MUTE_LEFT 0x02
72 #define TEA5767_PORT1_HIGH 0x01
75 #define TEA5767_PORT2_HIGH 0x80
77 #define TEA5767_STDBY 0x40
80 #define TEA5767_JAPAN_BAND 0x20
83 #define TEA5767_XTAL_32768 0x10
86 #define TEA5767_SOFT_MUTE 0x08
89 #define TEA5767_HIGH_CUT_CTRL 0x04
92 #define TEA5767_ST_NOISE_CTL 0x02
95 #define TEA5767_SRCH_IND 0x01
100 #define TEA5767_PLLREF_ENABLE 0x80
103 #define TEA5767_DEEMPH_75 0X40
110 #define TEA5767_READY_FLAG_MASK 0x80
111 #define TEA5767_BAND_LIMIT_MASK 0X40
118 #define TEA5767_STEREO_MASK 0x80
119 #define TEA5767_IF_CNTR_MASK 0x7f
122 #define TEA5767_ADC_LEVEL_MASK 0xf0
125 #define TEA5767_CHIP_ID_MASK 0x0f
129 #define TEA5767_RESERVED_MASK 0xff
136 unsigned int div, frq;
148 div = ((buffer[0] & 0x3f) << 8) | buffer[1];
150 switch (priv->
ctrl.xtal_freq) {
152 frq = (div * 50000 - 700000 - 225000) / 4;
155 frq = (div * 50000 + 700000 + 225000) / 4;
158 frq = (div * 32768 + 700000 + 225000) / 4;
162 frq = (div * 32768 - 700000 - 225000) / 4;
165 buffer[0] = (div >> 8) & 0x3f;
166 buffer[1] = div & 0xff;
168 tuner_info(
"Frequency %d.%03d KHz (divider = 0x%04x)\n",
169 frq / 1000, frq % 1000, div);
197 tuner_dbg(
"radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000);
201 if (priv->
ctrl.port1)
214 if (priv->
ctrl.port2)
217 if (priv->
ctrl.high_cut)
220 if (priv->
ctrl.st_noise)
223 if (priv->
ctrl.soft_mute)
226 if (priv->
ctrl.japan_band)
231 if (priv->
ctrl.deemph_75)
234 if (priv->
ctrl.pllref)
241 switch (priv->
ctrl.xtal_freq) {
243 tuner_dbg(
"radio HIGH LO inject xtal @ 13 MHz\n");
245 div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000;
248 tuner_dbg(
"radio LOW LO inject xtal @ 13 MHz\n");
250 div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000;
253 tuner_dbg(
"radio LOW LO inject xtal @ 32,768 MHz\n");
256 div = ((frq * (4000 / 16) - 700000 - 225000) + 16384) >> 15;
260 tuner_dbg(
"radio HIGH LO inject xtal @ 32,768 MHz\n");
264 div = ((frq * (4000 / 16) + 700000 + 225000) + 16384) >> 15;
267 buffer[0] = (div >> 8) & 0x3f;
268 buffer[1] = div & 0xff;
270 if (5 != (rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 5)))
271 tuner_warn(
"i2c i/o error: rc == %d (should be 5)\n", rc);
274 if (5 != (rc = tuner_i2c_xfer_recv(&priv->
i2c_props, buffer, 5)))
275 tuner_warn(
"i2c i/o error: rc == %d (should be 5)\n", rc);
277 tea5767_status_dump(priv, buffer);
285 static int tea5767_read_status(
struct dvb_frontend *fe,
char *buffer)
291 if (5 != (rc = tuner_i2c_xfer_recv(&priv->
i2c_props, buffer, 5))) {
292 tuner_warn(
"i2c i/o error: rc == %d (should be 5)\n", rc);
299 static inline int tea5767_signal(
struct dvb_frontend *fe,
const char *buffer)
305 tuner_dbg(
"Signal strength: %d\n", signal);
310 static inline int tea5767_stereo(
struct dvb_frontend *fe,
const char *buffer)
316 tuner_dbg(
"Radio ST GET = %02x\n", stereo);
323 unsigned char buffer[5];
327 if (0 == tea5767_read_status(fe, buffer)) {
328 if (tea5767_signal(fe, buffer))
330 if (tea5767_stereo(fe, buffer))
337 static int tea5767_get_rf_strength(
struct dvb_frontend *fe,
u16 *strength)
339 unsigned char buffer[5];
343 if (0 == tea5767_read_status(fe, buffer))
344 *strength = tea5767_signal(fe, buffer);
351 unsigned char buffer[5];
355 div = (87500 * 4 + 700 + 225 + 25) / 50;
356 buffer[0] = (div >> 8) & 0x3f;
357 buffer[1] = div & 0xff;
363 if (5 != (rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 5)))
364 tuner_warn(
"i2c i/o error: rc == %d (should be 5)\n", rc);
372 unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
375 if ((rc = tuner_i2c_xfer_recv(&i2c, buffer, 7))< 5) {
381 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] &&
382 buffer[0] == buffer[3] && buffer[0] == buffer[4]) {
392 if (((buffer[3] & 0x0f) != 0x00) || (buffer[4] != 0x00)) {
417 static int tea5767_set_config (
struct dvb_frontend *fe,
void *priv_cfg)
431 .set_analog_params = set_radio_freq,
432 .set_config = tea5767_set_config,
433 .sleep = tea5767_standby,
434 .release = tea5767_release,
435 .get_frequency = tea5767_get_frequency,
436 .get_status = tea5767_get_status,
437 .get_rf_strength = tea5767_get_rf_strength,
456 priv->
ctrl.port1 = 1;
457 priv->
ctrl.port2 = 1;
458 priv->
ctrl.high_cut = 1;
459 priv->
ctrl.st_noise = 1;
460 priv->
ctrl.japan_band = 1;
462 memcpy(&fe->
ops.tuner_ops, &tea5767_tuner_ops,
465 tuner_info(
"type set to %s\n",
"Philips TEA5767HN FM Radio");