blob: d3d52972cd84661bf6eb91a7afb458739a781942 [file] [log] [blame]
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001/*
2 DVB device driver for em28xx
3
4 (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
5
Devin Heitmuellerbdfbf952008-04-17 21:38:27 -03006 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950
8
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03009 Based on cx88-dvb and saa7134-dvb originally written by:
10 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
11 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License.
16 */
17
18#include <linux/kernel.h>
19#include <linux/usb.h>
20
21#include "em28xx.h"
22#include <media/v4l2-common.h>
23#include <media/videobuf-vmalloc.h>
24
25#include "lgdt330x.h"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030026
27MODULE_DESCRIPTION("driver for em28xx based DVB cards");
28MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
29MODULE_LICENSE("GPL");
30
31static unsigned int debug;
32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
34
35DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
36
37#define dprintk(level, fmt, arg...) do { \
38if (debug >= level) \
39 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg) \
40} while (0)
41
42static int
43buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
44{
45 struct em28xx_fh *fh = vq->priv_data;
46 struct em28xx *dev = fh->dev;
47
Mauro Carvalho Chehab52284c32008-04-17 21:38:38 -030048 /* FIXME: The better would be to allocate a smaller buffer */
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030049 *size = 16 * fh->dev->width * fh->dev->height >> 3;
50 if (0 == *count)
51 *count = EM28XX_DEF_BUF;
52
53 if (*count < EM28XX_MIN_BUF)
54 *count = EM28XX_MIN_BUF;
55
56 dev->mode = EM28XX_DIGITAL_MODE;
57
58 return 0;
59}
60
61/* ------------------------------------------------------------------ */
62
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -030063static struct lgdt330x_config em2880_lgdt3303_dev = {
64 .demod_address = 0x0e,
65 .demod_chip = LGDT3303,
66};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030067
68/* ------------------------------------------------------------------ */
69
70static int attach_xc3028(u8 addr, struct em28xx *dev)
71{
72 struct dvb_frontend *fe;
73 struct xc2028_ctrl ctl;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -030074 struct xc2028_config cfg;
75
76 memset (&cfg, 0, sizeof(cfg));
77 cfg.i2c_adap = &dev->i2c_adap;
78 cfg.i2c_addr = addr;
79 cfg.ctrl = &ctl;
80 cfg.callback = em28xx_tuner_callback;
81
82 em28xx_setup_xc3028(dev, &ctl);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030083
84 if (!dev->dvb.frontend) {
85 printk(KERN_ERR "%s/2: dvb frontend not attached. "
86 "Can't attach xc3028\n",
87 dev->name);
88 return -EINVAL;
89 }
90
91 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
92 if (!fe) {
93 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
94 dev->name);
95 dvb_frontend_detach(dev->dvb.frontend);
96 dvb_unregister_frontend(dev->dvb.frontend);
97 dev->dvb.frontend = NULL;
98 return -EINVAL;
99 }
100
101 printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
102
103 return 0;
104}
105
106static int dvb_init(struct em28xx *dev)
107{
108 /* init struct videobuf_dvb */
109 dev->dvb.name = dev->name;
110
111 dev->qops->buf_setup = buffer_setup;
112
Mauro Carvalho Chehab52284c32008-04-17 21:38:38 -0300113 /* FIXME: Do we need more initialization here? */
114 memset(&dev->dvb_fh, 0, sizeof (dev->dvb_fh));
115 dev->dvb_fh.dev = dev;
116 dev->dvb_fh.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
117
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300118 videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops,
119 &dev->udev->dev, &dev->slock,
120 V4L2_BUF_TYPE_VIDEO_CAPTURE,
121 V4L2_FIELD_ALTERNATE,
Mauro Carvalho Chehab52284c32008-04-17 21:38:38 -0300122 sizeof(struct em28xx_buffer), &dev->dvb_fh);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300123
124 /* init frontend */
125 switch (dev->model) {
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300126 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
127 /* Enable lgdt330x */
Devin Heitmuellerbdfbf952008-04-17 21:38:27 -0300128 dev->mode = EM28XX_DIGITAL_MODE;
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300129 em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
130
131 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
132 &em2880_lgdt3303_dev,
133 &dev->i2c_adap);
134 if (attach_xc3028(0x61, dev) < 0)
135 return -EINVAL;
136 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300137 default:
138 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
139 " isn't supported yet\n",
140 dev->name);
141 break;
142 }
143 if (NULL == dev->dvb.frontend) {
144 printk(KERN_ERR
145 "%s/2: frontend initialization failed\n",
146 dev->name);
147 return -EINVAL;
148 }
149
150 /* register everything */
151 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
152 &dev->udev->dev,
153 adapter_nr);
154}
155
156static int dvb_fini(struct em28xx *dev)
157{
158 if (dev->dvb.frontend)
159 videobuf_dvb_unregister(&dev->dvb);
160
161 return 0;
162}
163
164static struct em28xx_ops dvb_ops = {
165 .id = EM28XX_DVB,
166 .name = "Em28xx dvb Extension",
167 .init = dvb_init,
168 .fini = dvb_fini,
169};
170
171static int __init em28xx_dvb_register(void)
172{
173 return em28xx_register_extension(&dvb_ops);
174}
175
176static void __exit em28xx_dvb_unregister(void)
177{
178 em28xx_unregister_extension(&dvb_ops);
179}
180
181module_init(em28xx_dvb_register);
182module_exit(em28xx_dvb_unregister);