]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/dvb/frontends/sp8870.c
V4L/DVB (7594): em28xx: Fix Kconfig
[linux-2.6-omap-h63xx.git] / drivers / media / dvb / frontends / sp8870.c
index 73829e647e50ad0cccb0e2f8cf6f8b18ada520ff..aa78aa14aad927564108b19afa05a74efdabd646 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 #include <linux/device.h>
 #include <linux/firmware.h>
 #include <linux/delay.h>
@@ -44,8 +43,6 @@ struct sp8870_state {
 
        struct i2c_adapter* i2c;
 
-       struct dvb_frontend_ops ops;
-
        const struct sp8870_config* config;
 
        struct dvb_frontend frontend;
@@ -73,7 +70,7 @@ static int sp8870_writereg (struct sp8870_state* state, u16 reg, u16 data)
        int err;
 
        if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
-               dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data);
+               dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__, err, reg, data);
                return -EREMOTEIO;
        }
 
@@ -91,7 +88,7 @@ static int sp8870_readreg (struct sp8870_state* state, u16 reg)
        ret = i2c_transfer (state->i2c, msg, 2);
 
        if (ret != 2) {
-               dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret);
+               dprintk("%s: readreg error (ret == %i)\n", __func__, ret);
                return -1;
        }
 
@@ -107,7 +104,7 @@ static int sp8870_firmware_upload (struct sp8870_state* state, const struct firm
        int tx_len;
        int err = 0;
 
-       dprintk ("%s: ...\n", __FUNCTION__);
+       dprintk ("%s: ...\n", __func__);
 
        if (fw->size < SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET)
                return -EINVAL;
@@ -134,14 +131,14 @@ static int sp8870_firmware_upload (struct sp8870_state* state, const struct firm
                msg.buf = tx_buf;
                msg.len = tx_len + 2;
                if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
-                       printk("%s: firmware upload failed!\n", __FUNCTION__);
-                       printk ("%s: i2c error (err == %i)\n", __FUNCTION__, err);
+                       printk("%s: firmware upload failed!\n", __func__);
+                       printk ("%s: i2c error (err == %i)\n", __func__, err);
                        return err;
                }
                fw_pos += tx_len;
        }
 
-       dprintk ("%s: done!\n", __FUNCTION__);
+       dprintk ("%s: done!\n", __func__);
        return 0;
 };
 
@@ -262,9 +259,10 @@ static int sp8870_set_frontend_parameters (struct dvb_frontend* fe,
        sp8870_microcontroller_stop(state);
 
        // set tuner parameters
-       sp8870_writereg(state, 0x206, 0x001);
-       state->config->pll_set(fe, p);
-       sp8870_writereg(state, 0x206, 0x000);
+       if (fe->ops.tuner_ops.set_params) {
+               fe->ops.tuner_ops.set_params(fe, p);
+               if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
+       }
 
        // sample rate correction bit [23..17]
        sp8870_writereg(state, 0x0319, 0x000A);
@@ -312,14 +310,13 @@ static int sp8870_init (struct dvb_frontend* fe)
        if (state->initialised) return 0;
        state->initialised = 1;
 
-       dprintk ("%s\n", __FUNCTION__);
+       dprintk ("%s\n", __func__);
 
 
        /* request the firmware, this will block until someone uploads it */
        printk("sp8870: waiting for firmware upload (%s)...\n", SP8870_DEFAULT_FIRMWARE);
        if (state->config->request_firmware(fe, &fw, SP8870_DEFAULT_FIRMWARE)) {
                printk("sp8870: no firmware upload (timeout or file not found?)\n");
-               release_firmware(fw);
                return -EIO;
        }
 
@@ -328,6 +325,7 @@ static int sp8870_init (struct dvb_frontend* fe)
                release_firmware(fw);
                return -EIO;
        }
+       release_firmware(fw);
        printk("sp8870: firmware upload complete\n");
 
        /* enable TS output and interface pins */
@@ -349,13 +347,6 @@ static int sp8870_init (struct dvb_frontend* fe)
        sp8870_writereg(state, 0x0D00, 0x010);
        sp8870_writereg(state, 0x0D01, 0x000);
 
