提交 3421b778 编写于 作者: A Aidan Thornton 提交者: Mauro Carvalho Chehab

V4L/DVB (7603): em28xx-dvb: don't use videobuf-dvb

Modifies em28xx-dvb not to use videobuf-dvb, but instead to include the code
for registering dvb devices locally and use the URB management code in the
em28xx driver directly. DVB data streaming should now work.
Signed-off-by: NAidan Thornton <makosoft@googlemail.com>
Signed-off-by: NMauro Carvalho Chehab <mchehab@infradead.org>
上级 579f72e4
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
(c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com> (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
- Fixes for the driver to properly work with HVR-950 - Fixes for the driver to properly work with HVR-950
Based on cx88-dvb and saa7134-dvb originally written by: (c) 2008 Aidan Thornton <makosoft@googlemail.com>
Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
(c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
(c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
...@@ -37,28 +39,157 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); ...@@ -37,28 +39,157 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
#define dprintk(level, fmt, arg...) do { \ #define dprintk(level, fmt, arg...) do { \
if (debug >= level) \ if (debug >= level) \
printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg) \ printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
} while (0) } while (0)
static int #define EM28XX_DVB_NUM_BUFS 5
buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) #define EM28XX_DVB_MAX_PACKETSIZE 564
#define EM28XX_DVB_MAX_PACKETS 64
struct em28xx_dvb {
struct dvb_frontend *frontend;
/* feed count management */
struct mutex lock;
int nfeeds;
/* general boilerplate stuff */
struct dvb_adapter adapter;
struct dvb_demux demux;
struct dmxdev dmxdev;
struct dmx_frontend fe_hw;
struct dmx_frontend fe_mem;
struct dvb_net net;
};
static inline void print_err_status(struct em28xx *dev,
int packet, int status)
{ {
struct em28xx_fh *fh = vq->priv_data; char *errmsg = "Unknown";
struct em28xx *dev = fh->dev;
/* FIXME: The better would be to allocate a smaller buffer */ switch (status) {
*size = 16 * fh->dev->width * fh->dev->height >> 3; case -ENOENT:
if (0 == *count) errmsg = "unlinked synchronuously";
*count = EM28XX_DEF_BUF; break;
case -ECONNRESET:
errmsg = "unlinked asynchronuously";
break;
case -ENOSR:
errmsg = "Buffer error (overrun)";
break;
case -EPIPE:
errmsg = "Stalled (device not responding)";
break;
case -EOVERFLOW:
errmsg = "Babble (bad cable?)";
break;
case -EPROTO:
errmsg = "Bit-stuff error (bad cable?)";
break;
case -EILSEQ:
errmsg = "CRC/Timeout (could be anything)";
break;
case -ETIME:
errmsg = "Device does not respond";
break;
}
if (packet < 0) {
dprintk(1, "URB status %d [%s].\n", status, errmsg);
} else {
dprintk(1, "URB packet %d, status %d [%s].\n", packet, status, errmsg);
}
}
if (*count < EM28XX_MIN_BUF) static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
*count = EM28XX_MIN_BUF; {
int i;
dev->mode = EM28XX_DIGITAL_MODE; if (!dev)
return 0;
if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
return 0;
if (urb->status < 0) {
print_err_status(dev, -1, urb->status);
if (urb->status == -ENOENT)
return 0;
}
for (i = 0; i < urb->number_of_packets; i++) {
int status = urb->iso_frame_desc[i].status;
if (status < 0) {
print_err_status(dev, i, status);
if (urb->iso_frame_desc[i].status != -EPROTO)
continue;
}
dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
urb->iso_frame_desc[i].offset,
urb->iso_frame_desc[i].actual_length);
}
return 0;
}
static int start_streaming(struct em28xx_dvb* dvb) {
struct em28xx *dev = dvb->adapter.priv;
usb_set_interface(dev->udev, 0, 1);
dev->em28xx_write_regs_req(dev,0x00,0x48,"\x00",1);
return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
EM28XX_DVB_NUM_BUFS, EM28XX_DVB_MAX_PACKETSIZE,
dvb_isoc_copy, EM28XX_DIGITAL_CAPTURE);
}
static int stop_streaming(struct em28xx_dvb* dvb) {
struct em28xx *dev = dvb->adapter.priv;
em28xx_uninit_isoc(dev);
return 0; return 0;
} }
static int start_feed(struct dvb_demux_feed *feed)
{
struct dvb_demux *demux = feed->demux;
struct em28xx_dvb *dvb = demux->priv;
int rc, ret;
if (!demux->dmx.frontend)
return -EINVAL;
mutex_lock(&dvb->lock);
dvb->nfeeds++;
rc = dvb->nfeeds;
if (dvb->nfeeds == 1) {
ret = start_streaming(dvb);
if(ret < 0) rc = ret;
}
mutex_unlock(&dvb->lock);
return rc;
}
static int stop_feed(struct dvb_demux_feed *feed)
{
struct dvb_demux *demux = feed->demux;
struct em28xx_dvb *dvb = demux->priv;
int err = 0;
mutex_lock(&dvb->lock);
dvb->nfeeds--;
if (0 == dvb->nfeeds) {
err = stop_streaming(dvb);
}
mutex_unlock(&dvb->lock);
return err;
}
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
static struct lgdt330x_config em2880_lgdt3303_dev = { static struct lgdt330x_config em2880_lgdt3303_dev = {
...@@ -89,20 +220,20 @@ static int attach_xc3028(u8 addr, struct em28xx *dev) ...@@ -89,20 +220,20 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
em28xx_setup_xc3028(dev, &ctl); em28xx_setup_xc3028(dev, &ctl);
if (!dev->dvb.frontend) { if (!dev->dvb->frontend) {
printk(KERN_ERR "%s/2: dvb frontend not attached. " printk(KERN_ERR "%s/2: dvb frontend not attached. "
"Can't attach xc3028\n", "Can't attach xc3028\n",
dev->name); dev->name);
return -EINVAL; return -EINVAL;
} }
fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg); fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg);
if (!fe) { if (!fe) {
printk(KERN_ERR "%s/2: xc3028 attach failed\n", printk(KERN_ERR "%s/2: xc3028 attach failed\n",
dev->name); dev->name);
dvb_frontend_detach(dev->dvb.frontend); dvb_frontend_detach(dev->dvb->frontend);
dvb_unregister_frontend(dev->dvb.frontend); dvb_unregister_frontend(dev->dvb->frontend);
dev->dvb.frontend = NULL; dev->dvb->frontend = NULL;
return -EINVAL; return -EINVAL;
} }
...@@ -111,23 +242,129 @@ static int attach_xc3028(u8 addr, struct em28xx *dev) ...@@ -111,23 +242,129 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
return 0; return 0;
} }
static int dvb_init(struct em28xx *dev) /* ------------------------------------------------------------------ */
int register_dvb(struct em28xx_dvb *dvb,
struct module *module,
struct em28xx *dev,
struct device *device)
{ {
/* init struct videobuf_dvb */ int result;
dev->dvb.name = dev->name;
dev->qops->buf_setup = buffer_setup; mutex_init(&dvb->lock);
/* FIXME: Do we need more initialization here? */ /* register adapter */
memset(&dev->dvb_fh, 0, sizeof (dev->dvb_fh)); result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
dev->dvb_fh.dev = dev; adapter_nr);
dev->dvb_fh.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (result < 0) {
printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
dev->name, result);
goto fail_adapter;
}
dvb->adapter.priv = dev;
/* register frontend */
result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
if (result < 0) {
printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
dev->name, result);
goto fail_frontend;
}
/* register demux stuff */
dvb->demux.dmx.capabilities =
DMX_TS_FILTERING | DMX_SECTION_FILTERING |
DMX_MEMORY_BASED_FILTERING;
dvb->demux.priv = dvb;
dvb->demux.filternum = 256;
dvb->demux.feednum = 256;
dvb->demux.start_feed = start_feed;
dvb->demux.stop_feed = stop_feed;
result = dvb_dmx_init(&dvb->demux);
if (result < 0) {
printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
dev->name, result);
goto fail_dmx;
}
dvb->dmxdev.filternum = 256;
dvb->dmxdev.demux = &dvb->demux.dmx;
dvb->dmxdev.capabilities = 0;
result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
if (result < 0) {
printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
dev->name, result);
goto fail_dmxdev;
}
videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops, dvb->fe_hw.source = DMX_FRONTEND_0;
&dev->udev->dev, &dev->slock, result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
V4L2_BUF_TYPE_VIDEO_CAPTURE, if (result < 0) {
V4L2_FIELD_ALTERNATE, printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
sizeof(struct em28xx_buffer), &dev->dvb_fh); dev->name, result);
goto fail_fe_hw;
}
dvb->fe_mem.source = DMX_MEMORY_FE;
result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
if (result < 0) {
printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
dev->name, result);
goto fail_fe_mem;
}
result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
if (result < 0) {
printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
dev->name, result);
goto fail_fe_conn;
}
/* register network adapter */
dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
return 0;
fail_fe_conn:
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
fail_fe_mem:
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
fail_fe_hw:
dvb_dmxdev_release(&dvb->dmxdev);
fail_dmxdev:
dvb_dmx_release(&dvb->demux);
fail_dmx:
dvb_unregister_frontend(dvb->frontend);
fail_frontend:
dvb_frontend_detach(dvb->frontend);
dvb_unregister_adapter(&dvb->adapter);
fail_adapter:
return result;
}
static void unregister_dvb(struct em28xx_dvb *dvb)
{
dvb_net_release(&dvb->net);
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
dvb_dmxdev_release(&dvb->dmxdev);
dvb_dmx_release(&dvb->demux);
dvb_unregister_frontend(dvb->frontend);
dvb_frontend_detach(dvb->frontend);
dvb_unregister_adapter(&dvb->adapter);
}
static int dvb_init(struct em28xx *dev)
{
int result = 0;
struct em28xx_dvb *dvb;
dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
if(dvb == NULL) {
printk("em28xx_dvb: memory allocation failed\n");
return -ENOMEM;
}
dev->dvb = dvb;
/* init frontend */ /* init frontend */
switch (dev->model) { switch (dev->model) {
...@@ -136,21 +373,25 @@ static int dvb_init(struct em28xx *dev) ...@@ -136,21 +373,25 @@ static int dvb_init(struct em28xx *dev)
dev->mode = EM28XX_DIGITAL_MODE; dev->mode = EM28XX_DIGITAL_MODE;
em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0); em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
dev->dvb.frontend = dvb_attach(lgdt330x_attach, dvb->frontend = dvb_attach(lgdt330x_attach,
&em2880_lgdt3303_dev, &em2880_lgdt3303_dev,
&dev->i2c_adap); &dev->i2c_adap);
if (attach_xc3028(0x61, dev) < 0) if (attach_xc3028(0x61, dev) < 0) {
return -EINVAL; result = -EINVAL;
goto out_free;
}
break; break;
case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
/* Enable zl10353 */ /* Enable zl10353 */
dev->mode = EM28XX_DIGITAL_MODE; dev->mode = EM28XX_DIGITAL_MODE;
em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0); em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
dev->dvb.frontend = dvb_attach(zl10353_attach, dvb->frontend = dvb_attach(zl10353_attach,
&em28xx_zl10353_with_xc3028, &em28xx_zl10353_with_xc3028,
&dev->i2c_adap); &dev->i2c_adap);
if (attach_xc3028(0x61, dev) < 0) if (attach_xc3028(0x61, dev) < 0) {
return -EINVAL; result = -EINVAL;
goto out_free;
}
break; break;
default: default:
printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
...@@ -158,23 +399,35 @@ static int dvb_init(struct em28xx *dev) ...@@ -158,23 +399,35 @@ static int dvb_init(struct em28xx *dev)
dev->name); dev->name);
break; break;
} }
if (NULL == dev->dvb.frontend) { if (NULL == dvb->frontend) {
printk(KERN_ERR printk(KERN_ERR
"%s/2: frontend initialization failed\n", "%s/2: frontend initialization failed\n",
dev->name); dev->name);
return -EINVAL; result = -EINVAL;
goto out_free;
} }
/* register everything */ /* register everything */
return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
&dev->udev->dev,
adapter_nr); if (result < 0) {
goto out_free;
}
return 0;
out_free:
kfree(dvb);
dev->dvb = NULL;
return result;
} }
static int dvb_fini(struct em28xx *dev) static int dvb_fini(struct em28xx *dev)
{ {
if (dev->dvb.frontend) if (dev->dvb) {
videobuf_dvb_unregister(&dev->dvb); unregister_dvb(dev->dvb);
dev->dvb = NULL;
}
return 0; return 0;
} }
......
...@@ -2190,11 +2190,6 @@ static int em28xx_usb_probe(struct usb_interface *interface, ...@@ -2190,11 +2190,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
/* save our data pointer in this interface device */ /* save our data pointer in this interface device */
usb_set_intfdata(interface, dev); 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); request_modules(dev);
return 0; return 0;
......
...@@ -422,11 +422,7 @@ struct em28xx { ...@@ -422,11 +422,7 @@ struct em28xx {
enum em28xx_mode mode; enum em28xx_mode mode;
#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE) struct em28xx_dvb *dvb;
struct videobuf_dvb dvb;
struct videobuf_queue_ops *qops;
struct em28xx_fh dvb_fh;
#endif
}; };
struct em28xx_ops { struct em28xx_ops {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册