summaryrefslogtreecommitdiff
path: root/linux/drivers/media/video/tda8290.c
diff options
context:
space:
mode:
authorGerd Knorr <devnull@localhost>2005-02-09 15:42:46 +0000
committerGerd Knorr <devnull@localhost>2005-02-09 15:42:46 +0000
commitd88c7c9e5a9181439bd0facde6802a881acd5442 (patch)
tree3e999d3831b6572297f10d83be93a564bc306a8c /linux/drivers/media/video/tda8290.c
parentdaadf7ba2bb54985678fe7f8270cf18e34f6e9f0 (diff)
downloadmediapointer-dvb-s2-d88c7c9e5a9181439bd0facde6802a881acd5442.tar.gz
mediapointer-dvb-s2-d88c7c9e5a9181439bd0facde6802a881acd5442.tar.bz2
- split tuner module into multiple smaller files.
Diffstat (limited to 'linux/drivers/media/video/tda8290.c')
-rw-r--r--linux/drivers/media/video/tda8290.c265
1 files changed, 265 insertions, 0 deletions
diff --git a/linux/drivers/media/video/tda8290.c b/linux/drivers/media/video/tda8290.c
new file mode 100644
index 000000000..898ac62e5
--- /dev/null
+++ b/linux/drivers/media/video/tda8290.c
@@ -0,0 +1,265 @@
+/*
+ * $Id: tda8290.c,v 1.1 2005/02/09 15:42:46 kraxel Exp $
+ */
+#include <linux/i2c.h>
+#include <linux/videodev.h>
+#include <linux/delay.h>
+#include <media/tuner.h>
+
+/* ---------------------------------------------------------------------- */
+
+struct freq_entry {
+ __u16 freq;
+ __u8 value;
+};
+
+static struct freq_entry band_table[] = {
+ { 0x2DF4, 0x1C },
+ { 0x2574, 0x14 },
+ { 0x22B4, 0x0C },
+ { 0x20D4, 0x0B },
+ { 0x1E74, 0x3B },
+ { 0x1C34, 0x33 },
+ { 0x16F4, 0x5B },
+ { 0x1454, 0x53 },
+ { 0x12D4, 0x52 },
+ { 0x1034, 0x4A },
+ { 0x0EE4, 0x7A },
+ { 0x0D34, 0x72 },
+ { 0x0B54, 0x9A },
+ { 0x0914, 0x91 },
+ { 0x07F4, 0x89 },
+ { 0x0774, 0xB9 },
+ { 0x067B, 0xB1 },
+ { 0x0634, 0xD9 },
+ { 0x05A4, 0xD8 }, // FM radio
+ { 0x0494, 0xD0 },
+ { 0x03BC, 0xC8 },
+ { 0x0394, 0xF8 }, // 57250000 Hz
+ { 0x0000, 0xF0 }, // 0
+};
+
+static struct freq_entry div_table[] = {
+ { 0x1C34, 3 },
+ { 0x0D34, 2 },
+ { 0x067B, 1 },
+ { 0x0000, 0 },
+};
+
+static struct freq_entry agc_table[] = {
+ { 0x22B4, 0x8F },
+ { 0x0B54, 0x9F },
+ { 0x09A4, 0x8F },
+ { 0x0554, 0x9F },
+ { 0x0000, 0xBF },
+};
+
+static __u8 get_freq_entry( struct freq_entry* table, __u16 freq)
+{
+ while(table->freq && table->freq > freq)
+ table++;
+ return table->value;
+}
+
+/* ---------------------------------------------------------------------- */
+
+static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 };
+static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 };
+static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00,
+ 0x7C, 0x04, 0xA3, 0x3F,
+ 0x2A, 0x04, 0xFF, 0x00,
+ 0x00, 0x40 };
+static unsigned char i2c_set_VS[2] = { 0x30, 0x6F };
+static unsigned char i2c_set_GP01_CF[2] = { 0x20, 0x0B };
+static unsigned char i2c_easy_mode[2] = { 0x01, 0x02 };
+static unsigned char i2c_tda8290_reset[2] = { 0x00, 0x00 };
+static unsigned char i2c_gainset_off[2] = { 0x28, 0x14 };
+static unsigned char i2c_gainset_on[2] = { 0x28, 0x54 };
+static unsigned char i2c_set_freq[8] = { 0x00, 0x00, 0x00, 0x40,
+ 0x52, 0x00, 0x00, 0x8F };
+static unsigned char i2c_agc3_00[2] = { 0x80, 0x00 };
+static unsigned char i2c_agc2_BF[2] = { 0x60, 0xBF };
+static unsigned char i2c_cb1_D2[2] = { 0x30, 0xD2 };
+static unsigned char i2c_cb1_56[2] = { 0x30, 0x56 };
+static unsigned char i2c_cb1_52[2] = { 0x30, 0x52 };
+static unsigned char i2c_cb1_50[2] = { 0x30, 0x50 };
+static unsigned char i2c_agc2_7F[2] = { 0x60, 0x7F };
+static unsigned char i2c_agc3_08[2] = { 0x80, 0x08 };
+
+static struct i2c_msg i2c_msg_init[] = {
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_init_tda8275), i2c_init_tda8275 },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_VS), i2c_set_VS },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_GP01_CF), i2c_set_GP01_CF },
+};
+
+static struct i2c_msg i2c_msg_prolog[] = {
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_easy_mode), i2c_easy_mode },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_off), i2c_gainset_off },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_reset), i2c_tda8290_reset },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge },
+};
+
+static struct i2c_msg i2c_msg_config[] = {
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_set_freq), i2c_set_freq },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_00), i2c_agc3_00 },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_BF), i2c_agc2_BF },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D2), i2c_cb1_D2 },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_56), i2c_cb1_56 },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_52), i2c_cb1_52 },
+};
+
+static struct i2c_msg i2c_msg_epilog[] = {
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_50), i2c_cb1_50 },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_7F), i2c_agc2_7F },
+ { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_08), i2c_agc3_08 },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
+ { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_on), i2c_gainset_on },
+};
+
+static int tda8290_tune(void)
+{
+ i2c_transfer(tda8290_client_template.adapter, i2c_msg_prolog, ARRAY_SIZE(i2c_msg_prolog));
+ i2c_transfer(tda8290_client_template.adapter, i2c_msg_config, ARRAY_SIZE(i2c_msg_config));
+ msleep(550);
+ i2c_transfer(tda8290_client_template.adapter, i2c_msg_epilog, ARRAY_SIZE(i2c_msg_epilog));
+
+ return 0;
+}
+
+static void set_frequency(struct tuner *t, u32 frequency, u16 ifc)
+{
+ u32 N = (((frequency<<3)+ifc)&0x3fffc);
+
+ N = N >> get_freq_entry(div_table, frequency);
+
+ i2c_set_freq[1] = (unsigned char)(N>>8);
+ i2c_set_freq[2] = (unsigned char) N;
+ i2c_set_freq[5] = get_freq_entry(band_table, frequency);
+ i2c_set_freq[6] = get_freq_entry(agc_table, frequency);
+}
+
+#define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
+#define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
+#define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
+#define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
+
+static void set_audio(struct tuner *t)
+{
+ if (t->std & V4L2_STD_MN)
+ i2c_easy_mode[1] = 0x01;
+ else if (t->std & V4L2_STD_B)
+ i2c_easy_mode[1] = 0x02;
+ else if (t->std & V4L2_STD_GH)
+ i2c_easy_mode[1] = 0x04;
+ else if (t->std & V4L2_STD_PAL_I)
+ i2c_easy_mode[1] = 0x08;
+ else if (t->std & V4L2_STD_DK)
+ i2c_easy_mode[1] = 0x10;
+ else if (t->std & V4L2_STD_SECAM_L)
+ i2c_easy_mode[1] = 0x20;
+}
+
+static void set_tv_freq(struct i2c_client *c, unsigned int freq)
+{
+ struct tuner *t = i2c_get_clientdata(c);
+
+ set_audio(t);
+ set_frequency(t, f->frequency, 864);
+ tda8290_tune();
+}
+
+static void set_radio_freq(struct i2c_client *c, unsigned int freq)
+{
+ struct tuner *t = i2c_get_clientdata(c);
+ set_frequency(t, f->frequency, 704);
+ tda8290_tune();
+}
+
+int default_tuner_init(struct i2c_client *c)
+{
+ struct tuner *t = i2c_get_clientdata(c);
+
+ strlcpy(c->name, "tda8290+75", sizeof(c->name));
+ printk("tuner: type set to %s\n", c->name);
+ t->tv_freq = set_tv_freq;
+ t->radio_freq = set_radio_freq;
+ return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+
+#if 0
+
+static int tda8290_command(struct i2c_client *client, unsigned int cmd, void *arg)
+{
+ if( client->addr == I2C_ADDR_TDA8275)
+ return 0;
+
+ switch (cmd) {
+ /* --- v4l ioctls --- */
+ case VIDIOC_G_TUNER:
+ {
+ struct v4l2_tuner* t = arg;
+
+ if (t->type == V4L2_TUNER_ANALOG_TV)
+ {
+ unsigned char afc = 0;
+ unsigned char i2c_get_afc[1] = { 0x1B };
+
+ i2c_master_send(&tda8290_client_template, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
+ i2c_master_recv(&tda8290_client_template, &afc, 1);
+
+ t->signal = (afc & 0x80)? 65535:0;
+ t->afc = -((((char)(afc<<1))*3375)>>9);
+ }
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+static int tda8290_attach(struct i2c_adapter *adap, int addr, int kind)
+{
+ printk("%s: chip found @ 0x%x\n", __FUNCTION__, addr);
+
+ switch(addr)
+ {
+ case I2C_ADDR_TDA8290:
+ {
+ tda8290_client_template.adapter = adap;
+ tda8290_client_template.addr = addr;
+
+ i2c_attach_client(&tda8290_client_template);
+
+ i2c_master_send(&tda8290_client_template, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge));
+ } break;
+
+ case I2C_ADDR_TDA8275:
+ {
+ tda8275_client_template.adapter = adap;
+ tda8275_client_template.addr = addr;
+
+ i2c_attach_client(&tda8275_client_template);
+
+ i2c_transfer(tda8290_client_template.adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init));
+ } break;
+
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+#endif
+
+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-basic-offset: 8
+ * End:
+ */
+