-       /* setup PLL */
-       if (state->config->pll_init) {
-               sp8870_writereg(state, 0x206, 0x001);
-               state->config->pll_init(fe);
-               sp8870_writereg(state, 0x206, 0x000);
-       }
-
        return 0;
 }
 
@@ -458,15 +449,15 @@ static int sp8870_read_uncorrected_blocks (struct dvb_frontend* fe, u32* ublocks
        return 0;
 }
 
-// number of trials to recover from lockup
+/* number of trials to recover from lockup */
 #define MAXTRIALS 5
-// maximum checks for data valid signal
+/* maximum checks for data valid signal */
 #define MAXCHECKS 100
 
-// only for debugging: counter for detected lockups
-static int lockups = 0;
-// only for debugging: counter for channel switches
-static int switches = 0;
+/* only for debugging: counter for detected lockups */
+static int lockups;
+/* only for debugging: counter for channel switches */
+static int switches;
 
 static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
 {
@@ -484,7 +475,7 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
        int trials = 0;
        int check_count = 0;
 
-       dprintk("%s: frequency = %i\n", __FUNCTION__, p->frequency);
+       dprintk("%s: frequency = %i\n", __func__, p->frequency);
 
        for (trials = 1; trials <= MAXTRIALS; trials++) {
 
@@ -496,7 +487,7 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
                        valid = sp8870_read_data_valid_signal(state);
                        if (valid) {
                                dprintk("%s: delay = %i usec\n",
-                                       __FUNCTION__, check_count * 10);
+                                       __func__, check_count * 10);
                                break;
                        }
                        udelay(10);
@@ -506,20 +497,20 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
        }
 
        if (!valid) {
-               printk("%s: firmware crash!!!!!!\n", __FUNCTION__);
+               printk("%s: firmware crash!!!!!!\n", __func__);
                return -EIO;
        }
 
        if (debug) {
                if (valid) {
                        if (trials > 1) {
-                               printk("%s: firmware lockup!!!\n", __FUNCTION__);
-                               printk("%s: recovered after %i trial(s))\n",  __FUNCTION__, trials - 1);
+                               printk("%s: firmware lockup!!!\n", __func__);
+                               printk("%s: recovered after %i trial(s))\n",  __func__, trials - 1);
                                lockups++;
                        }
                }
                switches++;
-               printk("%s: switches = %i lockups = %i\n", __FUNCTION__, switches, lockups);
+               printk("%s: switches = %i lockups = %i\n", __func__, switches, lockups);
        }
 
        return 0;
@@ -541,6 +532,17 @@ static int sp8870_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend
        return 0;
 }
 
+static int sp8870_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
+{
+       struct sp8870_state* state = fe->demodulator_priv;
+
+       if (enable) {
+               return sp8870_writereg(state, 0x206, 0x001);
+       } else {
+               return sp8870_writereg(state, 0x206, 0x000);
+       }
+}
+
 static void sp8870_release(struct dvb_frontend* fe)
 {
        struct sp8870_state* state = fe->demodulator_priv;
@@ -561,14 +563,13 @@ struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
        /* setup the state */
        state->config = config;
        state->i2c = i2c;
-       memcpy(&state->ops, &sp8870_ops, sizeof(struct dvb_frontend_ops));
        state->initialised = 0;
 
        /* check if the demod is there */
        if (sp8870_readreg(state, 0x0200) < 0) goto error;
 
        /* create dvb_frontend */
-       state->frontend.ops = &state->ops;
+       memcpy(&state->frontend.ops, &sp8870_ops, sizeof(struct dvb_frontend_ops));
        state->frontend.demodulator_priv = state;
        return &state->frontend;
 
@@ -597,6 +598,7 @@ static struct dvb_frontend_ops sp8870_ops = {
 
        .init = sp8870_init,
        .sleep = sp8870_sleep,
+       .i2c_gate_ctrl = sp8870_i2c_gate_ctrl,
 
        .set_frontend = sp8870_set_frontend,
        .get_tune_settings = sp8870_get_tune_settings,