summaryrefslogtreecommitdiff
path: root/linux/drivers/media/video/tea5767.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <devnull@localhost>2005-06-05 17:44:04 +0000
committerMauro Carvalho Chehab <devnull@localhost>2005-06-05 17:44:04 +0000
commit8a59c7d103ce703187bbc6aa1498adfb25dbb12d (patch)
tree4d062c25c618f7d26ad4c72aaab08a3deec1a476 /linux/drivers/media/video/tea5767.c
parent4d257e90cc7ab196053d9b2fa34f7b50a69b0772 (diff)
downloadmediapointer-dvb-s2-8a59c7d103ce703187bbc6aa1498adfb25dbb12d.tar.gz
mediapointer-dvb-s2-8a59c7d103ce703187bbc6aa1498adfb25dbb12d.tar.bz2
tea5767.c, Makefile, tuner-core.c, tuner-simple.c, tuner.h:
- Support for radio chip tea5767hn included. - It is used on several TV+FM cards, like cards with Tvision tuners (maybe also Tenna?). - This chip is always at I2C address 0xC0.
Diffstat (limited to 'linux/drivers/media/video/tea5767.c')
-rw-r--r--linux/drivers/media/video/tea5767.c247
1 files changed, 247 insertions, 0 deletions
diff --git a/linux/drivers/media/video/tea5767.c b/linux/drivers/media/video/tea5767.c
new file mode 100644
index 000000000..e49a53a1b
--- /dev/null
+++ b/linux/drivers/media/video/tea5767.c
@@ -0,0 +1,247 @@
+/*
+ * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
+ * I2C address is allways 0xC0.
+ *
+ * $Id: tea5767.c,v 1.1 2005/06/05 17:44:04 mchehab Exp $
+ *
+ * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
+ * This code is placed under the terms of the GNU General Public License
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/videodev.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+#include "tuner.h"
+#include "i2c-compat.h"
+#else
+#include <media/tuner.h>
+#endif
+
+/* Write mode register values */
+
+/* First register */
+#define TEA5767_MUTE 0x80 /* Mutes output */
+#define TEA5767_SEARCH 0x40 /* Activates station search */
+/* Bits 0-5 for divider MSB */
+
+/* Second register */
+/* Bits 0-7 for divider LSB */
+
+/* Third register */
+
+/* Station search from botton to up */
+#define TEA5767_SEARCH_UP 0x80
+
+/* Searches with ADC output = 10 */
+#define TEA5767_SRCH_HIGH_LVL 0x60
+
+/* Searches with ADC output = 10 */
+#define TEA5767_SRCH_MID_LVL 0x40
+
+/* Searches with ADC output = 5 */
+#define TEA5767_SRCH_LOW_LVL 0x20
+
+/* if on, div=4*(Frf+Fif)/Fref otherwise, div=4*(Frf-Fif)/Freq) */
+#define TEA5767_HIGH_LO_INJECT 0x10
+
+/* Disable stereo */
+#define TEA5767_MONO 0x08
+
+/* Disable right channel and turns to mono */
+#define TEA5767_MUTE_RIGHT 0x04
+
+/* Disable left channel and turns to mono */
+#define TEA5767_MUTE_LEFT 0x02
+
+#define TEA5767_PORT1_HIGH 0x01
+
+/* Forth register */
+#define TEA5767_PORT2_HIGH 0x80
+/* Chips stops working. Only I2C bus remains on */
+#define TEA5767_STDBY 0x40
+
+/* Japan freq (76-108 MHz. If disabled, 87.5-108 MHz */
+#define TEA5767_JAPAN_BAND 0x20
+
+/* Unselected means 32.768 KHz freq as reference. Otherwise Xtal at 13 MHz */
+#define TEA5767_XTAL_32768 0x10
+
+/* Cuts weak signals */
+#define TEA5767_SOFT_MUTE 0x08
+
+/* Activates high cut control */
+#define TEA5767_HIGH_CUT_CTRL 0x04
+
+/* Activates stereo noise control */
+#define TEA5767_ST_NOISE_CTL 0x02
+
+/* If activate PORT 1 indicates SEARCH or else it is used as PORT1 */
+#define TEA5767_SRCH_IND 0x01
+
+/* Fiveth register */
+
+/* By activating, it will use Xtal at 13 MHz as reference for divider */
+#define TEA5767_PLLREF_ENABLE 0x80
+
+/* By activating, deemphasis=50, or else, deemphasis of 50us */
+#define TEA5767_DEEMPH_75 0X40
+/* Read mode register values */
+/* First register */
+#define TEA5767_READY_FLAG_MASK 0x80
+#define TEA5767_BAND_LIMIT_MASK 0X40
+/* Bits 0-5 for divider MSB after search or preset */
+
+/* Second register */
+/* Bits 0-7 for divider LSB after search or preset */
+
+/* Third register */
+#define TEA5767_STEREO_MASK 0x80
+#define TEA5767_IF_CNTR_MASK 0x7f
+
+/* Four register */
+#define TEA5767_ADC_LEVEL_MASK 0xf0
+
+/* should be 0 */
+#define TEA5767_CHIP_ID_MASK 0x0f
+
+/* Fiveth register */
+/* Reserved for future extensions */
+#define TEA5767_RESERVED_MASK 0xff
+
+
+enum v4l_radio_tuner {
+ RADIO_TUNER_UNSET = 0,
+ TEA5767_HIGH_LO_32768 = 1,
+ TEA5767_LOW_LO_32768 = 2,
+ TEA5767_HIGH_LO_13MHz = 3,
+ TEA5767_LOW_LO_13MHz = 4,
+};
+
+static void set_tv_freq(struct i2c_client *c, unsigned int freq)
+{
+ struct tuner *t = i2c_get_clientdata(c);
+
+ tuner_warn("This tuner doesn't support TV freq.\n");
+}
+
+static void set_radio_freq(struct i2c_client *c, unsigned int frq)
+{
+ struct tuner *t = i2c_get_clientdata(c);
+ unsigned char buffer[5];
+ unsigned div;
+ int rc;
+
+ buffer[2] = TEA5767_PORT1_HIGH;
+ buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | TEA5767_ST_NOISE_CTL;
+ buffer[4]=0;
+
+ switch (t->type) {
+
+ case TEA5767_HIGH_LO_13MHz:
+ tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n");
+ buffer[2] |= TEA5767_HIGH_LO_INJECT;
+ buffer[4] |= TEA5767_PLLREF_ENABLE;
+ div = (frq*4000/16+225+25)/50;
+ break;
+ case TEA5767_LOW_LO_13MHz:
+ tuner_dbg("TEA5767 radio LOW LO inject xtal @ 13 MHz\n");
+
+ buffer[4] |= TEA5767_PLLREF_ENABLE;
+ div = (frq*4000/16-225+25)/50;
+ break;
+ case TEA5767_LOW_LO_32768:
+ tuner_dbg("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n");
+
+ buffer[3] |= TEA5767_XTAL_32768;
+ div = (1000*(frq*4000/16+225)+16384)/32768;
+ break;
+ case TEA5767_HIGH_LO_32768:
+ default:
+ tuner_dbg("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n");
+
+ buffer[2] |= TEA5767_HIGH_LO_INJECT;
+ buffer[3] |= TEA5767_XTAL_32768;
+ div = (1000*(frq*4000/16+225)+16384)/32768;
+ break;
+ }
+ buffer[0] = (div>>8) & 0x3f;
+ buffer[1] = div & 0xff;
+
+ tuner_dbg("TEA5767 radio SET 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
+ buffer[0],buffer[1],buffer[2],buffer[3],buffer[4]);
+
+ if (5 != (rc = i2c_master_send(c,buffer,5)))
+ tuner_warn("i2c i/o error: rc == %d (should be 5)\n",rc);
+}
+
+static int tea5767_signal(struct i2c_client *c)
+{
+ unsigned char buffer[5];
+ int rc;
+ struct tuner *t = i2c_get_clientdata(c);
+
+ memset(buffer,0,sizeof(buffer));
+ if (5 != (rc = i2c_master_recv(c,buffer,5)))
+ tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc);
+
+ tuner_dbg("TEA5767 radio SIG GET 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
+ buffer[0],buffer[1],buffer[2],buffer[3],buffer[4]);
+
+ return ( (buffer[0] & TEA5767_READY_FLAG_MASK) ? 0x7<<13 : 0);
+}
+
+static int tea5767_stereo(struct i2c_client *c)
+{
+ unsigned char buffer[5];
+ int rc;
+ struct tuner *t = i2c_get_clientdata(c);
+
+ memset(buffer,0,sizeof(buffer));
+ if (5 != (rc = i2c_master_recv(c,buffer,5)))
+ tuner_warn ( "i2c i/o error: rc == %d (should be 5)\n",rc);
+
+ tuner_dbg("TEA5767 radio ST GET 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
+ buffer[0],buffer[1],buffer[2],buffer[3],buffer[4]);
+
+ return ( (buffer[2] & TEA5767_STEREO_MASK) ? 0x10: 0);
+}
+
+int tea5767_tuner_init(struct i2c_client *c)
+{
+ /* TEA5767 is always on 0xC0, according with Philips datasheet */
+ struct tuner_addr tun_addr = { V4L2_TUNER_RADIO, 0xc0>>1 };
+
+ struct tuner *t = i2c_get_clientdata(c);
+
+ /***************************************************************************
+ HACKING FOR TESTING PURPOSES ONLY. Should have an option to configure
+ ***************************************************************************/
+ t->type= TEA5767_HIGH_LO_32768;
+// t->type= TEA5767_LOW_LO_32768;
+ strlcpy(c->name, "TEA5767", sizeof("TEA5767"));
+ tuner_info("type set to TEA5797\n");
+
+ if (c->driver->command) {
+ c->driver->command(c, TUNER_SET_ADDR, &tun_addr);
+ } else {
+ tuner_warn("TAE5797 Couldn't set Radio tuner I2C address to 0xc0\n");
+ return -1;
+ }
+
+ t->tv_freq = set_tv_freq;
+ t->radio_freq = set_radio_freq;
+ t->has_signal = tea5767_signal;
+ t->is_stereo = tea5767_stereo;
+ return 0;
+}