10 #include <linux/i2c.h>
11 #include <linux/slab.h>
13 #include <linux/videodev2.h>
38 #define TEA5761_INTREG_IFFLAG 0x10
39 #define TEA5761_INTREG_LEVFLAG 0x8
40 #define TEA5761_INTREG_FRRFLAG 0x2
41 #define TEA5761_INTREG_BLFLAG 0x1
44 #define TEA5761_INTREG_IFMSK 0x10
45 #define TEA5761_INTREG_LEVMSK 0x8
46 #define TEA5761_INTREG_FRMSK 0x2
47 #define TEA5761_INTREG_BLMSK 0x1
52 #define TEA5761_FRQSET_SEARCH_UP 0x80
53 #define TEA5761_FRQSET_SEARCH_MODE 0x40
64 #define TEA5761_TNCTRL_PUPD_0 0x40
65 #define TEA5761_TNCTRL_BLIM 0X20
66 #define TEA5761_TNCTRL_SWPM 0x10
67 #define TEA5761_TNCTRL_IFCTC 0x08
68 #define TEA5761_TNCTRL_AFM 0x04
69 #define TEA5761_TNCTRL_SMUTE 0x02
70 #define TEA5761_TNCTRL_SNC 0x01
74 #define TEA5761_TNCTRL_MU 0x80
75 #define TEA5761_TNCTRL_SSL_1 0x40
76 #define TEA5761_TNCTRL_SSL_0 0x20
77 #define TEA5761_TNCTRL_HLSI 0x10
78 #define TEA5761_TNCTRL_MST 0x08
79 #define TEA5761_TNCTRL_SWP 0x04
80 #define TEA5761_TNCTRL_DTC 0x02
81 #define TEA5761_TNCTRL_AHLSI 0x01
94 #define TEA5761_TUNCHECK_IF_MASK 0x7e
95 #define TEA5761_TUNCHECK_TUNTO 0x01
98 #define TEA5761_TUNCHECK_LEV_MASK 0xf0
99 #define TEA5761_TUNCHECK_LD 0x08
100 #define TEA5761_TUNCHECK_STEREO 0x04
109 #define TEA5767_MANID_VERSION_MASK 0xf0
110 #define TEA5767_MANID_ID_MSB_MASK 0x0f
114 #define TEA5767_MANID_ID_LSB_MASK 0xfe
115 #define TEA5767_MANID_IDAV 0x01
125 #define FREQ_OFFSET 0
126 static void tea5761_status_dump(
unsigned char *
buffer)
128 unsigned int div, frq;
130 div = ((buffer[2] & 0x3f) << 8) | buffer[3];
132 frq = 1000 * (div * 32768 / 1000 +
FREQ_OFFSET + 225) / 4;
134 printk(
KERN_INFO "tea5761: Frequency %d.%03d KHz (divider = 0x%04x)\n",
135 frq / 1000, frq % 1000, div);
144 unsigned int frq =
freq;
145 unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 };
149 tuner_dbg(
"radio freq counter %d\n", frq);
152 tuner_dbg(
"TEA5761 set to standby mode\n");
166 div = (1000 * (frq * 4 / 16 + 700 + 225) ) >> 15;
167 buffer[1] = (div >> 8) & 0x3f;
168 buffer[2] = div & 0xff;
171 tea5761_status_dump(buffer);
173 if (7 != (rc = tuner_i2c_xfer_send(&priv->
i2c_props, buffer, 7)))
174 tuner_warn(
"i2c i/o error: rc == %d (should be 5)\n", rc);
188 return __set_radio_freq(fe, params->
frequency,
198 return __set_radio_freq(fe, priv->
frequency,
false);
201 static int tea5761_read_status(
struct dvb_frontend *fe,
char *buffer)
207 if (16 != (rc = tuner_i2c_xfer_recv(&priv->
i2c_props, buffer, 16))) {
208 tuner_warn(
"i2c i/o error: rc == %d (should be 16)\n", rc);
215 static inline int tea5761_signal(
struct dvb_frontend *fe,
const char *buffer)
221 tuner_dbg(
"Signal strength: %d\n", signal);
226 static inline int tea5761_stereo(
struct dvb_frontend *fe,
const char *buffer)
232 tuner_dbg(
"Radio ST GET = %02x\n", stereo);
239 unsigned char buffer[16];
243 if (0 == tea5761_read_status(fe, buffer)) {
244 if (tea5761_signal(fe, buffer))
246 if (tea5761_stereo(fe, buffer))
253 static int tea5761_get_rf_strength(
struct dvb_frontend *fe,
u16 *strength)
255 unsigned char buffer[16];
259 if (0 == tea5761_read_status(fe, buffer))
260 *strength = tea5761_signal(fe, buffer);
267 unsigned char buffer[16];
271 if (16 != (rc = tuner_i2c_xfer_recv(&i2c, buffer, 16))) {
276 if ((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061)) {
278 " It is not a TEA5761\n",
279 buffer[13], buffer[14], buffer[15]);
283 "Manufacturer ID= 0x%02x\n",
284 buffer[14], buffer[15], buffer[13]);
308 .set_analog_params = set_radio_freq,
309 .sleep = set_radio_sleep,
310 .release = tea5761_release,
311 .get_frequency = tea5761_get_frequency,
312 .get_status = tea5761_get_status,
313 .get_rf_strength = tea5761_get_rf_strength,
334 memcpy(&fe->
ops.tuner_ops, &tea5761_tuner_ops,
337 tuner_info(
"type set to %s\n",
"Philips TEA5761HN FM Radio");