V4L/DVB (11327): ov772x: add edge contrl support
[safe/jmp/linux-2.6] / drivers / media / video / cx18 / cx18-dvb.c
index 65efe69..3b86f57 100644 (file)
@@ -1,7 +1,8 @@
 /*
  *  cx18 functions for DVB support
  *
- *  Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
+ *  Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
+ *  Copyright (C) 2008  Andy Walls <awalls@radix.net>
  *
  *  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
 
 #include "cx18-version.h"
 #include "cx18-dvb.h"
+#include "cx18-io.h"
 #include "cx18-streams.h"
 #include "cx18-cards.h"
 #include "s5h1409.h"
-
-/* Wait until the MXL500X driver is merged */
-#ifdef HAVE_MXL500X
-#include "mxl500x.h"
-#endif
+#include "mxl5005s.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 #define CX18_REG_DMUX_NUM_PORT_0_CONTROL 0xd5a000
 
-#ifdef HAVE_MXL500X
-static struct mxl500x_config hauppauge_hvr1600_tuner = {
-       .delsys    = MXL500x_MODE_ATSC,
-       .octf      = MXL500x_OCTF_CH,
-       .xtal_freq = 16000000,
-       .iflo_freq = 5380000,
-       .ref_freq  = 322800000,
-       .rssi_ena  = MXL_RSSI_ENABLE,
-       .addr      = 0xC6 >> 1,
+static struct mxl5005s_config hauppauge_hvr1600_tuner = {
+       .i2c_address     = 0xC6 >> 1,
+       .if_freq         = IF_FREQ_5380000HZ,
+       .xtal_freq       = CRYSTAL_FREQ_16000000HZ,
+       .agc_mode        = MXL_SINGLE_AGC,
+       .tracking_filter = MXL_TF_C_H,
+       .rssi_enable     = MXL_RSSI_ENABLE,
+       .cap_select      = MXL_CAP_SEL_ENABLE,
+       .div_out         = MXL_DIV_OUT_4,
+       .clock_out       = MXL_CLOCK_OUT_DISABLE,
+       .output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
+       .top             = MXL5005S_TOP_25P2,
+       .mod_mode        = MXL_DIGITAL_MODE,
+       .if_mode         = MXL_ZERO_IF,
+       .AgcMasterByte   = 0x00,
 };
 
 static struct s5h1409_config hauppauge_hvr1600_config = {
@@ -55,7 +59,6 @@ static struct s5h1409_config hauppauge_hvr1600_config = {
        .mpeg_timing   = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
 
 };
-#endif
 
 static int dvb_register(struct cx18_stream *stream);
 
@@ -68,21 +71,31 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
        struct dvb_demux *demux = feed->demux;
        struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
        struct cx18 *cx = stream->cx;
-       int ret = -EINVAL;
+       int ret;
        u32 v;
 
        CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
                        feed->pid, feed->index);
+
+       mutex_lock(&cx->serialize_lock);
+       ret = cx18_init_on_first_open(cx);
+       mutex_unlock(&cx->serialize_lock);
+       if (ret) {
+               CX18_ERR("Failed to initialize firmware starting DVB feed\n");
+               return ret;
+       }
+       ret = -EINVAL;
+
        switch (cx->card->type) {
        case CX18_CARD_HVR_1600_ESMT:
        case CX18_CARD_HVR_1600_SAMSUNG:
-               v = read_reg(CX18_REG_DMUX_NUM_PORT_0_CONTROL);
+               v = cx18_read_reg(cx, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
                v |= 0x00400000; /* Serial Mode */
                v |= 0x00002000; /* Data Length - Byte */
                v |= 0x00010000; /* Error - Polarity */
                v |= 0x00020000; /* Error - Passthru */
                v |= 0x000c0000; /* Error - Ignore */
-               write_reg(v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
+               cx18_write_reg(cx, v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
                break;
 
        default:
@@ -95,15 +108,23 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
        if (!demux->dmx.frontend)
                return -EINVAL;
 
-       if (stream) {
-               mutex_lock(&stream->dvb.feedlock);
-               if (stream->dvb.feeding++ == 0) {
-                       CX18_DEBUG_INFO("Starting Transport DMA\n");
-                       ret = cx18_start_v4l2_encode_stream(stream);
-               } else
-                       ret = 0;
-               mutex_unlock(&stream->dvb.feedlock);
-       }
+       if (!stream)
+               return -EINVAL;
+
+       mutex_lock(&stream->dvb.feedlock);
+       if (stream->dvb.feeding++ == 0) {
+               CX18_DEBUG_INFO("Starting Transport DMA\n");
+               set_bit(CX18_F_S_STREAMING, &stream->s_flags);
+               ret = cx18_start_v4l2_encode_stream(stream);
+               if (ret < 0) {
+                       CX18_DEBUG_INFO("Failed to start Transport DMA\n");
+                       stream->dvb.feeding--;
+                       if (stream->dvb.feeding == 0)
+                               clear_bit(CX18_F_S_STREAMING, &stream->s_flags);
+               }
+       } else
+               ret = 0;
+       mutex_unlock(&stream->dvb.feedlock);
 
        return ret;
 }
@@ -146,7 +167,7 @@ int cx18_dvb_register(struct cx18_stream *stream)
 
        ret = dvb_register_adapter(&dvb->dvb_adapter,
                        CX18_DRIVER_NAME,
-                       THIS_MODULE, &cx->dev->dev, adapter_nr);
+                       THIS_MODULE, &cx->pci_dev->dev, adapter_nr);
        if (ret < 0)
                goto err_out;
 
@@ -196,6 +217,10 @@ int cx18_dvb_register(struct cx18_stream *stream)
        dvb_net_init(dvb_adapter, &dvb->dvbnet, dmx);
 
        CX18_INFO("DVB Frontend registered\n");
+       CX18_INFO("Registered DVB adapter%d for %s (%d x %d kB)\n",
+                 stream->dvb.dvb_adapter.num, stream->name,
+                 stream->buffers, stream->buf_size/1024);
+
        mutex_init(&dvb->feedlock);
        dvb->enabled = 1;
        return ret;
@@ -252,21 +277,18 @@ static int dvb_register(struct cx18_stream *stream)
        int ret = 0;
 
        switch (cx->card->type) {
-/* Wait until the MXL500X driver is merged */
-#ifdef HAVE_MXL500X
        case CX18_CARD_HVR_1600_ESMT:
        case CX18_CARD_HVR_1600_SAMSUNG:
                dvb->fe = dvb_attach(s5h1409_attach,
                        &hauppauge_hvr1600_config,
                        &cx->i2c_adap[0]);
                if (dvb->fe != NULL) {
-                       dvb_attach(mxl500x_attach, dvb->fe,
-                               &hauppauge_hvr1600_tuner,
-                               &cx->i2c_adap[0]);
+                       dvb_attach(mxl5005s_attach, dvb->fe,
+                               &cx->i2c_adap[0],
+                               &hauppauge_hvr1600_tuner);
                        ret = 0;
                }
                break;
-#endif
        default:
                /* No Digital Tv Support */
                break;