blob: 1645021191a8049c2780fa631512eac86f96d7b9 [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
6 Based on cx88-dvb and saa7134-dvb originally written by:
7 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
8 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License.
13 */
14
15#include <linux/kernel.h>
16#include <linux/usb.h>
17
18#include "em28xx.h"
19#include <media/v4l2-common.h>
20#include <media/videobuf-vmalloc.h>
21
22#include "lgdt330x.h"
23#include "tuner-xc2028.h"
24#include "tuner-xc2028-types.h"
25
26MODULE_DESCRIPTION("driver for em28xx based DVB cards");
27MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
28MODULE_LICENSE("GPL");
29
30static unsigned int debug;
31module_param(debug, int, 0644);
32MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
33
34DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
35
36#define dprintk(level, fmt, arg...) do { \
37if (debug >= level) \
38 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg) \
39} while (0)
40
41static int
42buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
43{
44 struct em28xx_fh *fh = vq->priv_data;
45 struct em28xx *dev = fh->dev;
46
47 *size = 16 * fh->dev->width * fh->dev->height >> 3;
48 if (0 == *count)
49 *count = EM28XX_DEF_BUF;
50
51 if (*count < EM28XX_MIN_BUF)
52 *count = EM28XX_MIN_BUF;
53
54 dev->mode = EM28XX_DIGITAL_MODE;
55
56 return 0;
57}
58
59/* ------------------------------------------------------------------ */
60
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -030061static struct lgdt330x_config em2880_lgdt3303_dev = {
62 .demod_address = 0x0e,
63 .demod_chip = LGDT3303,
64};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030065
66/* ------------------------------------------------------------------ */
67
68static int attach_xc3028(u8 addr, struct em28xx *dev)
69{
70 struct dvb_frontend *fe;
71 struct xc2028_ctrl ctl;
72 struct xc2028_config cfg = {
73 .i2c_adap = &dev->i2c_adap,
74 .i2c_addr = addr,
75 .ctrl = &ctl,
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -030076 .callback = em28xx_tuner_callback,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030077 };
78
79 if (!dev->dvb.frontend) {
80 printk(KERN_ERR "%s/2: dvb frontend not attached. "
81 "Can't attach xc3028\n",
82 dev->name);
83 return -EINVAL;
84 }
85
86 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
87 if (!fe) {
88 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
89 dev->name);
90 dvb_frontend_detach(dev->dvb.frontend);
91 dvb_unregister_frontend(dev->dvb.frontend);
92 dev->dvb.frontend = NULL;
93 return -EINVAL;
94 }
95
96 printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
97
98 return 0;
99}
100
101static int dvb_init(struct em28xx *dev)
102{
103 /* init struct videobuf_dvb */
104 dev->dvb.name = dev->name;
105
106 dev->qops->buf_setup = buffer_setup;
107
108 videobuf_queue_vmalloc_init(&dev->dvb.dvbq, dev->qops,
109 &dev->udev->dev, &dev->slock,
110 V4L2_BUF_TYPE_VIDEO_CAPTURE,
111 V4L2_FIELD_ALTERNATE,
112 sizeof(struct em28xx_buffer), dev);
113
114 /* init frontend */
115 switch (dev->model) {
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300116 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
117 /* Enable lgdt330x */
118 dev->mode = EM28XX_ANALOG_MODE;
119 em28xx_tuner_callback(dev, XC2028_TUNER_RESET, 0);
120
121 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
122 &em2880_lgdt3303_dev,
123 &dev->i2c_adap);
124 if (attach_xc3028(0x61, dev) < 0)
125 return -EINVAL;
126 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300127 default:
128 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
129 " isn't supported yet\n",
130 dev->name);
131 break;
132 }
133 if (NULL == dev->dvb.frontend) {
134 printk(KERN_ERR
135 "%s/2: frontend initialization failed\n",
136 dev->name);
137 return -EINVAL;
138 }
139
140 /* register everything */
141 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
142 &dev->udev->dev,
143 adapter_nr);
144}
145
146static int dvb_fini(struct em28xx *dev)
147{
148 if (dev->dvb.frontend)
149 videobuf_dvb_unregister(&dev->dvb);
150
151 return 0;
152}
153
154static struct em28xx_ops dvb_ops = {
155 .id = EM28XX_DVB,
156 .name = "Em28xx dvb Extension",
157 .init = dvb_init,
158 .fini = dvb_fini,
159};
160
161static int __init em28xx_dvb_register(void)
162{
163 return em28xx_register_extension(&dvb_ops);
164}
165
166static void __exit em28xx_dvb_unregister(void)
167{
168 em28xx_unregister_extension(&dvb_ops);
169}
170
171module_init(em28xx_dvb_register);
172module_exit(em28xx_dvb_unregister);