aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2007-04-08 00:09:11 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-07-18 13:23:11 -0400
commit8573a9e6a8ed724b7e3074dc8762d4117ed0b3aa (patch)
treec84aa587103700a3db61f271dfb7c0b99aa37492 /drivers
parent8b4a40809e5330c9da5d20107d693d92d73b31dc (diff)
V4L/DVB (5563a): Add experimental support for tea5761 tuner
This driver were made based on tea5761 specs. Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/Kconfig8
-rw-r--r--drivers/media/video/Makefile4
-rw-r--r--drivers/media/video/tea5761.c239
-rw-r--r--drivers/media/video/tuner-core.c26
-rw-r--r--drivers/media/video/tuner-types.c4
5 files changed, 281 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 4d45a40016de..bb072ab5f09b 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -489,6 +489,14 @@ config TUNER_3036
489 Say Y here to include support for Philips SAB3036 compatible tuners. 489 Say Y here to include support for Philips SAB3036 compatible tuners.
490 If in doubt, say N. 490 If in doubt, say N.
491 491
492config TUNER_TEA5761
493 tristate "TEA 5761 radio tuner (EXPERIMENTAL)"
494 depends on I2C
495 select VIDEO_TUNER
496 help
497 Say Y here to include support for Philips TEA5761 radio tuner.
498 If in doubt, say N.
499
492config VIDEO_VINO 500config VIDEO_VINO
493 tristate "SGI Vino Video For Linux (EXPERIMENTAL)" 501 tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
494 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2 502 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 9c2de501612f..3202e872914e 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -7,6 +7,10 @@ zr36067-objs := zoran_procfs.o zoran_device.o \
7tuner-objs := tuner-core.o tuner-types.o tuner-simple.o \ 7tuner-objs := tuner-core.o tuner-types.o tuner-simple.o \
8 mt20xx.o tda8290.o tea5767.o tda9887.o 8 mt20xx.o tda8290.o tea5767.o tda9887.o
9 9
10ifneq ($(CONFIG_TUNER_TEA5761),n)
11 tuner-objs += tea5761.o
12endif
13
10msp3400-objs := msp3400-driver.o msp3400-kthreads.o 14msp3400-objs := msp3400-driver.o msp3400-kthreads.o
11 15
12obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o 16obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o
diff --git a/drivers/media/video/tea5761.c b/drivers/media/video/tea5761.c
new file mode 100644
index 000000000000..4d2d3ef0860c
--- /dev/null
+++ b/drivers/media/video/tea5761.c
@@ -0,0 +1,239 @@
1/*
2 * For Philips TEA5761 FM Chip
3 * I2C address is allways 0x20 (0x10 at 7-bit mode).
4 *
5 * Copyright (c) 2005-2007 Mauro Carvalho Chehab (mchehab@infradead.org)
6 * This code is placed under the terms of the GNUv2 General Public License
7 *
8 */
9
10#include <linux/i2c.h>
11#include <linux/videodev.h>
12#include <linux/delay.h>
13#include <media/tuner.h>
14#include <media/tuner.h>
15
16#define PREFIX "TEA5761 "
17
18/* from tuner-core.c */
19extern int tuner_debug;
20
21/*****************************************************************************/
22
23/***************************
24 * TEA5761HN I2C registers *
25 ***************************/
26
27/* INTREG - Read: bytes 0 and 1 / Write: byte 0 */
28
29 /* first byte for reading */
30#define TEA5761_INTREG_IFFLAG 0x10
31#define TEA5761_INTREG_LEVFLAG 0x8
32#define TEA5761_INTREG_FRRFLAG 0x2
33#define TEA5761_INTREG_BLFLAG 0x1
34
35 /* second byte for reading / byte for writing */
36#define TEA5761_INTREG_IFMSK 0x10
37#define TEA5761_INTREG_LEVMSK 0x8
38#define TEA5761_INTREG_FRMSK 0x2
39#define TEA5761_INTREG_BLMSK 0x1
40
41/* FRQSET - Read: bytes 2 and 3 / Write: byte 1 and 2 */
42
43 /* First byte */
44#define TEA5761_FRQSET_SEARCH_UP 0x80 /* 1=Station search from botton to up */
45#define TEA5761_FRQSET_SEARCH_MODE 0x40 /* 1=Search mode */
46
47 /* Bits 0-5 for divider MSB */
48
49 /* Second byte */
50 /* Bits 0-7 for divider LSB */
51
52/* TNCTRL - Read: bytes 4 and 5 / Write: Bytes 3 and 4 */
53
54 /* first byte */
55
56#define TEA5761_TNCTRL_PUPD_0 0x40 /* Power UP/Power Down MSB */
57#define TEA5761_TNCTRL_BLIM 0X20 /* 1= Japan Frequencies, 0= European frequencies */
58#define TEA5761_TNCTRL_SWPM 0x10 /* 1= software port is FRRFLAG */
59#define TEA5761_TNCTRL_IFCTC 0x08 /* 1= IF count time 15.02 ms, 0= IF count time 2.02 ms */
60#define TEA5761_TNCTRL_AFM 0x04
61#define TEA5761_TNCTRL_SMUTE 0x02 /* 1= Soft mute */
62#define TEA5761_TNCTRL_SNC 0x01
63
64 /* second byte */
65
66#define TEA5761_TNCTRL_MU 0x80 /* 1=Hard mute */
67#define TEA5761_TNCTRL_SSL_1 0x40
68#define TEA5761_TNCTRL_SSL_0 0x20
69#define TEA5761_TNCTRL_HLSI 0x10
70#define TEA5761_TNCTRL_MST 0x08 /* 1 = mono */
71#define TEA5761_TNCTRL_SWP 0x04
72#define TEA5761_TNCTRL_DTC 0x02 /* 1 = deemphasis 50 us, 0 = deemphasis 75 us */
73#define TEA5761_TNCTRL_AHLSI 0x01
74
75/* FRQCHECK - Read: bytes 6 and 7 */
76 /* First byte */
77
78 /* Bits 0-5 for divider MSB */
79
80 /* Second byte */
81 /* Bits 0-7 for divider LSB */
82
83/* TUNCHECK - Read: bytes 8 and 9 */
84
85 /* First byte */
86#define TEA5761_TUNCHECK_IF_MASK 0x7e /* IF count */
87#define TEA5761_TUNCHECK_TUNTO 0x01
88
89 /* Second byte */
90#define TEA5761_TUNCHECK_LEV_MASK 0xf0 /* Level Count */
91#define TEA5761_TUNCHECK_LD 0x08
92#define TEA5761_TUNCHECK_STEREO 0x04
93
94/* TESTREG - Read: bytes 10 and 11 / Write: bytes 5 and 6 */
95
96 /* All zero = no test mode */
97
98/* MANID - Read: bytes 12 and 13 */
99
100 /* First byte - should be 0x10 */
101#define TEA5767_MANID_VERSION_MASK 0xf0 /* Version = 1 */
102#define TEA5767_MANID_ID_MSB_MASK 0x0f /* Manufacurer ID - should be 0 */
103
104 /* Second byte - Should be 0x2b */
105
106#define TEA5767_MANID_ID_LSB_MASK 0xfe /* Manufacturer ID - should be 0x15 */
107#define TEA5767_MANID_IDAV 0x01 /* 1 = Chip has ID, 0 = Chip has no ID */
108
109/* Chip ID - Read: bytes 14 and 15 */
110
111 /* First byte - should be 0x57 */
112
113 /* Second byte - should be 0x61 */
114
115/*****************************************************************************/
116
117static void set_tv_freq(struct i2c_client *c, unsigned int freq)
118{
119 struct tuner *t = i2c_get_clientdata(c);
120
121 tuner_warn("This tuner doesn't support TV freq.\n");
122}
123
124#define FREQ_OFFSET 0 /* for TEA5767, it is 700 to give the right freq */
125static void tea5761_status_dump(unsigned char *buffer)
126{
127 unsigned int div, frq;
128
129 div = ((buffer[2] & 0x3f) << 8) | buffer[3];
130
131 frq = 1000 * (div * 32768 / 1000 + FREQ_OFFSET + 225) / 4; /* Freq in KHz */
132
133 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n",
134 frq / 1000, frq % 1000, div);
135}
136
137/* Freq should be specifyed at 62.5 Hz */
138static void set_radio_freq(struct i2c_client *c, unsigned int frq)
139{
140 struct tuner *t = i2c_get_clientdata(c);
141 unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 };
142 unsigned div;
143 int rc;
144
145 tuner_dbg (PREFIX "radio freq counter %d\n", frq);
146
147 if (t->mode == T_STANDBY) {
148 tuner_dbg("TEA5761 set to standby mode\n");
149 buffer[5] |= TEA5761_TNCTRL_MU;
150 } else {
151 buffer[4] |= TEA5761_TNCTRL_PUPD_0;
152 }
153
154
155 if (t->audmode == V4L2_TUNER_MODE_MONO) {
156 tuner_dbg("TEA5761 set to mono\n");
157 buffer[5] |= TEA5761_TNCTRL_MST;
158;
159 } else {
160 tuner_dbg("TEA5761 set to stereo\n");
161 }
162
163 div = (1000 * (frq * 4 / 16 + 700 + 225) ) >> 15;
164 buffer[1] = (div >> 8) & 0x3f;
165 buffer[2] = div & 0xff;
166
167 if (tuner_debug)
168 tea5761_status_dump(buffer);
169
170 if (7 != (rc = i2c_master_send(c, buffer, 7)))
171 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
172}
173
174static int tea5761_signal(struct i2c_client *c)
175{
176 unsigned char buffer[16];
177 int rc;
178 struct tuner *t = i2c_get_clientdata(c);
179
180 memset(buffer, 0, sizeof(buffer));
181 if (16 != (rc = i2c_master_recv(c, buffer, 16)))
182 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
183
184 return ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4));
185}
186
187static int tea5761_stereo(struct i2c_client *c)
188{
189 unsigned char buffer[16];
190 int rc;
191 struct tuner *t = i2c_get_clientdata(c);
192
193 memset(buffer, 0, sizeof(buffer));
194 if (16 != (rc = i2c_master_recv(c, buffer, 16)))
195 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
196
197 rc = buffer[9] & TEA5761_TUNCHECK_STEREO;
198
199 tuner_dbg("TEA5761 radio ST GET = %02x\n", rc);
200
201 return (rc ? V4L2_TUNER_SUB_STEREO : 0);
202}
203
204int tea5761_autodetection(struct i2c_client *c)
205{
206 unsigned char buffer[16];
207 int rc;
208 struct tuner *t = i2c_get_clientdata(c);
209
210 if (16 != (rc = i2c_master_recv(c, buffer, 16))) {
211 tuner_warn("it is not a TEA5761. Received %i chars.\n", rc);
212 return EINVAL;
213 }
214
215 if (!((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061))) {
216 tuner_warn("Manufacturer ID= 0x%02x, Chip ID = %02x%02x. It is not a TEA5761\n",buffer[13],buffer[14],buffer[15]);
217 return EINVAL;
218 }
219 tuner_warn("TEA5761 detected.\n");
220 return 0;
221}
222
223int tea5761_tuner_init(struct i2c_client *c)
224{
225 struct tuner *t = i2c_get_clientdata(c);
226
227 if (tea5761_autodetection(c) == EINVAL)
228 return EINVAL;
229
230 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5761HN FM Radio");
231 strlcpy(c->name, "tea5761", sizeof(c->name));
232
233 t->set_tv_freq = set_tv_freq;
234 t->set_radio_freq = set_radio_freq;
235 t->has_signal = tea5761_signal;
236 t->is_stereo = tea5761_stereo;
237
238 return (0);
239}
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 505591a7abe9..591ca9ce0440 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -25,6 +25,9 @@
25 25
26/* standard i2c insmod options */ 26/* standard i2c insmod options */
27static unsigned short normal_i2c[] = { 27static unsigned short normal_i2c[] = {
28#ifdef CONFIG_TUNER_5761
29 0x10,
30#endif
28 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */ 31 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
29 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 32 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
30 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 33 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
@@ -189,6 +192,16 @@ static void set_type(struct i2c_client *c, unsigned int type,
189 } 192 }
190 t->mode_mask = T_RADIO; 193 t->mode_mask = T_RADIO;
191 break; 194 break;
195#ifdef CONFIG_TUNER_5761
196 case TUNER_TEA5761:
197 if (tea5761_tuner_init(c) == EINVAL) {
198 t->type = TUNER_ABSENT;
199 t->mode_mask = T_UNINITIALIZED;
200 return -ENODEV;
201 }
202 t->mode_mask = T_RADIO;
203 break;
204#endif
192 case TUNER_PHILIPS_FMD1216ME_MK3: 205 case TUNER_PHILIPS_FMD1216ME_MK3:
193 buffer[0] = 0x0b; 206 buffer[0] = 0x0b;
194 buffer[1] = 0xdc; 207 buffer[1] = 0xdc;
@@ -460,6 +473,19 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
460 /* autodetection code based on the i2c addr */ 473 /* autodetection code based on the i2c addr */
461 if (!no_autodetect) { 474 if (!no_autodetect) {
462 switch (addr) { 475 switch (addr) {
476#ifdef CONFIG_TUNER_5761
477 case 0x10:
478 if (tea5761_autodetection(&t->i2c) != EINVAL) {
479 t->type = TUNER_TEA5761;
480 t->mode_mask = T_RADIO;
481 t->mode = T_STANDBY;
482 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
483 default_mode_mask &= ~T_RADIO;
484
485 goto register_client;
486 }
487 break;
488#endif
463 case 0x42: 489 case 0x42:
464 case 0x43: 490 case 0x43:
465 case 0x4a: 491 case 0x4a:
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index 74c3e6f96f1a..03849a166e55 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -1463,6 +1463,10 @@ struct tunertype tuners[] = {
1463 .name = "Philips TDA988[5,6,7] IF PLL Demodulator", 1463 .name = "Philips TDA988[5,6,7] IF PLL Demodulator",
1464 /* see tda9887.c for details */ 1464 /* see tda9887.c for details */
1465 }, 1465 },
1466 [TUNER_TEA5761] = { /* Philips RADIO */
1467 .name = "Philips TEA5761 FM Radio",
1468 /* see tea5767.c for details */
1469 },
1466}; 1470};
1467 1471
1468unsigned const int tuner_count = ARRAY_SIZE(tuners); 1472unsigned const int tuner_count = ARRAY_SIZE(tuners);