]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/dvb/frontends/tda10086.c
V4L/DVB (7654): tda10086: make the xtal frequency a configuration option
[linux-2.6-omap-h63xx.git] / drivers / media / dvb / frontends / tda10086.c
index 9d26ace651518389d1cbd3255ee6b05ef83eba34..acf1471373cad3365c9b4c11834e7ea60b98d60e 100644 (file)
@@ -43,7 +43,7 @@ struct tda10086_state {
        bool has_lock;
 };
 
-static int debug = 0;
+static int debug;
 #define dprintk(args...) \
        do { \
                if (debug) printk(KERN_DEBUG "tda10086: " args); \
@@ -60,7 +60,7 @@ static int tda10086_write_byte(struct tda10086_state *state, int reg, int data)
 
        if (ret != 1)
                dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
-                       __FUNCTION__, reg, data, ret);
+                       __func__, reg, data, ret);
 
        return (ret != 1) ? ret : 0;
 }
@@ -78,7 +78,7 @@ static int tda10086_read_byte(struct tda10086_state *state, int reg)
        ret = i2c_transfer(state->i2c, msg, 2);
 
        if (ret != 2) {
-               dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg,
+               dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg,
                        ret);
                return ret;
        }
@@ -106,9 +106,12 @@ static int tda10086_write_mask(struct tda10086_state *state, int reg, int mask,
 static int tda10086_init(struct dvb_frontend* fe)
 {
        struct tda10086_state* state = fe->demodulator_priv;
+       u8 t22k_off = 0x80;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
+       if (state->config->diseqc_tone)
+               t22k_off = 0;
        // reset
        tda10086_write_byte(state, 0x00, 0x00);
        msleep(10);
@@ -125,10 +128,15 @@ static int tda10086_init(struct dvb_frontend* fe)
        tda10086_write_byte(state, 0x32, 0x00); // irq off
        tda10086_write_byte(state, 0x31, 0x56); // setup AFC
 
-       // setup PLL (assumes 16Mhz XIN)
+       // setup PLL (this assumes SACLK = 96MHz)
        tda10086_write_byte(state, 0x55, 0x2c); // misc PLL setup
-       tda10086_write_byte(state, 0x3a, 0x0b); // M=12
-       tda10086_write_byte(state, 0x3b, 0x01); // P=2
+       if (state->config->xtal_freq == TDA10086_XTAL_16M) {
+               tda10086_write_byte(state, 0x3a, 0x0b); // M=12
+               tda10086_write_byte(state, 0x3b, 0x01); // P=2
+       } else {
+               tda10086_write_byte(state, 0x3a, 0x17); // M=24
+               tda10086_write_byte(state, 0x3b, 0x00); // P=1
+       }
        tda10086_write_mask(state, 0x55, 0x20, 0x00); // powerup PLL
 
        // setup TS interface
@@ -158,7 +166,7 @@ static int tda10086_init(struct dvb_frontend* fe)
        tda10086_write_byte(state, 0x3d, 0x80);
 
        // setup SEC
-       tda10086_write_byte(state, 0x36, 0x80); // all SEC off, no 22k tone
+       tda10086_write_byte(state, 0x36, t22k_off); // all SEC off, 22k tone
        tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000)));      // } tone frequency
        tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8); // }
 
