blob: 87a735f1ee9e6f49b6d5ca0285443d2a5b4e8ec8 [file] [log] [blame]
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001/*
2 * cx18 driver initialization and card probing
3 *
4 * Derived from ivtv-driver.c
5 *
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
Andy Wallsc641d092008-09-01 00:40:41 -03007 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 * 02111-1307 USA
23 */
24
25#include "cx18-driver.h"
Andy Wallsb1526422008-08-30 16:03:44 -030026#include "cx18-io.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030027#include "cx18-version.h"
28#include "cx18-cards.h"
29#include "cx18-i2c.h"
30#include "cx18-irq.h"
31#include "cx18-gpio.h"
32#include "cx18-firmware.h"
Andy Walls21a278b2009-04-15 20:45:10 -030033#include "cx18-queue.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030034#include "cx18-streams.h"
35#include "cx18-av-core.h"
36#include "cx18-scb.h"
37#include "cx18-mailbox.h"
38#include "cx18-ioctl.h"
39#include "tuner-xc2028.h"
40
41#include <media/tveeprom.h>
42
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030043/* If you have already X v4l cards, then set this to X. This way
44 the device numbers stay matched. Example: you have a WinTV card
45 without radio and a Compro H900 with. Normally this would give a
46 video1 device together with a radio0 device for the Compro. By
47 setting this to 1 you ensure that radio0 is now also radio1. */
48int cx18_first_minor;
49
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030050/* add your revision and whatnot here */
51static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
52 {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418,
53 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
54 {0,}
55};
56
57MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
58
Andy Walls5811cf92009-02-14 17:08:37 -030059static atomic_t cx18_instance = ATOMIC_INIT(0);
60
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030061/* Parameter declarations */
62static int cardtype[CX18_MAX_CARDS];
63static int tuner[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
64 -1, -1, -1, -1, -1, -1, -1, -1,
65 -1, -1, -1, -1, -1, -1, -1, -1,
66 -1, -1, -1, -1, -1, -1, -1, -1 };
67static int radio[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
68 -1, -1, -1, -1, -1, -1, -1, -1,
69 -1, -1, -1, -1, -1, -1, -1, -1,
70 -1, -1, -1, -1, -1, -1, -1, -1 };
Hans Verkuilc6eb8ea2008-09-03 17:11:54 -030071static unsigned cardtype_c = 1;
72static unsigned tuner_c = 1;
73static unsigned radio_c = 1;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030074static char pal[] = "--";
75static char secam[] = "--";
76static char ntsc[] = "-";
77
78/* Buffers */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030079static int enc_ts_buffers = CX18_DEFAULT_ENC_TS_BUFFERS;
Andy Walls6ecd86d2008-12-07 23:30:17 -030080static int enc_mpg_buffers = CX18_DEFAULT_ENC_MPG_BUFFERS;
81static int enc_idx_buffers = CX18_DEFAULT_ENC_IDX_BUFFERS;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030082static int enc_yuv_buffers = CX18_DEFAULT_ENC_YUV_BUFFERS;
83static int enc_vbi_buffers = CX18_DEFAULT_ENC_VBI_BUFFERS;
84static int enc_pcm_buffers = CX18_DEFAULT_ENC_PCM_BUFFERS;
85
Andy Walls6ecd86d2008-12-07 23:30:17 -030086static int enc_ts_bufsize = CX18_DEFAULT_ENC_TS_BUFSIZE;
87static int enc_mpg_bufsize = CX18_DEFAULT_ENC_MPG_BUFSIZE;
88static int enc_idx_bufsize = CX18_DEFAULT_ENC_IDX_BUFSIZE;
89static int enc_yuv_bufsize = CX18_DEFAULT_ENC_YUV_BUFSIZE;
90/* VBI bufsize based on standards supported by card tuner for now */
91static int enc_pcm_bufsize = CX18_DEFAULT_ENC_PCM_BUFSIZE;
92
93static int enc_ts_bufs = -1;
94static int enc_mpg_bufs = -1;
95static int enc_idx_bufs = -1;
96static int enc_yuv_bufs = -1;
97static int enc_vbi_bufs = -1;
98static int enc_pcm_bufs = -1;
99
100
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300101static int cx18_pci_latency = 1;
102
Andy Walls3f75c612008-11-16 23:33:41 -0300103static int mmio_ndelay;
104static int retry_mmio = 1;
105
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300106int cx18_debug;
107
108module_param_array(tuner, int, &tuner_c, 0644);
109module_param_array(radio, bool, &radio_c, 0644);
110module_param_array(cardtype, int, &cardtype_c, 0644);
111module_param_string(pal, pal, sizeof(pal), 0644);
112module_param_string(secam, secam, sizeof(secam), 0644);
113module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
114module_param_named(debug, cx18_debug, int, 0644);
Andy Walls3f75c612008-11-16 23:33:41 -0300115module_param(mmio_ndelay, int, 0644);
116module_param(retry_mmio, int, 0644);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300117module_param(cx18_pci_latency, int, 0644);
118module_param(cx18_first_minor, int, 0644);
119
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300120module_param(enc_ts_buffers, int, 0644);
Andy Walls6ecd86d2008-12-07 23:30:17 -0300121module_param(enc_mpg_buffers, int, 0644);
122module_param(enc_idx_buffers, int, 0644);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300123module_param(enc_yuv_buffers, int, 0644);
124module_param(enc_vbi_buffers, int, 0644);
125module_param(enc_pcm_buffers, int, 0644);
126
Andy Walls6ecd86d2008-12-07 23:30:17 -0300127module_param(enc_ts_bufsize, int, 0644);
128module_param(enc_mpg_bufsize, int, 0644);
129module_param(enc_idx_bufsize, int, 0644);
130module_param(enc_yuv_bufsize, int, 0644);
131/* VBI bufsize based on standards supported by card tuner for now */
132module_param(enc_pcm_bufsize, int, 0644);
133
134module_param(enc_ts_bufs, int, 0644);
135module_param(enc_mpg_bufs, int, 0644);
136module_param(enc_idx_bufs, int, 0644);
137module_param(enc_yuv_bufs, int, 0644);
138module_param(enc_vbi_bufs, int, 0644);
139module_param(enc_pcm_bufs, int, 0644);
140
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300141MODULE_PARM_DESC(tuner, "Tuner type selection,\n"
142 "\t\t\tsee tuner.h for values");
143MODULE_PARM_DESC(radio,
144 "Enable or disable the radio. Use only if autodetection\n"
145 "\t\t\tfails. 0 = disable, 1 = enable");
146MODULE_PARM_DESC(cardtype,
147 "Only use this option if your card is not detected properly.\n"
148 "\t\tSpecify card type:\n"
149 "\t\t\t 1 = Hauppauge HVR 1600 (ESMT memory)\n"
150 "\t\t\t 2 = Hauppauge HVR 1600 (Samsung memory)\n"
151 "\t\t\t 3 = Compro VideoMate H900\n"
152 "\t\t\t 4 = Yuan MPC718\n"
Sri Deevi03c28082008-06-21 11:06:44 -0300153 "\t\t\t 5 = Conexant Raptor PAL/SECAM\n"
Andy Walls9eee4fb2008-10-04 20:28:40 -0300154 "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n"
Andy Walls9d5af862009-06-09 20:37:24 -0300155 "\t\t\t 7 = Leadtek WinFast PVR2100\n"
156 "\t\t\t 8 = Leadtek WinFast DVR3100 H\n"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300157 "\t\t\t 0 = Autodetect (default)\n"
158 "\t\t\t-1 = Ignore this card\n\t\t");
159MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
160MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC");
161MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K");
162MODULE_PARM_DESC(debug,
163 "Debug level (bitmask). Default: 0\n"
164 "\t\t\t 1/0x0001: warning\n"
165 "\t\t\t 2/0x0002: info\n"
166 "\t\t\t 4/0x0004: mailbox\n"
167 "\t\t\t 8/0x0008: dma\n"
168 "\t\t\t 16/0x0010: ioctl\n"
169 "\t\t\t 32/0x0020: file\n"
170 "\t\t\t 64/0x0040: i2c\n"
171 "\t\t\t128/0x0080: irq\n"
172 "\t\t\t256/0x0100: high volume\n");
173MODULE_PARM_DESC(cx18_pci_latency,
174 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
175 "\t\t\tDefault: Yes");
Andy Wallsd267d852008-09-28 21:46:02 -0300176MODULE_PARM_DESC(retry_mmio,
Andy Walls3f75c612008-11-16 23:33:41 -0300177 "(Deprecated) MMIO writes are now always checked and retried\n"
178 "\t\t\tEffectively: 1 [Yes]");
Andy Wallsc641d092008-09-01 00:40:41 -0300179MODULE_PARM_DESC(mmio_ndelay,
Andy Walls3f75c612008-11-16 23:33:41 -0300180 "(Deprecated) MMIO accesses are now never purposely delayed\n"
181 "\t\t\tEffectively: 0 ns");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300182MODULE_PARM_DESC(enc_ts_buffers,
Andy Walls6ecd86d2008-12-07 23:30:17 -0300183 "Encoder TS buffer memory (MB). (enc_ts_bufs can override)\n"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300184 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFFERS));
Andy Walls6ecd86d2008-12-07 23:30:17 -0300185MODULE_PARM_DESC(enc_ts_bufsize,
186 "Size of an encoder TS buffer (kB)\n"
187 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_TS_BUFSIZE));
188MODULE_PARM_DESC(enc_ts_bufs,
189 "Number of encoder TS buffers\n"
190 "\t\t\tDefault is computed from other enc_ts_* parameters");
191MODULE_PARM_DESC(enc_mpg_buffers,
192 "Encoder MPG buffer memory (MB). (enc_mpg_bufs can override)\n"
193 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS));
194MODULE_PARM_DESC(enc_mpg_bufsize,
195 "Size of an encoder MPG buffer (kB)\n"
196 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFSIZE));
197MODULE_PARM_DESC(enc_mpg_bufs,
198 "Number of encoder MPG buffers\n"
199 "\t\t\tDefault is computed from other enc_mpg_* parameters");
200MODULE_PARM_DESC(enc_idx_buffers,
201 "Encoder IDX buffer memory (MB). (enc_idx_bufs can override)\n"
202 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFFERS));
203MODULE_PARM_DESC(enc_idx_bufsize,
204 "Size of an encoder IDX buffer (kB)\n"
205 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFSIZE));
206MODULE_PARM_DESC(enc_idx_bufs,
207 "Number of encoder IDX buffers\n"
208 "\t\t\tDefault is computed from other enc_idx_* parameters");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300209MODULE_PARM_DESC(enc_yuv_buffers,
Andy Walls6ecd86d2008-12-07 23:30:17 -0300210 "Encoder YUV buffer memory (MB). (enc_yuv_bufs can override)\n"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300211 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFFERS));
Andy Walls6ecd86d2008-12-07 23:30:17 -0300212MODULE_PARM_DESC(enc_yuv_bufsize,
213 "Size of an encoder YUV buffer (kB)\n"
Andy Walls22dce182009-11-09 23:55:30 -0300214 "\t\t\tAllowed values are multiples of 33.75 kB rounded up\n"
215 "\t\t\t(multiples of size required for 32 screen lines)\n"
216 "\t\t\tDefault: 102");
Andy Walls6ecd86d2008-12-07 23:30:17 -0300217MODULE_PARM_DESC(enc_yuv_bufs,
218 "Number of encoder YUV buffers\n"
219 "\t\t\tDefault is computed from other enc_yuv_* parameters");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300220MODULE_PARM_DESC(enc_vbi_buffers,
Andy Walls6ecd86d2008-12-07 23:30:17 -0300221 "Encoder VBI buffer memory (MB). (enc_vbi_bufs can override)\n"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300222 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_VBI_BUFFERS));
Andy Walls6ecd86d2008-12-07 23:30:17 -0300223MODULE_PARM_DESC(enc_vbi_bufs,
224 "Number of encoder VBI buffers\n"
225 "\t\t\tDefault is computed from enc_vbi_buffers & tuner std");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300226MODULE_PARM_DESC(enc_pcm_buffers,
Andy Walls6ecd86d2008-12-07 23:30:17 -0300227 "Encoder PCM buffer memory (MB). (enc_pcm_bufs can override)\n"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300228 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS));
Andy Walls6ecd86d2008-12-07 23:30:17 -0300229MODULE_PARM_DESC(enc_pcm_bufsize,
230 "Size of an encoder PCM buffer (kB)\n"
231 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFSIZE));
232MODULE_PARM_DESC(enc_pcm_bufs,
233 "Number of encoder PCM buffers\n"
234 "\t\t\tDefault is computed from other enc_pcm_* parameters");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300235
Hans Verkuil581644d2009-06-19 11:54:00 -0300236MODULE_PARM_DESC(cx18_first_minor, "Set device node number assigned to first card");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300237
238MODULE_AUTHOR("Hans Verkuil");
239MODULE_DESCRIPTION("CX23418 driver");
240MODULE_SUPPORTED_DEVICE("CX23418 MPEG2 encoder");
241MODULE_LICENSE("GPL");
242
243MODULE_VERSION(CX18_VERSION);
244
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300245/* Generic utility functions */
246int cx18_msleep_timeout(unsigned int msecs, int intr)
247{
Andy Walls330c6ec2008-11-08 14:19:37 -0300248 long int timeout = msecs_to_jiffies(msecs);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300249 int sig;
250
251 do {
252 set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
253 timeout = schedule_timeout(timeout);
254 sig = intr ? signal_pending(current) : 0;
255 } while (!sig && timeout);
256 return sig;
257}
258
259/* Release ioremapped memory */
260static void cx18_iounmap(struct cx18 *cx)
261{
262 if (cx == NULL)
263 return;
264
265 /* Release io memory */
266 if (cx->enc_mem != NULL) {
267 CX18_DEBUG_INFO("releasing enc_mem\n");
268 iounmap(cx->enc_mem);
269 cx->enc_mem = NULL;
270 }
271}
272
Andy Walls25a42e42009-07-05 17:09:28 -0300273static void cx18_eeprom_dump(struct cx18 *cx, unsigned char *eedata, int len)
274{
275 int i;
276
277 CX18_INFO("eeprom dump:\n");
278 for (i = 0; i < len; i++) {
279 if (0 == (i % 16))
280 CX18_INFO("eeprom %02x:", i);
281 printk(KERN_CONT " %02x", eedata[i]);
282 if (15 == (i % 16))
283 printk(KERN_CONT "\n");
284 }
285}
286
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300287/* Hauppauge card? get values from tveeprom */
288void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
289{
Andy Wallsff2a2002009-02-20 23:52:13 -0300290 struct i2c_client c;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300291 u8 eedata[256];
292
Andy Walls6246d4e2009-02-21 22:27:37 -0300293 memset(&c, 0, sizeof(c));
Andy Walls098003d2009-02-28 13:19:45 -0300294 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
Andy Wallsff2a2002009-02-20 23:52:13 -0300295 c.adapter = &cx->i2c_adap[0];
296 c.addr = 0xA0 >> 1;
297
Andy Walls25a42e42009-07-05 17:09:28 -0300298 memset(tv, 0, sizeof(*tv));
299 if (tveeprom_read(&c, eedata, sizeof(eedata)))
300 return;
301
302 switch (cx->card->type) {
303 case CX18_CARD_HVR_1600_ESMT:
304 case CX18_CARD_HVR_1600_SAMSUNG:
305 tveeprom_hauppauge_analog(&c, tv, eedata);
306 break;
307 case CX18_CARD_YUAN_MPC718:
308 tv->model = 0x718;
309 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
310 CX18_INFO("eeprom PCI ID: %02x%02x:%02x%02x\n",
311 eedata[2], eedata[1], eedata[4], eedata[3]);
312 break;
313 default:
314 tv->model = 0xffffffff;
315 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
316 break;
317 }
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300318}
319
320static void cx18_process_eeprom(struct cx18 *cx)
321{
322 struct tveeprom tv;
323
324 cx18_read_eeprom(cx, &tv);
325
326 /* Many thanks to Steven Toth from Hauppauge for providing the
327 model numbers */
Hans Verkuil1d081602008-05-12 14:45:19 -0300328 /* Note: the Samsung memory models cannot be reliably determined
329 from the model number. Use the cardtype module option if you
330 have one of these preproduction models. */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300331 switch (tv.model) {
Hans Verkuil1d081602008-05-12 14:45:19 -0300332 case 74000 ... 74999:
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300333 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
334 break;
Andy Walls25a42e42009-07-05 17:09:28 -0300335 case 0x718:
336 return;
337 case 0xffffffff:
338 CX18_INFO("Unknown EEPROM encoding\n");
339 return;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300340 case 0:
341 CX18_ERR("Invalid EEPROM\n");
342 return;
343 default:
344 CX18_ERR("Unknown model %d, defaulting to HVR-1600\n", tv.model);
345 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
346 break;
347 }
348
349 cx->v4l2_cap = cx->card->v4l2_capabilities;
350 cx->card_name = cx->card->name;
351 cx->card_i2c = cx->card->i2c;
352
353 CX18_INFO("Autodetected %s\n", cx->card_name);
354
355 if (tv.tuner_type == TUNER_ABSENT)
Andy Walls4442ee82009-05-09 00:34:31 -0300356 CX18_ERR("tveeprom cannot autodetect tuner!\n");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300357
358 if (cx->options.tuner == -1)
359 cx->options.tuner = tv.tuner_type;
360 if (cx->options.radio == -1)
361 cx->options.radio = (tv.has_radio != 0);
362
363 if (cx->std != 0)
364 /* user specified tuner standard */
365 return;
366
367 /* autodetect tuner standard */
368 if (tv.tuner_formats & V4L2_STD_PAL) {
369 CX18_DEBUG_INFO("PAL tuner detected\n");
370 cx->std |= V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
371 } else if (tv.tuner_formats & V4L2_STD_NTSC) {
372 CX18_DEBUG_INFO("NTSC tuner detected\n");
373 cx->std |= V4L2_STD_NTSC_M;
374 } else if (tv.tuner_formats & V4L2_STD_SECAM) {
375 CX18_DEBUG_INFO("SECAM tuner detected\n");
376 cx->std |= V4L2_STD_SECAM_L;
377 } else {
378 CX18_INFO("No tuner detected, default to NTSC-M\n");
379 cx->std |= V4L2_STD_NTSC_M;
380 }
381}
382
383static v4l2_std_id cx18_parse_std(struct cx18 *cx)
384{
385 switch (pal[0]) {
386 case '6':
387 return V4L2_STD_PAL_60;
388 case 'b':
389 case 'B':
390 case 'g':
391 case 'G':
392 return V4L2_STD_PAL_BG;
393 case 'h':
394 case 'H':
395 return V4L2_STD_PAL_H;
396 case 'n':
397 case 'N':
398 if (pal[1] == 'c' || pal[1] == 'C')
399 return V4L2_STD_PAL_Nc;
400 return V4L2_STD_PAL_N;
401 case 'i':
402 case 'I':
403 return V4L2_STD_PAL_I;
404 case 'd':
405 case 'D':
406 case 'k':
407 case 'K':
408 return V4L2_STD_PAL_DK;
409 case 'M':
410 case 'm':
411 return V4L2_STD_PAL_M;
412 case '-':
413 break;
414 default:
415 CX18_WARN("pal= argument not recognised\n");
416 return 0;
417 }
418
419 switch (secam[0]) {
420 case 'b':
421 case 'B':
422 case 'g':
423 case 'G':
424 case 'h':
425 case 'H':
426 return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H;
427 case 'd':
428 case 'D':
429 case 'k':
430 case 'K':
431 return V4L2_STD_SECAM_DK;
432 case 'l':
433 case 'L':
434 if (secam[1] == 'C' || secam[1] == 'c')
435 return V4L2_STD_SECAM_LC;
436 return V4L2_STD_SECAM_L;
437 case '-':
438 break;
439 default:
440 CX18_WARN("secam= argument not recognised\n");
441 return 0;
442 }
443
444 switch (ntsc[0]) {
445 case 'm':
446 case 'M':
447 return V4L2_STD_NTSC_M;
448 case 'j':
449 case 'J':
450 return V4L2_STD_NTSC_M_JP;
451 case 'k':
452 case 'K':
453 return V4L2_STD_NTSC_M_KR;
454 case '-':
455 break;
456 default:
457 CX18_WARN("ntsc= argument not recognised\n");
458 return 0;
459 }
460
461 /* no match found */
462 return 0;
463}
464
465static void cx18_process_options(struct cx18 *cx)
466{
467 int i, j;
468
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300469 cx->options.megabytes[CX18_ENC_STREAM_TYPE_TS] = enc_ts_buffers;
Andy Walls6ecd86d2008-12-07 23:30:17 -0300470 cx->options.megabytes[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers;
471 cx->options.megabytes[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_buffers;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300472 cx->options.megabytes[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers;
473 cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers;
474 cx->options.megabytes[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
Andy Walls6ecd86d2008-12-07 23:30:17 -0300475 cx->options.megabytes[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control only */
476
477 cx->stream_buffers[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufs;
478 cx->stream_buffers[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufs;
479 cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufs;
480 cx->stream_buffers[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufs;
481 cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] = enc_vbi_bufs;
482 cx->stream_buffers[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufs;
483 cx->stream_buffers[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control, no data */
484
485 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = enc_ts_bufsize;
486 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize;
487 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize;
488 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize;
Andy Walls466df462009-02-07 15:47:28 -0300489 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = vbi_active_samples * 36;
Andy Walls6ecd86d2008-12-07 23:30:17 -0300490 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize;
491 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */
492
Andy Walls466df462009-02-07 15:47:28 -0300493 /* Ensure stream_buffers & stream_buf_size are valid */
Andy Walls6ecd86d2008-12-07 23:30:17 -0300494 for (i = 0; i < CX18_MAX_STREAMS; i++) {
Andy Walls466df462009-02-07 15:47:28 -0300495 if (cx->stream_buffers[i] == 0 || /* User said 0 buffers */
496 cx->options.megabytes[i] <= 0 || /* User said 0 MB total */
497 cx->stream_buf_size[i] <= 0) { /* User said buf size 0 */
Andy Walls6ecd86d2008-12-07 23:30:17 -0300498 cx->options.megabytes[i] = 0;
499 cx->stream_buffers[i] = 0;
500 cx->stream_buf_size[i] = 0;
501 continue;
502 }
Andy Walls466df462009-02-07 15:47:28 -0300503 /*
Andy Walls22dce182009-11-09 23:55:30 -0300504 * YUV is a special case where the stream_buf_size needs to be
505 * an integral multiple of 33.75 kB (storage for 32 screens
506 * lines to maintain alignment in case of lost buffers
507 */
508 if (i == CX18_ENC_STREAM_TYPE_YUV) {
509 cx->stream_buf_size[i] *= 1024;
510 cx->stream_buf_size[i] -=
511 (cx->stream_buf_size[i] % CX18_UNIT_ENC_YUV_BUFSIZE);
512
513 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_YUV_BUFSIZE)
514 cx->stream_buf_size[i] =
515 CX18_UNIT_ENC_YUV_BUFSIZE;
516 }
517 /*
518 * YUV is a special case where the stream_buf_size is
519 * now in bytes.
Andy Walls466df462009-02-07 15:47:28 -0300520 * VBI is a special case where the stream_buf_size is fixed
521 * and already in bytes
522 */
Andy Walls22dce182009-11-09 23:55:30 -0300523 if (i == CX18_ENC_STREAM_TYPE_VBI ||
524 i == CX18_ENC_STREAM_TYPE_YUV) {
Andy Walls466df462009-02-07 15:47:28 -0300525 if (cx->stream_buffers[i] < 0) {
526 cx->stream_buffers[i] =
527 cx->options.megabytes[i] * 1024 * 1024
528 / cx->stream_buf_size[i];
529 } else {
530 /* N.B. This might round down to 0 */
531 cx->options.megabytes[i] =
532 cx->stream_buffers[i]
533 * cx->stream_buf_size[i]/(1024 * 1024);
Andy Walls6ecd86d2008-12-07 23:30:17 -0300534 }
Andy Walls6ecd86d2008-12-07 23:30:17 -0300535 } else {
Andy Walls22dce182009-11-09 23:55:30 -0300536 /* All other streams have stream_buf_size in kB here */
537 if (cx->stream_buffers[i] < 0) {
538 cx->stream_buffers[i] =
539 cx->options.megabytes[i] * 1024
540 / cx->stream_buf_size[i];
541 } else {
542 /* N.B. This might round down to 0 */
543 cx->options.megabytes[i] =
544 cx->stream_buffers[i]
545 * cx->stream_buf_size[i] / 1024;
546 }
547 /* convert from kB to bytes */
548 cx->stream_buf_size[i] *= 1024;
Andy Walls6ecd86d2008-12-07 23:30:17 -0300549 }
Andy Walls22dce182009-11-09 23:55:30 -0300550 CX18_DEBUG_INFO("Stream type %d options: %d MB, %d buffers, "
551 "%d bytes\n", i, cx->options.megabytes[i],
552 cx->stream_buffers[i], cx->stream_buf_size[i]);
Andy Walls6ecd86d2008-12-07 23:30:17 -0300553 }
554
Andy Walls5811cf92009-02-14 17:08:37 -0300555 cx->options.cardtype = cardtype[cx->instance];
556 cx->options.tuner = tuner[cx->instance];
557 cx->options.radio = radio[cx->instance];
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300558
559 cx->std = cx18_parse_std(cx);
560 if (cx->options.cardtype == -1) {
561 CX18_INFO("Ignore card\n");
562 return;
563 }
564 cx->card = cx18_get_card(cx->options.cardtype - 1);
565 if (cx->card)
566 CX18_INFO("User specified %s card\n", cx->card->name);
567 else if (cx->options.cardtype != 0)
568 CX18_ERR("Unknown user specified type, trying to autodetect card\n");
569 if (cx->card == NULL) {
Andy Walls3d059132009-01-10 21:54:39 -0300570 if (cx->pci_dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300571 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
572 CX18_INFO("Autodetected Hauppauge card\n");
573 }
574 }
575 if (cx->card == NULL) {
576 for (i = 0; (cx->card = cx18_get_card(i)); i++) {
577 if (cx->card->pci_list == NULL)
578 continue;
579 for (j = 0; cx->card->pci_list[j].device; j++) {
Andy Walls3d059132009-01-10 21:54:39 -0300580 if (cx->pci_dev->device !=
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300581 cx->card->pci_list[j].device)
582 continue;
Andy Walls3d059132009-01-10 21:54:39 -0300583 if (cx->pci_dev->subsystem_vendor !=
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300584 cx->card->pci_list[j].subsystem_vendor)
585 continue;
Andy Walls3d059132009-01-10 21:54:39 -0300586 if (cx->pci_dev->subsystem_device !=
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300587 cx->card->pci_list[j].subsystem_device)
588 continue;
589 CX18_INFO("Autodetected %s card\n", cx->card->name);
590 goto done;
591 }
592 }
593 }
594done:
595
596 if (cx->card == NULL) {
597 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
Bjorn Helgaas29e66a62008-09-04 17:24:51 -0300598 CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
Andy Walls3d059132009-01-10 21:54:39 -0300599 cx->pci_dev->vendor, cx->pci_dev->device);
Bjorn Helgaas29e66a62008-09-04 17:24:51 -0300600 CX18_ERR(" subsystem vendor/device: [%04x:%04x]\n",
Andy Walls3d059132009-01-10 21:54:39 -0300601 cx->pci_dev->subsystem_vendor,
602 cx->pci_dev->subsystem_device);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300603 CX18_ERR("Defaulting to %s card\n", cx->card->name);
604 CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
605 CX18_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n");
606 CX18_ERR("Prefix your subject line with [UNKNOWN CX18 CARD].\n");
607 }
608 cx->v4l2_cap = cx->card->v4l2_capabilities;
609 cx->card_name = cx->card->name;
610 cx->card_i2c = cx->card->i2c;
611}
612
Andy Walls87116152009-04-13 22:42:43 -0300613static int __devinit cx18_create_in_workq(struct cx18 *cx)
614{
615 snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in",
616 cx->v4l2_dev.name);
617 cx->in_work_queue = create_singlethread_workqueue(cx->in_workq_name);
618 if (cx->in_work_queue == NULL) {
619 CX18_ERR("Unable to create incoming mailbox handler thread\n");
620 return -ENOMEM;
621 }
622 return 0;
623}
624
625static int __devinit cx18_create_out_workq(struct cx18 *cx)
626{
627 snprintf(cx->out_workq_name, sizeof(cx->out_workq_name), "%s-out",
628 cx->v4l2_dev.name);
629 cx->out_work_queue = create_workqueue(cx->out_workq_name);
630 if (cx->out_work_queue == NULL) {
631 CX18_ERR("Unable to create outgoing mailbox handler threads\n");
632 return -ENOMEM;
633 }
634 return 0;
635}
636
637static void __devinit cx18_init_in_work_orders(struct cx18 *cx)
638{
639 int i;
640 for (i = 0; i < CX18_MAX_IN_WORK_ORDERS; i++) {
641 cx->in_work_order[i].cx = cx;
642 cx->in_work_order[i].str = cx->epu_debug_str;
643 INIT_WORK(&cx->in_work_order[i].work, cx18_in_work_handler);
644 }
645}
646
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300647/* Precondition: the cx18 structure has been memset to 0. Only
Andy Walls5811cf92009-02-14 17:08:37 -0300648 the dev and instance fields have been filled in.
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300649 No assumptions on the card type may be made here (see cx18_init_struct2
650 for that).
651 */
652static int __devinit cx18_init_struct1(struct cx18 *cx)
653{
Andy Walls87116152009-04-13 22:42:43 -0300654 int ret;
Andy Wallsee2d64f2008-11-16 01:38:19 -0300655
Andy Walls3d059132009-01-10 21:54:39 -0300656 cx->base_addr = pci_resource_start(cx->pci_dev, 0);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300657
658 mutex_init(&cx->serialize_lock);
Andy Walls8abdd002008-07-13 19:05:25 -0300659 mutex_init(&cx->gpio_lock);
Andy Walls72c2d6d2008-11-06 01:15:41 -0300660 mutex_init(&cx->epu2apu_mb_lock);
661 mutex_init(&cx->epu2cpu_mb_lock);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300662
Andy Walls87116152009-04-13 22:42:43 -0300663 ret = cx18_create_out_workq(cx);
664 if (ret)
665 return ret;
666
667 ret = cx18_create_in_workq(cx);
668 if (ret) {
669 destroy_workqueue(cx->out_work_queue);
670 return ret;
Andy Walls572bfea2008-11-25 21:43:05 -0300671 }
672
Andy Walls87116152009-04-13 22:42:43 -0300673 cx18_init_in_work_orders(cx);
Andy Walls1d6782b2008-11-05 00:49:14 -0300674
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300675 /* start counting open_id at 1 */
676 cx->open_id = 1;
677
678 /* Initial settings */
679 cx2341x_fill_defaults(&cx->params);
680 cx->temporal_strength = cx->params.video_temporal_filter;
681 cx->spatial_strength = cx->params.video_spatial_filter;
682 cx->filter_mode = cx->params.video_spatial_filter_mode |
683 (cx->params.video_temporal_filter_mode << 1) |
684 (cx->params.video_median_filter_type << 2);
685 cx->params.port = CX2341X_PORT_MEMORY;
Andy Walls302df972009-01-31 00:33:02 -0300686 cx->params.capabilities =
Andy Walls006e7172009-02-21 22:44:50 -0300687 CX2341X_CAP_HAS_TS | CX2341X_CAP_HAS_SLICED_VBI;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300688 init_waitqueue_head(&cx->cap_w);
689 init_waitqueue_head(&cx->mb_apu_waitq);
690 init_waitqueue_head(&cx->mb_cpu_waitq);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300691 init_waitqueue_head(&cx->dma_waitq);
692
693 /* VBI */
Andy Wallsdd073432008-12-12 16:24:04 -0300694 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300695 cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced;
Andy Wallsaf009cf2008-12-12 20:00:29 -0300696
Andy Walls52fcb3e2009-11-08 23:45:24 -0300697 /* IVTV style VBI insertion into MPEG streams */
698 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_buf.list);
699 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.list);
700 INIT_LIST_HEAD(&cx->vbi.sliced_mpeg_mdl.buf_list);
701 list_add(&cx->vbi.sliced_mpeg_buf.list,
702 &cx->vbi.sliced_mpeg_mdl.buf_list);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300703 return 0;
704}
705
706/* Second initialization part. Here the card type has been
707 autodetected. */
708static void __devinit cx18_init_struct2(struct cx18 *cx)
709{
710 int i;
711
712 for (i = 0; i < CX18_CARD_MAX_VIDEO_INPUTS; i++)
713 if (cx->card->video_inputs[i].video_type == 0)
714 break;
715 cx->nof_inputs = i;
716 for (i = 0; i < CX18_CARD_MAX_AUDIO_INPUTS; i++)
717 if (cx->card->audio_inputs[i].audio_type == 0)
718 break;
719 cx->nof_audio_inputs = i;
720
721 /* Find tuner input */
722 for (i = 0; i < cx->nof_inputs; i++) {
723 if (cx->card->video_inputs[i].video_type ==
724 CX18_CARD_INPUT_VID_TUNER)
725 break;
726 }
727 if (i == cx->nof_inputs)
728 i = 0;
729 cx->active_input = i;
730 cx->audio_input = cx->card->video_inputs[i].audio_index;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300731}
732
Andy Walls3d059132009-01-10 21:54:39 -0300733static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *pci_dev,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300734 const struct pci_device_id *pci_id)
735{
736 u16 cmd;
737 unsigned char pci_latency;
738
739 CX18_DEBUG_INFO("Enabling pci device\n");
740
Andy Walls3d059132009-01-10 21:54:39 -0300741 if (pci_enable_device(pci_dev)) {
Andy Walls5811cf92009-02-14 17:08:37 -0300742 CX18_ERR("Can't enable device %d!\n", cx->instance);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300743 return -EIO;
744 }
Andy Walls3d059132009-01-10 21:54:39 -0300745 if (pci_set_dma_mask(pci_dev, 0xffffffff)) {
Andy Walls5811cf92009-02-14 17:08:37 -0300746 CX18_ERR("No suitable DMA available, card %d\n", cx->instance);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300747 return -EIO;
748 }
749 if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) {
Andy Walls5811cf92009-02-14 17:08:37 -0300750 CX18_ERR("Cannot request encoder memory region, card %d\n",
751 cx->instance);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300752 return -EIO;
753 }
754
Andy Walls45190642008-08-29 16:10:21 -0300755 /* Enable bus mastering and memory mapped IO for the CX23418 */
Andy Walls3d059132009-01-10 21:54:39 -0300756 pci_read_config_word(pci_dev, PCI_COMMAND, &cmd);
Andy Walls45190642008-08-29 16:10:21 -0300757 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
Andy Walls3d059132009-01-10 21:54:39 -0300758 pci_write_config_word(pci_dev, PCI_COMMAND, cmd);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300759
Andy Walls3d059132009-01-10 21:54:39 -0300760 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &cx->card_rev);
761 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &pci_latency);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300762
763 if (pci_latency < 64 && cx18_pci_latency) {
764 CX18_INFO("Unreasonably low latency timer, "
765 "setting to 64 (was %d)\n", pci_latency);
Andy Walls3d059132009-01-10 21:54:39 -0300766 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, 64);
767 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &pci_latency);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300768 }
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300769
770 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, "
771 "irq: %d, latency: %d, memory: 0x%lx\n",
Andy Walls3d059132009-01-10 21:54:39 -0300772 cx->pci_dev->device, cx->card_rev, pci_dev->bus->number,
773 PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn),
774 cx->pci_dev->irq, pci_latency, (unsigned long)cx->base_addr);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300775
776 return 0;
777}
778
Andy Wallsff2a2002009-02-20 23:52:13 -0300779static void cx18_init_subdevs(struct cx18 *cx)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300780{
781 u32 hw = cx->card->hw_all;
Andy Wallsff2a2002009-02-20 23:52:13 -0300782 u32 device;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300783 int i;
784
Andy Wallsff2a2002009-02-20 23:52:13 -0300785 for (i = 0, device = 1; i < 32; i++, device <<= 1) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300786
787 if (!(device & hw))
788 continue;
Andy Wallsff2a2002009-02-20 23:52:13 -0300789
790 switch (device) {
Andy Wallsff2a2002009-02-20 23:52:13 -0300791 case CX18_HW_DVB:
792 case CX18_HW_TVEEPROM:
793 /* These subordinate devices do not use probing */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300794 cx->hw_flags |= device;
Andy Wallsff2a2002009-02-20 23:52:13 -0300795 break;
796 case CX18_HW_418_AV:
797 /* The A/V decoder gets probed earlier to set PLLs */
798 /* Just note that the card uses it (i.e. has analog) */
799 cx->hw_flags |= device;
800 break;
Andy Wallseefe1012009-02-21 18:42:49 -0300801 case CX18_HW_GPIO_RESET_CTRL:
802 /*
803 * The Reset Controller gets probed and added to
804 * hw_flags earlier for i2c adapter/bus initialization
805 */
806 break;
807 case CX18_HW_GPIO_MUX:
808 if (cx18_gpio_register(cx, device) == 0)
809 cx->hw_flags |= device;
810 break;
Andy Wallsff2a2002009-02-20 23:52:13 -0300811 default:
812 if (cx18_i2c_register(cx, i) == 0)
813 cx->hw_flags |= device;
814 break;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300815 }
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300816 }
817
Andy Wallsff2a2002009-02-20 23:52:13 -0300818 if (cx->hw_flags & CX18_HW_418_AV)
819 cx->sd_av = cx18_find_hw(cx, CX18_HW_418_AV);
820
821 if (cx->card->hw_muxer != 0)
822 cx->sd_extmux = cx18_find_hw(cx, cx->card->hw_muxer);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300823}
824
Andy Walls3d059132009-01-10 21:54:39 -0300825static int __devinit cx18_probe(struct pci_dev *pci_dev,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300826 const struct pci_device_id *pci_id)
827{
828 int retval = 0;
Andy Wallsff086572008-10-18 08:51:28 -0300829 int i;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300830 u32 devtype;
831 struct cx18 *cx;
832
Andy Walls5811cf92009-02-14 17:08:37 -0300833 /* FIXME - module parameter arrays constrain max instances */
834 i = atomic_inc_return(&cx18_instance) - 1;
835 if (i >= CX18_MAX_CARDS) {
836 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
837 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300838 return -ENOMEM;
839 }
840
841 cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC);
Andy Walls5811cf92009-02-14 17:08:37 -0300842 if (cx == NULL) {
843 printk(KERN_ERR "cx18: cannot manage card %d, out of memory\n",
844 i);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300845 return -ENOMEM;
846 }
Andy Walls888cdb02009-01-11 15:08:53 -0300847 cx->pci_dev = pci_dev;
Andy Walls5811cf92009-02-14 17:08:37 -0300848 cx->instance = i;
849
Andy Walls888cdb02009-01-11 15:08:53 -0300850 retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev);
851 if (retval) {
Andy Walls5811cf92009-02-14 17:08:37 -0300852 printk(KERN_ERR "cx18: v4l2_device_register of card %d failed"
853 "\n", cx->instance);
854 kfree(cx);
855 return retval;
Andy Walls888cdb02009-01-11 15:08:53 -0300856 }
Andy Walls5811cf92009-02-14 17:08:37 -0300857 snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d",
858 cx->instance);
859 CX18_INFO("Initializing card %d\n", cx->instance);
Andy Walls888cdb02009-01-11 15:08:53 -0300860
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300861 cx18_process_options(cx);
862 if (cx->options.cardtype == -1) {
863 retval = -ENODEV;
Andy Walls5811cf92009-02-14 17:08:37 -0300864 goto err;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300865 }
Andy Walls87116152009-04-13 22:42:43 -0300866
867 retval = cx18_init_struct1(cx);
868 if (retval)
Andy Walls5811cf92009-02-14 17:08:37 -0300869 goto err;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300870
871 CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr);
872
873 /* PCI Device Setup */
Andy Walls3d059132009-01-10 21:54:39 -0300874 retval = cx18_setup_pci(cx, pci_dev, pci_id);
Andy Walls572bfea2008-11-25 21:43:05 -0300875 if (retval != 0)
Andy Walls87116152009-04-13 22:42:43 -0300876 goto free_workqueues;
Andy Walls572bfea2008-11-25 21:43:05 -0300877
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300878 /* map io memory */
879 CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n",
880 cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE);
881 cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET,
882 CX18_MEM_SIZE);
883 if (!cx->enc_mem) {
884 CX18_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n");
885 CX18_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n");
886 retval = -ENOMEM;
887 goto free_mem;
888 }
889 cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET;
Andy Wallsb1526422008-08-30 16:03:44 -0300890 devtype = cx18_read_reg(cx, 0xC72028);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300891 switch (devtype & 0xff000000) {
892 case 0xff000000:
893 CX18_INFO("cx23418 revision %08x (A)\n", devtype);
894 break;
895 case 0x01000000:
896 CX18_INFO("cx23418 revision %08x (B)\n", devtype);
897 break;
898 default:
899 CX18_INFO("cx23418 revision %08x (Unknown)\n", devtype);
900 break;
901 }
902
903 cx18_init_power(cx, 1);
904 cx18_init_memory(cx);
905
Al Viro990c81c2008-05-21 00:32:01 -0300906 cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300907 cx18_init_scb(cx);
908
909 cx18_gpio_init(cx);
910
Andy Wallsff2a2002009-02-20 23:52:13 -0300911 /* Initialize integrated A/V decoder early to set PLLs, just in case */
912 retval = cx18_av_probe(cx);
Andy Wallsfa3e7032009-02-16 02:23:25 -0300913 if (retval) {
914 CX18_ERR("Could not register A/V decoder subdevice\n");
915 goto free_map;
916 }
Hans Verkuilcc26b072009-03-29 19:20:26 -0300917 cx18_call_hw(cx, CX18_HW_418_AV, core, init, 0);
Andy Wallsfa3e7032009-02-16 02:23:25 -0300918
Andy Wallseefe1012009-02-21 18:42:49 -0300919 /* Initialize GPIO Reset Controller to do chip resets during i2c init */
920 if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) {
921 if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0)
922 CX18_WARN("Could not register GPIO reset controller"
923 "subdevice; proceeding anyway.\n");
924 else
925 cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL;
926 }
927
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300928 /* active i2c */
929 CX18_DEBUG_INFO("activating i2c...\n");
Andy Walls9b4a7c82008-10-18 10:20:25 -0300930 retval = init_cx18_i2c(cx);
931 if (retval) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300932 CX18_ERR("Could not initialize i2c\n");
933 goto free_map;
934 }
935
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300936 if (cx->card->hw_all & CX18_HW_TVEEPROM) {
937 /* Based on the model number the cardtype may be changed.
938 The PCI IDs are not always reliable. */
939 cx18_process_eeprom(cx);
940 }
941 if (cx->card->comment)
942 CX18_INFO("%s", cx->card->comment);
943 if (cx->card->v4l2_capabilities == 0) {
944 retval = -ENODEV;
945 goto free_i2c;
946 }
947 cx18_init_memory(cx);
Andy Wallsfd6b9c92008-12-14 21:26:25 -0300948 cx18_init_scb(cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300949
950 /* Register IRQ */
Andy Walls3d059132009-01-10 21:54:39 -0300951 retval = request_irq(cx->pci_dev->irq, cx18_irq_handler,
Andy Walls5811cf92009-02-14 17:08:37 -0300952 IRQF_SHARED | IRQF_DISABLED,
953 cx->v4l2_dev.name, (void *)cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300954 if (retval) {
955 CX18_ERR("Failed to register irq %d\n", retval);
956 goto free_i2c;
957 }
958
959 if (cx->std == 0)
960 cx->std = V4L2_STD_NTSC_M;
961
962 if (cx->options.tuner == -1) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300963 for (i = 0; i < CX18_CARD_MAX_TUNERS; i++) {
964 if ((cx->std & cx->card->tuners[i].std) == 0)
965 continue;
966 cx->options.tuner = cx->card->tuners[i].tuner;
967 break;
968 }
969 }
970 /* if no tuner was found, then pick the first tuner in the card list */
971 if (cx->options.tuner == -1 && cx->card->tuners[0].std) {
972 cx->std = cx->card->tuners[0].std;
Hans Verkuilc3cb4d92008-06-27 23:27:25 -0300973 if (cx->std & V4L2_STD_PAL)
974 cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
975 else if (cx->std & V4L2_STD_NTSC)
976 cx->std = V4L2_STD_NTSC_M;
977 else if (cx->std & V4L2_STD_SECAM)
978 cx->std = V4L2_STD_SECAM_L;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300979 cx->options.tuner = cx->card->tuners[0].tuner;
980 }
981 if (cx->options.radio == -1)
982 cx->options.radio = (cx->card->radio_input.audio_type != 0);
983
984 /* The card is now fully identified, continue with card-specific
985 initialization. */
986 cx18_init_struct2(cx);
987
Andy Wallsff2a2002009-02-20 23:52:13 -0300988 cx18_init_subdevs(cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300989
Andy Walls8d037ed2009-02-21 22:35:11 -0300990 if (cx->std & V4L2_STD_525_60)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300991 cx->is_60hz = 1;
Andy Walls8d037ed2009-02-21 22:35:11 -0300992 else
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300993 cx->is_50hz = 1;
Andy Walls8d037ed2009-02-21 22:35:11 -0300994
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300995 cx->params.video_gop_size = cx->is_60hz ? 15 : 12;
996
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300997 if (cx->options.radio > 0)
998 cx->v4l2_cap |= V4L2_CAP_RADIO;
999
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001000 if (cx->options.tuner > -1) {
1001 struct tuner_setup setup;
1002
1003 setup.addr = ADDR_UNSET;
1004 setup.type = cx->options.tuner;
1005 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1006 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
1007 cx18_reset_tuner_gpio : NULL;
Andy Wallsff2a2002009-02-20 23:52:13 -03001008 cx18_call_all(cx, tuner, s_type_addr, &setup);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001009 if (setup.type == TUNER_XC2028) {
1010 static struct xc2028_ctrl ctrl = {
1011 .fname = XC2028_DEFAULT_FIRMWARE,
1012 .max_len = 64,
1013 };
1014 struct v4l2_priv_tun_config cfg = {
1015 .tuner = cx->options.tuner,
1016 .priv = &ctrl,
1017 };
Andy Wallsff2a2002009-02-20 23:52:13 -03001018 cx18_call_all(cx, tuner, s_config, &cfg);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001019 }
1020 }
1021
1022 /* The tuner is fixed to the standard. The other inputs (e.g. S-Video)
1023 are not. */
1024 cx->tuner_std = cx->std;
1025
Hans Verkuil5e7fdc52008-05-30 10:51:53 -03001026 retval = cx18_streams_setup(cx);
1027 if (retval) {
1028 CX18_ERR("Error %d setting up streams\n", retval);
1029 goto free_irq;
1030 }
1031 retval = cx18_streams_register(cx);
1032 if (retval) {
1033 CX18_ERR("Error %d registering devices\n", retval);
1034 goto free_streams;
1035 }
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001036
Andy Walls5811cf92009-02-14 17:08:37 -03001037 CX18_INFO("Initialized card: %s\n", cx->card_name);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001038 return 0;
1039
1040free_streams:
Hans Verkuil3f983872008-05-01 10:31:12 -03001041 cx18_streams_cleanup(cx, 1);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001042free_irq:
Andy Walls3d059132009-01-10 21:54:39 -03001043 free_irq(cx->pci_dev->irq, (void *)cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001044free_i2c:
1045 exit_cx18_i2c(cx);
1046free_map:
1047 cx18_iounmap(cx);
1048free_mem:
1049 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
Andy Walls87116152009-04-13 22:42:43 -03001050free_workqueues:
Andy Wallsdeed75e2009-04-13 22:22:40 -03001051 destroy_workqueue(cx->in_work_queue);
Andy Walls87116152009-04-13 22:42:43 -03001052 destroy_workqueue(cx->out_work_queue);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001053err:
1054 if (retval == 0)
1055 retval = -ENODEV;
1056 CX18_ERR("Error %d on initialization\n", retval);
1057
Andy Walls5811cf92009-02-14 17:08:37 -03001058 v4l2_device_unregister(&cx->v4l2_dev);
1059 kfree(cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001060 return retval;
1061}
1062
1063int cx18_init_on_first_open(struct cx18 *cx)
1064{
1065 int video_input;
1066 int fw_retry_count = 3;
1067 struct v4l2_frequency vf;
Andy Walls3b6fe582008-06-21 08:36:31 -03001068 struct cx18_open_id fh;
1069
1070 fh.cx = cx;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001071
1072 if (test_bit(CX18_F_I_FAILED, &cx->i_flags))
1073 return -ENXIO;
1074
1075 if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags))
1076 return 0;
1077
1078 while (--fw_retry_count > 0) {
1079 /* load firmware */
1080 if (cx18_firmware_init(cx) == 0)
1081 break;
1082 if (fw_retry_count > 1)
1083 CX18_WARN("Retry loading firmware\n");
1084 }
1085
1086 if (fw_retry_count == 0) {
1087 set_bit(CX18_F_I_FAILED, &cx->i_flags);
1088 return -ENXIO;
1089 }
1090 set_bit(CX18_F_I_LOADED_FW, &cx->i_flags);
1091
Andy Walls350145a2009-01-04 21:51:17 -03001092 /*
1093 * Init the firmware twice to work around a silicon bug
1094 * with the digital TS.
1095 *
1096 * The second firmware load requires us to normalize the APU state,
1097 * or the audio for the first analog capture will be badly incorrect.
1098 *
1099 * I can't seem to call APU_RESETAI and have it succeed without the
1100 * APU capturing audio, so we start and stop it here to do the reset
1101 */
1102
1103 /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */
1104 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1105 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1106 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001107
1108 fw_retry_count = 3;
1109 while (--fw_retry_count > 0) {
1110 /* load firmware */
1111 if (cx18_firmware_init(cx) == 0)
1112 break;
1113 if (fw_retry_count > 1)
1114 CX18_WARN("Retry loading firmware\n");
1115 }
1116
1117 if (fw_retry_count == 0) {
1118 set_bit(CX18_F_I_FAILED, &cx->i_flags);
1119 return -ENXIO;
1120 }
1121
Andy Wallsd5c02f62009-01-30 22:48:40 -03001122 /*
1123 * The second firmware load requires us to normalize the APU state,
1124 * or the audio for the first analog capture will be badly incorrect.
1125 *
1126 * I can't seem to call APU_RESETAI and have it succeed without the
1127 * APU capturing audio, so we start and stop it here to do the reset
1128 */
1129
1130 /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */
1131 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1132 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1133 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1134
Andy Wallsfa3e7032009-02-16 02:23:25 -03001135 /* Init the A/V decoder, if it hasn't been already */
Hans Verkuilcc26b072009-03-29 19:20:26 -03001136 v4l2_subdev_call(cx->sd_av, core, load_fw);
Andy Wallsfa3e7032009-02-16 02:23:25 -03001137
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001138 vf.tuner = 0;
1139 vf.type = V4L2_TUNER_ANALOG_TV;
1140 vf.frequency = 6400; /* the tuner 'baseline' frequency */
1141
1142 /* Set initial frequency. For PAL/SECAM broadcasts no
1143 'default' channel exists AFAIK. */
1144 if (cx->std == V4L2_STD_NTSC_M_JP)
1145 vf.frequency = 1460; /* ch. 1 91250*16/1000 */
1146 else if (cx->std & V4L2_STD_NTSC_M)
1147 vf.frequency = 1076; /* ch. 4 67250*16/1000 */
1148
1149 video_input = cx->active_input;
1150 cx->active_input++; /* Force update of input */
Andy Walls3b6fe582008-06-21 08:36:31 -03001151 cx18_s_input(NULL, &fh, video_input);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001152
1153 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
1154 in one place. */
1155 cx->std++; /* Force full standard initialization */
Andy Walls3b6fe582008-06-21 08:36:31 -03001156 cx18_s_std(NULL, &fh, &cx->tuner_std);
1157 cx18_s_frequency(NULL, &fh, &vf);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001158 return 0;
1159}
1160
Andy Wallsdeed75e2009-04-13 22:22:40 -03001161static void cx18_cancel_in_work_orders(struct cx18 *cx)
Andy Walls18b5dc22008-11-16 17:15:01 -03001162{
1163 int i;
Andy Wallsdeed75e2009-04-13 22:22:40 -03001164 for (i = 0; i < CX18_MAX_IN_WORK_ORDERS; i++)
1165 cancel_work_sync(&cx->in_work_order[i].work);
Andy Walls18b5dc22008-11-16 17:15:01 -03001166}
1167
Andy Walls21a278b2009-04-15 20:45:10 -03001168static void cx18_cancel_out_work_orders(struct cx18 *cx)
1169{
1170 int i;
1171 for (i = 0; i < CX18_MAX_STREAMS; i++)
1172 if (&cx->streams[i].video_dev != NULL)
1173 cancel_work_sync(&cx->streams[i].out_work_order);
1174}
1175
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001176static void cx18_remove(struct pci_dev *pci_dev)
1177{
Andy Walls888cdb02009-01-11 15:08:53 -03001178 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
Andy Walls5811cf92009-02-14 17:08:37 -03001179 struct cx18 *cx = to_cx18(v4l2_dev);
Andy Walls6da6bf52009-02-21 19:53:54 -03001180 int i;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001181
Andy Walls5811cf92009-02-14 17:08:37 -03001182 CX18_DEBUG_INFO("Removing Card\n");
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001183
1184 /* Stop all captures */
1185 CX18_DEBUG_INFO("Stopping all streams\n");
Hans Verkuil31554ae2008-05-25 11:21:27 -03001186 if (atomic_read(&cx->tot_capturing) > 0)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001187 cx18_stop_all_captures(cx);
1188
Andy Walls87116152009-04-13 22:42:43 -03001189 /* Stop interrupts that cause incoming work to be queued */
Andy Wallsb1526422008-08-30 16:03:44 -03001190 cx18_sw1_irq_disable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
Andy Walls87116152009-04-13 22:42:43 -03001191
1192 /* Incoming work can cause outgoing work, so clean up incoming first */
1193 cx18_cancel_in_work_orders(cx);
Andy Walls21a278b2009-04-15 20:45:10 -03001194 cx18_cancel_out_work_orders(cx);
Andy Walls87116152009-04-13 22:42:43 -03001195
1196 /* Stop ack interrupts that may have been needed for work to finish */
Andy Wallsb1526422008-08-30 16:03:44 -03001197 cx18_sw2_irq_disable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001198
1199 cx18_halt_firmware(cx);
1200
Andy Wallsdeed75e2009-04-13 22:22:40 -03001201 destroy_workqueue(cx->in_work_queue);
Andy Walls87116152009-04-13 22:42:43 -03001202 destroy_workqueue(cx->out_work_queue);
Andy Walls572bfea2008-11-25 21:43:05 -03001203
Hans Verkuil3f983872008-05-01 10:31:12 -03001204 cx18_streams_cleanup(cx, 1);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001205
1206 exit_cx18_i2c(cx);
1207
Andy Walls3d059132009-01-10 21:54:39 -03001208 free_irq(cx->pci_dev->irq, (void *)cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001209
Hans Verkuilcba627a2008-05-12 14:48:26 -03001210 cx18_iounmap(cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001211
1212 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
1213
Andy Walls3d059132009-01-10 21:54:39 -03001214 pci_disable_device(cx->pci_dev);
Andy Walls6da6bf52009-02-21 19:53:54 -03001215
1216 if (cx->vbi.sliced_mpeg_data[0] != NULL)
1217 for (i = 0; i < CX18_VBI_FRAMES; i++)
1218 kfree(cx->vbi.sliced_mpeg_data[i]);
Andy Walls5811cf92009-02-14 17:08:37 -03001219
1220 CX18_INFO("Removed %s\n", cx->card_name);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001221
Andy Walls888cdb02009-01-11 15:08:53 -03001222 v4l2_device_unregister(v4l2_dev);
Andy Walls5811cf92009-02-14 17:08:37 -03001223 kfree(cx);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001224}
1225
1226/* define a pci_driver for card detection */
1227static struct pci_driver cx18_pci_driver = {
1228 .name = "cx18",
1229 .id_table = cx18_pci_tbl,
1230 .probe = cx18_probe,
1231 .remove = cx18_remove,
1232};
1233
Peter Huewe9710e7a2009-11-04 15:28:33 -03001234static int __init module_start(void)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001235{
1236 printk(KERN_INFO "cx18: Start initialization, version %s\n", CX18_VERSION);
1237
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001238 /* Validate parameters */
1239 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) {
Hans Verkuildd896012008-10-04 08:36:54 -03001240 printk(KERN_ERR "cx18: Exiting, cx18_first_minor must be between 0 and %d\n",
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001241 CX18_MAX_CARDS - 1);
1242 return -1;
1243 }
1244
1245 if (cx18_debug < 0 || cx18_debug > 511) {
1246 cx18_debug = 0;
1247 printk(KERN_INFO "cx18: Debug value must be >= 0 and <= 511!\n");
1248 }
1249
1250 if (pci_register_driver(&cx18_pci_driver)) {
1251 printk(KERN_ERR "cx18: Error detecting PCI card\n");
1252 return -ENODEV;
1253 }
1254 printk(KERN_INFO "cx18: End initialization\n");
1255 return 0;
1256}
1257
Peter Huewe9710e7a2009-11-04 15:28:33 -03001258static void __exit module_cleanup(void)
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001259{
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001260 pci_unregister_driver(&cx18_pci_driver);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001261}
1262
1263module_init(module_start);
1264module_exit(module_cleanup);