V4L/DVB (7593): em28xx: add a module to handle dvb
authorMauro Carvalho Chehab <mchehab@infradead.org>
Fri, 18 Apr 2008 00:36:41 +0000 (21:36 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Thu, 24 Apr 2008 17:09:40 +0000 (14:09 -0300)
This patch adds em28xx-dvb. This driver is highly based on cx88-dvb and
saa7134-dvb.

This code currently loads and unloads successfully. However, some
changes are needed to properly support the mpeg streams and to setup
em28xx to work on DVB mode.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/video/em28xx/Kconfig
drivers/media/video/em28xx/Makefile
drivers/media/video/em28xx/em28xx-cards.c
drivers/media/video/em28xx/em28xx-dvb.c [new file with mode: 0644]
drivers/media/video/em28xx/em28xx-video.c
drivers/media/video/em28xx/em28xx.h

index 0f7a0bd86ff4e87a0485f90f162f876a1f2f1202..11a2759ecbc92c3bcae8e22cad1610ce4d612d09 100644 (file)
@@ -27,3 +27,11 @@ config VIDEO_EM28XX_ALSA
          To compile this driver as a module, choose M here: the
          module will be called em28xx-alsa
 
+config VIDEO_EM28XX_DVB
+       tristate "DVB/ATSC Support for em28xx based TV cards"
+       depends on VIDEO_EM28XX && DVB_CORE
+       select VIDEOBUF_DVB
+       select FW_LOADER
+       ---help---
+         This adds support for DVB cards based on the
+         Empiatech em28xx chips.
index 0924550992d0e4f37781bf66b5166ef30ce9a8de..3d1c3cc337fe65c7407d728afab04990bdcd4e98 100644 (file)
@@ -5,6 +5,7 @@ em28xx-alsa-objs := em28xx-audio.o
 
 obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
 obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o
+obj-$(CONFIG_VIDEO_EM28XX_DVB) += em28xx-dvb.o
 
 EXTRA_CFLAGS += -Idrivers/media/video
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
index 94aed008f83b25e1457055bbb898cc68159ab687..bbd75bd3ff1af9aa76a5094884a5ba0095d1fa4c 100644 (file)
@@ -52,26 +52,6 @@ struct em28xx_hash_table {
        unsigned int  tuner;
 };
 
-/* Boards supported by driver */
-
-#define EM2800_BOARD_UNKNOWN                   0
-#define EM2820_BOARD_UNKNOWN                   1
-#define EM2820_BOARD_TERRATEC_CINERGY_250      2
-#define EM2820_BOARD_PINNACLE_USB_2            3
-#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2      4
-#define EM2820_BOARD_MSI_VOX_USB_2              5
-#define EM2800_BOARD_TERRATEC_CINERGY_200       6
-#define EM2800_BOARD_LEADTEK_WINFAST_USBII      7
-#define EM2800_BOARD_KWORLD_USB2800             8
-#define EM2820_BOARD_PINNACLE_DVC_90           9
-#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900   10
-#define EM2880_BOARD_TERRATEC_HYBRID_XS                11
-#define EM2820_BOARD_KWORLD_PVRTV2800RF                12
-#define EM2880_BOARD_TERRATEC_PRODIGY_XS       13
-#define EM2820_BOARD_PROLINK_PLAYTV_USB2       14
-#define EM2800_BOARD_VGEAR_POCKETTV             15
-#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950   16
-
 struct em28xx_board em28xx_boards[] = {
        [EM2800_BOARD_UNKNOWN] = {
                .name         = "Unknown EM2800 video grabber",
@@ -665,6 +645,7 @@ static void em28xx_set_model(struct em28xx *dev)
        dev->analog_gpio = em28xx_boards[dev->model].analog_gpio;
        dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
        dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
+       dev->has_dvb = em28xx_boards[dev->model].has_dvb;
 }
 
 /* ----------------------------------------------------------------------- */
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
new file mode 100644 (file)
index 0000000..1ffe64f
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ DVB device driver for em28xx
+
+ (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+ Based on cx88-dvb and saa7134-dvb originally written by:
+       (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
+       (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
+
+ 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/usb.h>
+
+#include "em28xx.h"
+#include <media/v4l2-common.h>
+#include <media/videobuf-vmalloc.h>
+
+#include "lgdt330x.h"
+#include "tuner-xc2028.h"
+#include "tuner-xc2028-types.h"
+
+MODULE_DESCRIPTION("driver for em28xx based DVB cards");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
+MODULE_LICENSE("GPL");
+
+static unsigned int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+#define dprintk(level, fmt, arg...) do {                       \
+if (debug >= level)                                            \
+       printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg)  \
+} while (0)
+
+static int
+buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
+{
+       struct em28xx_fh *fh = vq->priv_data;
+       struct em28xx        *dev = fh->dev;
+
+       *size = 16 * fh->dev->width * fh->dev->height >> 3;
+       if (0 == *count)
+               *count = EM28XX_DEF_BUF;
+
+       if (*count < EM28XX_MIN_BUF)
+               *count = EM28XX_MIN_BUF;
+
+       dev->mode = EM28XX_DIGITAL_MODE;
+
+       return 0;
+}
+
+/* ------------------------------------------------------------------ */
+
+/* Add demods here */
+
+/* ------------------------------------------------------------------ */
+
+static int attach_xc3028(u8 addr, struct em28xx *dev)
+{
+       struct dvb_frontend *fe;
+       struct xc2028_ctrl ctl;
+       struct xc2028_config cfg = {
+               .i2c_adap  = &dev->i2c_adap,
+               .i2c_addr  = addr,
+               .ctrl      = &ctl,
+       };
+
+       if (!dev->dvb.frontend) {
+               printk(KERN_ERR "%s/2: dvb frontend not attached. "
+                               "Can't attach xc3028\n",
+                      dev->name);
+               return -EINVAL;
+       }
+
+       fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
+       if (!fe) {
+               printk(KERN_ERR "%s/2: xc3028 attach failed\n",
+                      dev->name);
+               dvb_frontend_detach(dev->dvb.frontend);
+               dvb_unregister_frontend(dev->dvb.frontend);
+               dev->dvb.frontend = NULL;
+               return -EINVAL;
+       }
+
+       printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
+
+       return 0;
+}
+
+static int dvb_init(struct em28xx *dev)
+{
+       /* init struct videobuf_dvb */
+       dev->dvb.name = dev->name;
+
+       dev->qops->buf_setup = buffer_setup;
+
+       videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops,
+                       &dev->udev->dev, &dev->slock,
+                       V4L2_BUF_TYPE_VIDEO_CAPTURE,
+                       V4L2_FIELD_ALTERNATE,
+                       sizeof(struct em28xx_buffer), dev);
+
+       /* init frontend */
+       switch (dev->model) {
+       default:
+               printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
+                               " isn't supported yet\n",
+                      dev->name);
+               break;
+       }
+       if (NULL == dev->dvb.frontend) {
+               printk(KERN_ERR
+                      "%s/2: frontend initialization failed\n",
+                      dev->name);
+               return -EINVAL;
+       }
+
+       /* register everything */
+       return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
+                                    &dev->udev->dev,
+                                    adapter_nr);
+}
+
+static int dvb_fini(struct em28xx *dev)
+{
+       if (dev->dvb.frontend)
+               videobuf_dvb_unregister(&dev->dvb);
+
+       return 0;
+}
+
+static struct em28xx_ops dvb_ops = {
+       .id   = EM28XX_DVB,
+       .name = "Em28xx dvb Extension",
+       .init = dvb_init,
+       .fini = dvb_fini,
+};
+
+static int __init em28xx_dvb_register(void)
+{
+       return em28xx_register_extension(&dvb_ops);
+}
+
+static void __exit em28xx_dvb_unregister(void)
+{
+       em28xx_unregister_extension(&dvb_ops);
+}
+
+module_init(em28xx_dvb_register);
+module_exit(em28xx_dvb_unregister);
index 6084f8452b2beaa6dd604c3f6c7967e8f4f68e30..362251838d4b0f7f4a76f44fc139f9759f5f3162 100644 (file)
@@ -63,10 +63,6 @@ MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
                printk(KERN_INFO "%s %s :"fmt, \
                         dev->name, __func__ , ##arg); } while (0)
 
-/* Limits minimum and default number of buffers */
-#define EM28XX_MIN_BUF 4
-#define EM28XX_DEF_BUF 8
-
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
@@ -2237,6 +2233,9 @@ static void request_module_async(struct work_struct *work)
                request_module("snd-usb-audio");
        else
                request_module("em28xx-alsa");
+
+       if (dev->has_dvb)
+               request_module("em28xx-dvb");
 }
 
 static void request_modules(struct em28xx *dev)