@@ -170,7 +178,7 @@ static void tda10086_diseqc_wait(struct tda10086_state *state)
        unsigned long timeout = jiffies + msecs_to_jiffies(200);
        while (!(tda10086_read_byte(state, 0x50) & 0x01)) {
                if(time_after(jiffies, timeout)) {
-                       printk("%s: diseqc queue not ready, command may be lost.\n", __FUNCTION__);
+                       printk("%s: diseqc queue not ready, command may be lost.\n", __func__);
                        break;
                }
                msleep(10);
@@ -180,16 +188,20 @@ static void tda10086_diseqc_wait(struct tda10086_state *state)
 static int tda10086_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
 {
        struct tda10086_state* state = fe->demodulator_priv;
+       u8 t22k_off = 0x80;
+
+       dprintk ("%s\n", __func__);
 
-       dprintk ("%s\n", __FUNCTION__);
+       if (state->config->diseqc_tone)
+               t22k_off = 0;
 
        switch (tone) {
        case SEC_TONE_OFF:
-               tda10086_write_byte(state, 0x36, 0x80);
+               tda10086_write_byte(state, 0x36, t22k_off);
                break;
 
        case SEC_TONE_ON:
-               tda10086_write_byte(state, 0x36, 0x81);
+               tda10086_write_byte(state, 0x36, 0x01 + t22k_off);
                break;
        }
 
@@ -202,8 +214,12 @@ static int tda10086_send_master_cmd (struct dvb_frontend* fe,
        struct tda10086_state* state = fe->demodulator_priv;
        int i;
        u8 oldval;
+       u8 t22k_off = 0x80;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
+
+       if (state->config->diseqc_tone)
+               t22k_off = 0;
 
        if (cmd->msg_len > 6)
                return -EINVAL;
@@ -212,7 +228,8 @@ static int tda10086_send_master_cmd (struct dvb_frontend* fe,
        for(i=0; i< cmd->msg_len; i++) {
                tda10086_write_byte(state, 0x48+i, cmd->msg[i]);
        }
-       tda10086_write_byte(state, 0x36, 0x88 | ((cmd->msg_len - 1) << 4));
+       tda10086_write_byte(state, 0x36, (0x08 + t22k_off)
+                                       | ((cmd->msg_len - 1) << 4));
 
        tda10086_diseqc_wait(state);
 
@@ -225,16 +242,20 @@ static int tda10086_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minic
 {
        struct tda10086_state* state = fe->demodulator_priv;
        u8 oldval = tda10086_read_byte(state, 0x36);
+       u8 t22k_off = 0x80;
+
+       dprintk ("%s\n", __func__);
 
-       dprintk ("%s\n", __FUNCTION__);
+       if (state->config->diseqc_tone)
+               t22k_off = 0;
 
        switch(minicmd) {
        case SEC_MINI_A:
-               tda10086_write_byte(state, 0x36, 0x84);
+               tda10086_write_byte(state, 0x36, 0x04 + t22k_off);
                break;
 
        case SEC_MINI_B:
-               tda10086_write_byte(state, 0x36, 0x86);
+               tda10086_write_byte(state, 0x36, 0x06 + t22k_off);
                break;
        }
 
@@ -250,7 +271,7 @@ static int tda10086_set_inversion(struct tda10086_state *state,
 {
        u8 invval = 0x80;
 
-       dprintk ("%s %i %i\n", __FUNCTION__, fe_params->inversion, state->config->invert);
+       dprintk ("%s %i %i\n", __func__, fe_params->inversion, state->config->invert);
 
        switch(fe_params->inversion) {
        case INVERSION_OFF:
@@ -284,7 +305,7 @@ static int tda10086_set_symbol_rate(struct tda10086_state *state,
        u32 bdri;
        u32 symbol_rate = fe_params->u.qpsk.symbol_rate;
 
-       dprintk ("%s %i\n", __FUNCTION__, symbol_rate);
+       dprintk ("%s %i\n", __func__, symbol_rate);
 
        // setup the decimation and anti-aliasing filters..
        if (symbol_rate < (u32) (SACLK * 0.0137)) {
@@ -350,7 +371,7 @@ static int tda10086_set_fec(struct tda10086_state *state,
 {
        u8 fecval;
 
-       dprintk ("%s %i\n", __FUNCTION__, fe_params->u.qpsk.fec_inner);
+       dprintk ("%s %i\n", __func__, fe_params->u.qpsk.fec_inner);
 
        switch(fe_params->u.qpsk.fec_inner) {
        case FEC_1_2:
@@ -396,7 +417,7 @@ static int tda10086_set_frontend(struct dvb_frontend* fe,
        u32 freq = 0;
        int freqoff;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        // modify parameters for tuning
        tda10086_write_byte(state, 0x02, 0x35);
@@ -443,7 +464,7 @@ static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
        int tmp;
        u64 tmp64;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        // check for invalid symbol rate
        if (fe_params->u.qpsk.symbol_rate < 500000)
@@ -534,7 +555,7 @@ static int tda10086_read_status(struct dvb_frontend* fe, fe_status_t *fe_status)
        struct tda10086_state* state = fe->demodulator_priv;
        u8 val;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        val = tda10086_read_byte(state, 0x0e);
        *fe_status = 0;
@@ -563,7 +584,7 @@ static int tda10086_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
        struct tda10086_state* state = fe->demodulator_priv;
        u8 _str;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        _str = 0xff - tda10086_read_byte(state, 0x43);
        *signal = (_str << 8) | _str;
@@ -576,7 +597,7 @@ static int tda10086_read_snr(struct dvb_frontend* fe, u16 * snr)
        struct tda10086_state* state = fe->demodulator_priv;
        u8 _snr;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        _snr = 0xff - tda10086_read_byte(state, 0x1c);
        *snr = (_snr << 8) | _snr;
@@ -588,7 +609,7 @@ static int tda10086_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
 {
        struct tda10086_state* state = fe->demodulator_priv;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        // read it
        *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f;
@@ -604,7 +625,7 @@ static int tda10086_read_ber(struct dvb_frontend* fe, u32* ber)
 {
        struct tda10086_state* state = fe->demodulator_priv;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        // read it
        *ber = 0;
@@ -619,7 +640,7 @@ static int tda10086_sleep(struct dvb_frontend* fe)
 {
        struct tda10086_state* state = fe->demodulator_priv;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        tda10086_write_mask(state, 0x00, 0x08, 0x08);
 
@@ -630,7 +651,7 @@ static int tda10086_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
 {
        struct tda10086_state* state = fe->demodulator_priv;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        if (enable) {
                tda10086_write_mask(state, 0x00, 0x10, 0x10);
@@ -721,7 +742,7 @@ struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
 {
        struct tda10086_state *state;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
        /* allocate memory for the internal state */
        state = kmalloc(sizeof(struct tda10086_state), GFP_KERNEL);