Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / drivers / media / dvb / frontends / nxt200x.c
index aeafef4..55671cb 100644 (file)
@@ -1,9 +1,10 @@
 /*
  *    Support for NXT2002 and NXT2004 - VSB/QAM
  *
- *    Copyright (C) 2005 Kirk Lapray (kirk.lapray@gmail.com)
+ *    Copyright (C) 2005 Kirk Lapray <kirk.lapray@gmail.com>
+ *    Copyright (C) 2006 Michael Krufky <mkrufky@m1k.net>
  *    based on nxt2002 by Taylor Jacob <rtjacob@earthlink.net>
- *    and nxt2004 by Jean-Francois Thibert (jeanfrancois@sagetv.com)
+ *    and nxt2004 by Jean-Francois Thibert <jeanfrancois@sagetv.com>
  *
  *    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
@@ -54,7 +55,6 @@
 struct nxt200x_state {
 
        struct i2c_adapter* i2c;
-       struct dvb_frontend_ops ops;
        const struct nxt200x_config* config;
        struct dvb_frontend frontend;
 
@@ -332,17 +332,17 @@ static int nxt200x_writetuner (struct nxt200x_state* state, u8* data)
 
        dprintk("%s\n", __FUNCTION__);
 
-       dprintk("Tuner Bytes: %02X %02X %02X %02X\n", data[0], data[1], data[2], data[3]);
+       dprintk("Tuner Bytes: %02X %02X %02X %02X\n", data[1], data[2], data[3], data[4]);
 
        /* if NXT2004, write directly to tuner. if NXT2002, write through NXT chip.
         * direct write is required for Philips TUV1236D and ALPS TDHU2 */
        switch (state->demod_chip) {
                case NXT2004:
-                       if (i2c_writebytes(state, state->config->pll_address, data, 4))
+                       if (i2c_writebytes(state, data[0], data+1, 4))
                                printk(KERN_WARNING "nxt200x: error writing to tuner\n");
                        /* wait until we have a lock */
                        while (count < 20) {
-                               i2c_readbytes(state, state->config->pll_address, &buf, 1);
+                               i2c_readbytes(state, data[0], &buf, 1);
                                if (buf & 0x40)
                                        return 0;
                                msleep(100);
@@ -360,10 +360,10 @@ static int nxt200x_writetuner (struct nxt200x_state* state, u8* data)
                        nxt200x_writebytes(state, 0x34, &buf, 1);
 
                        /* write actual tuner bytes */
-                       nxt200x_writebytes(state, 0x36, data, 4);
+                       nxt200x_writebytes(state, 0x36, data+1, 4);
 
                        /* set tuner i2c address */
-                       buf = state->config->pll_address;
+                       buf = data[0] << 1;
                        nxt200x_writebytes(state, 0x35, &buf, 1);
 
                        /* write UC Opmode to begin transfer */
@@ -533,7 +533,7 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
                                             struct dvb_frontend_parameters *p)
 {
        struct nxt200x_state* state = fe->demodulator_priv;
-       u8 buf[4];
+       u8 buf[5];
 
        /* stop the micro first */
        nxt200x_microcontroller_stop(state);
@@ -547,7 +547,9 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
        }
 
        /* get tuning information */
-       dvb_pll_configure(state->config->pll_desc, buf, p->frequency, 0);
+       if (fe->ops.tuner_ops.calc_regs) {
+               fe->ops.tuner_ops.calc_regs(fe, p, buf, 5);
+       }
 
        /* set additional params */
        switch (p->u.vsb.modulation) {
@@ -614,7 +616,17 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
        /* write sdm1 input */
        buf[0] = 0x10;
        buf[1] = 0x00;
-       nxt200x_writebytes(state, 0x58, buf, 2);
+       switch (state->demod_chip) {
+               case NXT2002:
+                       nxt200x_writereg_multibyte(state, 0x58, buf, 2);
+                       break;
+               case NXT2004:
+                       nxt200x_writebytes(state, 0x58, buf, 2);
+                       break;
+               default:
+                       return -EINVAL;
+                       break;
+       }
 
        /* write sdmx input */
        switch (p->u.vsb.modulation) {
@@ -632,7 +644,17 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
                                break;
        }
        buf[1] = 0x00;
-       nxt200x_writebytes(state, 0x5C, buf, 2);
+       switch (state->demod_chip) {
+               case NXT2002:
+                       nxt200x_writereg_multibyte(state, 0x5C, buf, 2);
+                       break;
+               case NXT2004:
+                       nxt200x_writebytes(state, 0x5C, buf, 2);
+                       break;
+               default:
+                       return -EINVAL;
+                       break;
+       }
 
        /* write adc power lpf fc */
        buf[0] = 0x05;
@@ -648,7 +670,17 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
        /* write accumulator2 input */
        buf[0] = 0x80;
        buf[1] = 0x00;
-       nxt200x_writebytes(state, 0x4B, buf, 2);
+       switch (state->demod_chip) {
+               case NXT2002:
+                       nxt200x_writereg_multibyte(state, 0x4B, buf, 2);
+                       break;
+               case NXT2004:
+                       nxt200x_writebytes(state, 0x4B, buf, 2);
+                       break;
+               default:
+                       return -EINVAL;
+                       break;
+       }
 
        /* write kg1 */
        buf[0] = 0x00;
@@ -714,8 +746,19 @@ static int nxt200x_setup_frontend_parameters (struct dvb_frontend* fe,
        /* write accumulator2 input */
        buf[0] = 0x80;
        buf[1] = 0x00;
-       nxt200x_writebytes(state, 0x49, buf,2);
-       nxt200x_writebytes(state, 0x4B, buf,2);
+       switch (state->demod_chip) {
+               case NXT2002:
+                       nxt200x_writereg_multibyte(state, 0x49, buf, 2);
+                       nxt200x_writereg_multibyte(state, 0x4B, buf, 2);
+                       break;
+               case NXT2004:
+                       nxt200x_writebytes(state, 0x49, buf, 2);
+                       nxt200x_writebytes(state, 0x4B, buf, 2);
+                       break;
+               default:
+                       return -EINVAL;
+                       break;
+       }
 
        /* write agc control reg */
        buf[0] = 0x04;
@@ -1110,15 +1153,13 @@ struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
        u8 buf [] = {0,0,0,0,0};
 
        /* allocate memory for the internal state */
-       state = (struct nxt200x_state*) kmalloc(sizeof(struct nxt200x_state), GFP_KERNEL);
+       state = kzalloc(sizeof(struct nxt200x_state), GFP_KERNEL);
        if (state == NULL)
                goto error;
-       memset(state,0,sizeof(*state));
 
        /* setup the state */
        state->config = config;
        state->i2c = i2c;
-       memcpy(&state->ops, &nxt200x_ops, sizeof(struct dvb_frontend_ops));
        state->initialised = 0;
 
        /* read card id */
@@ -1157,7 +1198,7 @@ struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
        }
 
        /* create dvb_frontend */
-       state->frontend.ops = &state->ops;
+       memcpy(&state->frontend.ops, &nxt200x_ops, sizeof(struct dvb_frontend_ops));
        state->frontend.demodulator_priv = state;
        return &state->frontend;
 
@@ -1200,7 +1241,7 @@ module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
 
 MODULE_DESCRIPTION("NXT200X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
-MODULE_AUTHOR("Kirk Lapray, Jean-Francois Thibert, and Taylor Jacob");
+MODULE_AUTHOR("Kirk Lapray, Michael Krufky, Jean-Francois Thibert, and Taylor Jacob");
 MODULE_LICENSE("GPL");
 
 EXPORT_SYMBOL(nxt200x_attach);