@@ -2368,6 +2367,11 @@ static int em28xx_usb_probe(struct usb_interface *interface,
        /* save our data pointer in this interface device */
        usb_set_intfdata(interface, dev);
 
+#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
+       dev->qops = kmalloc(sizeof(em28xx_video_qops), GFP_KERNEL);
+       memcpy(dev->qops, &em28xx_video_qops, sizeof(em28xx_video_qops));
+#endif
+
        request_modules(dev);
 
        return 0;
index 0080a09860d92af08ec553e71dd18df1d4af7067..96a56faeb77bd29732511778fd094547cef1c5af 100644 (file)
 #include <linux/i2c.h>
 #include <linux/mutex.h>
 #include <media/ir-kbd-i2c.h>
+#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
+#include <media/videobuf-dvb.h>
+#endif
+
+/* Boards supported by driver */
+#define EM2800_BOARD_UNKNOWN                   0
+#define EM2820_BOARD_UNKNOWN                   1
+#define EM2820_BOARD_TERRATEC_CINERGY_250      2
+#define EM2820_BOARD_PINNACLE_USB_2            3
+#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2      4
+#define EM2820_BOARD_MSI_VOX_USB_2              5
+#define EM2800_BOARD_TERRATEC_CINERGY_200       6
+#define EM2800_BOARD_LEADTEK_WINFAST_USBII      7
+#define EM2800_BOARD_KWORLD_USB2800             8
+#define EM2820_BOARD_PINNACLE_DVC_90           9
+#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900   10
+#define EM2880_BOARD_TERRATEC_HYBRID_XS                11
+#define EM2820_BOARD_KWORLD_PVRTV2800RF                12
+#define EM2880_BOARD_TERRATEC_PRODIGY_XS       13
+#define EM2820_BOARD_PROLINK_PLAYTV_USB2       14
+#define EM2800_BOARD_VGEAR_POCKETTV             15
+#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950   16
+
+/* Limits minimum and default number of buffers */
+#define EM28XX_MIN_BUF 4
+#define EM28XX_DEF_BUF 8
 
 /* maximum number of em28xx boards */
 #define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */
 /* time in msecs to wait for i2c writes to finish */
 #define EM2800_I2C_WRITE_TIMEOUT 20
 
+enum em28xx_mode {
+       EM28XX_ANALOG_MODE,
+       EM28XX_DIGITAL_MODE,
+};
+
 enum em28xx_stream_state {
        STREAM_OFF,
        STREAM_INTERRUPT,
@@ -200,6 +231,7 @@ struct em28xx_board {
        unsigned int mts_firmware:1;
        unsigned int has_12mhz_i2s:1;
        unsigned int max_range_640_480:1;
+       unsigned int has_dvb:1;
 
        unsigned int analog_gpio;
 
@@ -234,7 +266,10 @@ enum em28xx_dev_state {
 #define EM28XX_NUM_AUDIO_PACKETS 64
 #define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
 #define EM28XX_CAPTURE_STREAM_EN 1
+
+/* em28xx extensions */
 #define EM28XX_AUDIO   0x10
+#define EM28XX_DVB     0x20
 
 struct em28xx_audio {
        char name[50];
@@ -266,6 +301,7 @@ struct em28xx {
        unsigned int has_audio_class:1;
        unsigned int has_12mhz_i2s:1;
        unsigned int max_range_640_480:1;
+       unsigned int has_dvb:1;
 
        int video_inputs;       /* number of video inputs */
        struct list_head        devlist;
@@ -340,6 +376,13 @@ struct em28xx {
        int (*em28xx_write_regs_req) (struct em28xx * dev, u8 req, u16 reg,
                                      char *buf, int len);
        int (*em28xx_read_reg_req) (struct em28xx * dev, u8 req, u16 reg);
+
+       enum em28xx_mode mode;
+
+#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
+       struct videobuf_dvb        dvb;
+       struct videobuf_queue_ops  *qops;
+#endif
 };
 
 struct em28xx_fh {