summaryrefslogtreecommitdiff
path: root/linux/drivers/media/dvb/frontends/alps_tdmb7.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/drivers/media/dvb/frontends/alps_tdmb7.c')
-rw-r--r--linux/drivers/media/dvb/frontends/alps_tdmb7.c532
1 files changed, 0 insertions, 532 deletions
diff --git a/linux/drivers/media/dvb/frontends/alps_tdmb7.c b/linux/drivers/media/dvb/frontends/alps_tdmb7.c
deleted file mode 100644
index e07db4bb1..000000000
--- a/linux/drivers/media/dvb/frontends/alps_tdmb7.c
+++ /dev/null
@@ -1,532 +0,0 @@
-/*
- Alps TDMB7 DVB OFDM frontend driver
-
- Copyright (C) 2001-2002 Convergence Integrated Media GmbH
- Holger Waechtler <holger@convergence.de>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-
-#include "dvb_frontend.h"
-
-#define FRONTEND_NAME "dvbfe_alps_tdmb7"
-
-#define dprintk(args...) \
- do { \
- if (debug) printk(KERN_DEBUG FRONTEND_NAME ": " args); \
- } while (0)
-
-static int debug;
-
-module_param(debug, int, 0644);
-MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
-
-
-static struct dvb_frontend_info tdmb7_info = {
- .name = "Alps TDMB7",
- .type = FE_OFDM,
- .frequency_min = 470000000,
- .frequency_max = 860000000,
- .frequency_stepsize = 166667,
-#if 0
- .frequency_tolerance = ???,
- .symbol_rate_min = ???,
- .symbol_rate_max = ???,
- .symbol_rate_tolerance = 500, /* ppm */
- .notifier_delay = 0,
-#endif
- .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
- FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
- FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
- FE_CAN_RECOVER
-};
-
-struct tdmb7_state {
- struct i2c_adapter *i2c;
- struct dvb_adapter *dvb;
-};
-
-static u8 init_tab [] = {
- 0x04, 0x10,
- 0x05, 0x09,
- 0x06, 0x00,
- 0x08, 0x04,
- 0x09, 0x00,
- 0x0a, 0x01,
- 0x15, 0x40,
- 0x16, 0x10,
- 0x17, 0x87,
- 0x18, 0x17,
- 0x1a, 0x10,
- 0x25, 0x04,
- 0x2e, 0x00,
- 0x39, 0x00,
- 0x3a, 0x04,
- 0x45, 0x08,
- 0x46, 0x02,
- 0x47, 0x05,
-};
-
-static int cx22700_writereg (struct i2c_adapter *i2c, u8 reg, u8 data)
-{
- int ret;
- u8 buf [] = { reg, data };
- struct i2c_msg msg = { .addr = 0x43, .flags = 0, .buf = buf, .len = 2 };
-
- dprintk ("%s\n", __FUNCTION__);
-
- ret = i2c_transfer (i2c, &msg, 1);
-
- if (ret != 1)
- printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
- __FUNCTION__, reg, data, ret);
-
- return (ret != 1) ? -1 : 0;
-}
-
-static u8 cx22700_readreg (struct i2c_adapter *i2c, u8 reg)
-{
- int ret;
- u8 b0 [] = { reg };
- u8 b1 [] = { 0 };
- struct i2c_msg msg [] = { { .addr = 0x43, .flags = 0, .buf = b0, .len = 1 },
- { .addr = 0x43, .flags = I2C_M_RD, .buf = b1, .len = 1 } };
-
- dprintk ("%s\n", __FUNCTION__);
-
- ret = i2c_transfer (i2c, msg, 2);
-
- if (ret != 2)
- printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret);
-
- return b1[0];
-}
-
-static int pll_write (struct i2c_adapter *i2c, u8 data [4])
-{
- struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = 4 };
- int ret;
-
- cx22700_writereg (i2c, 0x0a, 0x00); /* open i2c bus switch */
- ret = i2c_transfer (i2c, &msg, 1);
- cx22700_writereg (i2c, 0x0a, 0x01); /* close i2c bus switch */
-
- if (ret != 1)
- printk("%s: i/o error (addr == 0x%02x, ret == %i)\n", __FUNCTION__, msg.addr, ret);
-
- return (ret != 1) ? -1 : 0;
-}
-
-/**
- * set up the downconverter frequency divisor for a
- * reference clock comparision frequency of 125 kHz.
- */
-static int pll_set_tv_freq (struct i2c_adapter *i2c, u32 freq)
-{
- u32 div = (freq + 36166667) / 166667;
-#if 1 //ALPS_SETTINGS
- u8 buf [4] = { (div >> 8) & 0x7f, div & 0xff, ((div >> 10) & 0x60) | 0x85,
- freq < 592000000 ? 0x40 : 0x80 };
-#else
- u8 buf [4] = { (div >> 8) & 0x7f, div & 0xff, ((div >> 10) & 0x60) | 0x85,
- freq < 470000000 ? 0x42 : freq < 862000000 ? 0x41 : 0x81 };
-#endif
-
- dprintk ("%s: freq == %i, div == %i\n", __FUNCTION__, (int) freq, (int) div);
-
- return pll_write (i2c, buf);
-}
-
-static int cx22700_init (struct i2c_adapter *i2c)
-{
- int i;
-
- dprintk("cx22700_init: init chip\n");
-
- cx22700_writereg (i2c, 0x00, 0x02); /* soft reset */
- cx22700_writereg (i2c, 0x00, 0x00);
-
- msleep(10);
-
- for (i=0; i<sizeof(init_tab); i+=2)
- cx22700_writereg (i2c, init_tab[i], init_tab[i+1]);
-
- cx22700_writereg (i2c, 0x00, 0x01);
-
- return 0;
-}
-
-static int cx22700_set_inversion (struct i2c_adapter *i2c, int inversion)
-{
- u8 val;
-
- dprintk ("%s\n", __FUNCTION__);
-
- switch (inversion) {
- case INVERSION_AUTO:
- return -EOPNOTSUPP;
- case INVERSION_ON:
- val = cx22700_readreg (i2c, 0x09);
- return cx22700_writereg (i2c, 0x09, val | 0x01);
- case INVERSION_OFF:
- val = cx22700_readreg (i2c, 0x09);
- return cx22700_writereg (i2c, 0x09, val & 0xfe);
- default:
- return -EINVAL;
- }
-}
-
-static int cx22700_set_tps (struct i2c_adapter *i2c, struct dvb_ofdm_parameters *p)
-{
- static const u8 qam_tab [4] = { 0, 1, 0, 2 };
- static const u8 fec_tab [6] = { 0, 1, 2, 0, 3, 4 };
- u8 val;
-
- dprintk ("%s\n", __FUNCTION__);
-
- if (p->code_rate_HP < FEC_1_2 || p->code_rate_HP > FEC_7_8)
- return -EINVAL;
-
- if (p->code_rate_LP < FEC_1_2 || p->code_rate_LP > FEC_7_8)
-
- if (p->code_rate_HP == FEC_4_5 || p->code_rate_LP == FEC_4_5)
- return -EINVAL;
-
- if (p->guard_interval < GUARD_INTERVAL_1_32 ||
- p->guard_interval > GUARD_INTERVAL_1_4)
- return -EINVAL;
-
- if (p->transmission_mode != TRANSMISSION_MODE_2K &&
- p->transmission_mode != TRANSMISSION_MODE_8K)
- return -EINVAL;
-
- if (p->constellation != QPSK &&
- p->constellation != QAM_16 &&
- p->constellation != QAM_64)
- return -EINVAL;
-
- if (p->hierarchy_information < HIERARCHY_NONE ||
- p->hierarchy_information > HIERARCHY_4)
- return -EINVAL;
-
- if (p->bandwidth < BANDWIDTH_8_MHZ && p->bandwidth > BANDWIDTH_6_MHZ)
- return -EINVAL;
-
- if (p->bandwidth == BANDWIDTH_7_MHZ)
- cx22700_writereg (i2c, 0x09, cx22700_readreg (i2c, 0x09 | 0x10));
- else
- cx22700_writereg (i2c, 0x09, cx22700_readreg (i2c, 0x09 & ~0x10));
-
- val = qam_tab[p->constellation - QPSK];
- val |= p->hierarchy_information - HIERARCHY_NONE;
-
- cx22700_writereg (i2c, 0x04, val);
-
- val = fec_tab[p->code_rate_HP - FEC_1_2] << 3;
- val |= fec_tab[p->code_rate_LP - FEC_1_2];
-
- cx22700_writereg (i2c, 0x05, val);
-
- val = (p->guard_interval - GUARD_INTERVAL_1_32) << 2;
- val |= p->transmission_mode - TRANSMISSION_MODE_2K;
-
- cx22700_writereg (i2c, 0x06, val);
-
- cx22700_writereg (i2c, 0x08, 0x04 | 0x02); /* use user tps parameters */
- cx22700_writereg (i2c, 0x08, 0x04); /* restart aquisition */
-
- return 0;
-}
-
-static int cx22700_get_tps (struct i2c_adapter *i2c, struct dvb_ofdm_parameters *p)
-{
- static const fe_modulation_t qam_tab [3] = { QPSK, QAM_16, QAM_64 };
- static const fe_code_rate_t fec_tab [5] = { FEC_1_2, FEC_2_3, FEC_3_4,
- FEC_5_6, FEC_7_8 };
- u8 val;
-
- dprintk ("%s\n", __FUNCTION__);
-
- if (!(cx22700_readreg(i2c, 0x07) & 0x20)) /* tps valid? */
- return -EAGAIN;
-
- val = cx22700_readreg (i2c, 0x01);
-
- if ((val & 0x7) > 4)
- p->hierarchy_information = HIERARCHY_AUTO;
- else
- p->hierarchy_information = HIERARCHY_NONE + (val & 0x7);
-
- if (((val >> 3) & 0x3) > 2)
- p->constellation = QAM_AUTO;
- else
- p->constellation = qam_tab[(val >> 3) & 0x3];
-
- val = cx22700_readreg (i2c, 0x02);
-
- if (((val >> 3) & 0x07) > 4)
- p->code_rate_HP = FEC_AUTO;
- else
- p->code_rate_HP = fec_tab[(val >> 3) & 0x07];
-
- if ((val & 0x07) > 4)
- p->code_rate_LP = FEC_AUTO;
- else
- p->code_rate_LP = fec_tab[val & 0x07];
-
- val = cx22700_readreg (i2c, 0x03);
-
- p->guard_interval = GUARD_INTERVAL_1_32 + ((val >> 6) & 0x3);
- p->transmission_mode = TRANSMISSION_MODE_2K + ((val >> 5) & 0x1);
-
- return 0;
-}
-
-static int tdmb7_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg)
-{
- struct tdmb7_state *state = fe->data;
- struct i2c_adapter *i2c = state->i2c;
-
- dprintk ("%s\n", __FUNCTION__);
-
- switch (cmd) {
- case FE_GET_INFO:
- memcpy (arg, &tdmb7_info, sizeof(struct dvb_frontend_info));
- break;
-
- case FE_READ_STATUS:
- {
- fe_status_t *status = (fe_status_t *) arg;
- u16 rs_ber = (cx22700_readreg (i2c, 0x0d) << 9)
- | (cx22700_readreg (i2c, 0x0e) << 1);
- u8 sync = cx22700_readreg (i2c, 0x07);
-
- *status = 0;
-
- if (rs_ber < 0xff00)
- *status |= FE_HAS_SIGNAL;
-
- if (sync & 0x20)
- *status |= FE_HAS_CARRIER;
-
- if (sync & 0x10)
- *status |= FE_HAS_VITERBI;
-
- if (sync & 0x10)
- *status |= FE_HAS_SYNC;
-
- if (*status == 0x0f)
- *status |= FE_HAS_LOCK;
-
- break;
- }
-
- case FE_READ_BER:
- *((u32*) arg) = cx22700_readreg (i2c, 0x0c) & 0x7f;
- cx22700_writereg (i2c, 0x0c, 0x00);
- break;
-
- case FE_READ_SIGNAL_STRENGTH:
- {
- u16 rs_ber = (cx22700_readreg (i2c, 0x0d) << 9)
- | (cx22700_readreg (i2c, 0x0e) << 1);
- *((u16*) arg) = ~rs_ber;
- break;
- }
- case FE_READ_SNR:
- {
- u16 rs_ber = (cx22700_readreg (i2c, 0x0d) << 9)
- | (cx22700_readreg (i2c, 0x0e) << 1);
- *((u16*) arg) = ~rs_ber;
- break;
- }
- case FE_READ_UNCORRECTED_BLOCKS:
- *((u32*) arg) = cx22700_readreg (i2c, 0x0f);
- cx22700_writereg (i2c, 0x0f, 0x00);
- break;
-
- case FE_SET_FRONTEND:
- {
- struct dvb_frontend_parameters *p = arg;
-
- cx22700_writereg (i2c, 0x00, 0x02); /* XXX CHECKME: soft reset*/
- cx22700_writereg (i2c, 0x00, 0x00);
-
- pll_set_tv_freq (i2c, p->frequency);
- cx22700_set_inversion (i2c, p->inversion);
- cx22700_set_tps (i2c, &p->u.ofdm);
- cx22700_writereg (i2c, 0x37, 0x01); /* PAL loop filter off */
- cx22700_writereg (i2c, 0x00, 0x01); /* restart acquire */
- break;
- }
-
- case FE_GET_FRONTEND:
- {
- struct dvb_frontend_parameters *p = arg;
- u8 reg09 = cx22700_readreg (i2c, 0x09);
-
- p->inversion = reg09 & 0x1 ? INVERSION_ON : INVERSION_OFF;
- return cx22700_get_tps (i2c, &p->u.ofdm);
- }
-
- case FE_INIT:
- return cx22700_init (i2c);
-
- case FE_GET_TUNE_SETTINGS:
- {
- struct dvb_frontend_tune_settings* fesettings = (struct dvb_frontend_tune_settings*) arg;
- fesettings->min_delay_ms = 150;
- fesettings->step_size = 166667;
- fesettings->max_drift = 166667*2;
- return 0;
- }
-
- default:
- return -EOPNOTSUPP;
- };
-
- return 0;
-}
-
-static struct i2c_client client_template;
-
-static int attach_adapter (struct i2c_adapter *adapter)
-{
- struct tdmb7_state *state;
- struct i2c_client *client;
- int ret;
-
- u8 b0 [] = { 0x7 };
- u8 b1 [] = { 0 };
- struct i2c_msg msg [] = { { .addr = 0x43, .flags = 0, .buf = b0, .len = 1 },
- { .addr = 0x43, .flags = I2C_M_RD, .buf = b1, .len = 1 } };
-
- dprintk ("%s\n", __FUNCTION__);
-
- if (i2c_transfer(adapter, msg, 2) != 2)
- return -ENODEV;
-
- if (NULL == (state = kmalloc(sizeof(struct tdmb7_state), GFP_KERNEL)))
- return -ENOMEM;
-
- state->i2c = adapter;
-
- if (NULL == (client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
- kfree(state);
- return -ENOMEM;
- }
-
- memcpy(client, &client_template, sizeof(struct i2c_client));
- client->adapter = adapter;
- i2c_set_clientdata(client, state);
-
- ret = i2c_attach_client(client);
- if (ret) {
- kfree(state);
- kfree(client);
- return ret;
- }
-
- BUG_ON(!state->dvb);
-
- ret = dvb_register_frontend (tdmb7_ioctl, state->dvb, state,
- &tdmb7_info, THIS_MODULE);
- if (ret) {
- i2c_detach_client(client);
- kfree(state);
- kfree(client);
- return ret;
- }
-
- return 0;
-}
-
-static int detach_client (struct i2c_client *client)
-{
- struct tdmb7_state *state = i2c_get_clientdata(client);
-
- dprintk ("%s\n", __FUNCTION__);
-
- dvb_unregister_frontend (tdmb7_ioctl, state->dvb);
- i2c_detach_client(client);
- BUG_ON(state->dvb);
- kfree(client);
- kfree(state);
- return 0;
-}
-
-static int command (struct i2c_client *client,
- unsigned int cmd, void *arg)
-{
- struct tdmb7_state *state = i2c_get_clientdata(client);
-
- dprintk("%s\n", __FUNCTION__);
-
- switch (cmd) {
- case FE_REGISTER:
- state->dvb = arg;
- break;
- case FE_UNREGISTER:
- state->dvb = NULL;
- break;
- default:
- return -EOPNOTSUPP;
- }
-
- return 0;
-}
-
-static struct i2c_driver driver = {
- .owner = THIS_MODULE,
- .name = FRONTEND_NAME,
- .id = I2C_DRIVERID_DVBFE_ALPS_TDMB7,
- .flags = I2C_DF_NOTIFY,
- .attach_adapter = attach_adapter,
- .detach_client = detach_client,
- .command = command,
-};
-
-static struct i2c_client client_template = {
- .name = FRONTEND_NAME,
- .flags = I2C_CLIENT_ALLOW_USE,
- .driver = &driver,
-};
-
-static int __init init_tdmb7 (void)
-{
- return i2c_add_driver(&driver);
-}
-
-static void __exit exit_tdmb7 (void)
-{
- if (i2c_del_driver(&driver))
- printk(KERN_ERR "alps_tdmb7: driver deregistration failed.\n");
-}
-
-module_init (init_tdmb7);
-module_exit (exit_tdmb7);
-
-MODULE_DESCRIPTION("TDMB7 DVB Frontend driver");
-MODULE_AUTHOR("Holger Waechtler");
-MODULE_LICENSE("GPL");
-