summaryrefslogtreecommitdiff
path: root/drivers/media/pci/solo6x10/solo6x10-core.c
blob: c6e0090f27e81f3fccc1104f47cab36f7a51db47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2010-2013 Bluecherry, LLC <https://www.bluecherrydvr.com>
 *
 * Original author:
 * Ben Collins <bcollins@ubuntu.com>
 *
 * Additional work by:
 * John Brooks <john.brooks@bluecherry.net>
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <linux/videodev2.h>
#include <linux/delay.h>
#include <linux/sysfs.h>
#include <linux/ktime.h>
#include <linux/slab.h>

#include "solo6x10.h"
#include "solo6x10-tw28.h"

MODULE_DESCRIPTION("Softlogic 6x10 MPEG4/H.264/G.723 CODEC V4L2/ALSA Driver");
MODULE_AUTHOR("Bluecherry <maintainers@bluecherrydvr.com>");
MODULE_VERSION(SOLO6X10_VERSION);
MODULE_LICENSE("GPL");

static unsigned video_nr = -1;
module_param(video_nr, uint, 0644);
MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect (default)");

static int full_eeprom; /* default is only top 64B */
module_param(full_eeprom, uint, 0644);
MODULE_PARM_DESC(full_eeprom, "Allow access to full 128B EEPROM (dangerous)");


static void solo_set_time(struct solo_dev *solo_dev)
{
	struct timespec64 ts;

	ktime_get_ts64(&ts);

	/* no overflow because we use monotonic timestamps */
	solo_reg_write(solo_dev, SOLO_TIMER_SEC, (u32)ts.tv_sec);
	solo_reg_write(solo_dev, SOLO_TIMER_USEC, (u32)ts.tv_nsec / NSEC_PER_USEC);
}

static void solo_timer_sync(struct solo_dev *solo_dev)
{
	u32 sec, usec;
	struct timespec64 ts;
	long diff;

	if (solo_dev->type != SOLO_DEV_6110)
		return;

	if (++solo_dev->time_sync < 60)
		return;

	solo_dev->time_sync = 0;

	sec = solo_reg_read(solo_dev, SOLO_TIMER_SEC);
	usec = solo_reg_read(solo_dev, SOLO_TIMER_USEC);

	ktime_get_ts64(&ts);

	diff = (s32)ts.tv_sec - (s32)sec;
	diff = (diff * 1000000)
		+ ((s32)(ts.tv_nsec / NSEC_PER_USEC) - (s32)usec);

	if (diff > 1000 || diff < -1000) {
		solo_set_time(solo_dev);
	} else if (diff) {
		long usec_lsb = solo_dev->usec_lsb;

		usec_lsb -= diff / 4;
		if (usec_lsb < 0)
			usec_lsb = 0;
		else if (usec_lsb > 255)
			usec_lsb = 255;

		solo_dev->usec_lsb = usec_lsb;
		solo_reg_write(solo_dev, SOLO_TIMER_USEC_LSB,
			       solo_dev->usec_lsb);
	}
}

static irqreturn_t solo_isr(int irq, void *data)
{
	struct solo_dev *solo_dev = data;
	u32 status;
	int i;

	status = solo_reg_read(solo_dev, SOLO_IRQ_STAT);
	if (!status)
		return IRQ_NONE;

	/* Acknowledge all interrupts immediately */
	solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);

	if (status & SOLO_IRQ_PCI_ERR)
		solo_p2m_error_isr(solo_dev);

	for (i = 0; i < SOLO_NR_P2M; i++)
		if (status & SOLO_IRQ_P2M(i))
			solo_p2m_isr(solo_dev, i);

	if (status & SOLO_IRQ_IIC)
		solo_i2c_isr(solo_dev);

	if (status & SOLO_IRQ_VIDEO_IN) {
		solo_video_in_isr(solo_dev);
		solo_timer_sync(solo_dev);
	}

	if (status & SOLO_IRQ_ENCODER)
		solo_enc_v4l2_isr(solo_dev);

	if (status & SOLO_IRQ_G723)
		solo_g723_isr(solo_dev);

	return IRQ_HANDLED;
}

static void free_solo_dev(struct solo_dev *solo_dev)
{
	struct pci_dev *pdev = solo_dev->pdev;

	if (solo_dev->dev.parent)
		device_unregister(&solo_dev->dev);

	if (solo_dev->reg_base) {
		/* Bring down the sub-devices first */
		solo_g723_exit(solo_dev);
		solo_enc_v4l2_exit(solo_dev);
		solo_enc_exit(solo_dev);
		solo_v4l2_exit(solo_dev);
		solo_disp_exit(solo_dev);
		solo_gpio_exit(solo_dev);
		solo_p2m_exit(solo_dev);
		solo_i2c_exit(solo_dev);

		/* Now cleanup the PCI device */
		solo_irq_off(solo_dev, ~0);
		free_irq(pdev->irq, solo_dev);
		pci_iounmap(pdev, solo_dev->reg_base);
	}

	pci_release_regions(pdev);
	pci_disable_device(pdev);
	v4l2_device_unregister(&solo_dev->v4l2_dev);
	pci_set_drvdata(pdev, NULL);

	kfree(solo_dev);
}

static ssize_t eeprom_store(struct device *dev, struct device_attribute *attr,
			    const char *buf, size_t count)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	u16 *p = (u16 *)buf;
	int i;

	if (count & 0x1)
		dev_warn(dev, "EEPROM Write not aligned (truncating)\n");

	if (!full_eeprom && count > 64) {
		dev_warn(dev, "EEPROM Write truncated to 64 bytes\n");
		count = 64;
	} else if (full_eeprom && count > 128) {
		dev_warn(dev, "EEPROM Write truncated to 128 bytes\n");
		count = 128;
	}

	solo_eeprom_ewen(solo_dev, 1);

	for (i = full_eeprom ? 0 : 32; i < min((int)(full_eeprom ? 64 : 32),
					       (int)(count / 2)); i++)
		solo_eeprom_write(solo_dev, i, cpu_to_be16(p[i]));

	solo_eeprom_ewen(solo_dev, 0);

	return count;
}

static ssize_t eeprom_show(struct device *dev, struct device_attribute *attr,
			   char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	u16 *p = (u16 *)buf;
	int count = (full_eeprom ? 128 : 64);
	int i;

	for (i = (full_eeprom ? 0 : 32); i < (count / 2); i++)
		p[i] = be16_to_cpu(solo_eeprom_read(solo_dev, i));

	return count;
}

static ssize_t p2m_timeouts_show(struct device *dev,
				 struct device_attribute *attr,
				 char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);

	return sprintf(buf, "%d\n", solo_dev->p2m_timeouts);
}

static ssize_t sdram_size_show(struct device *dev,
			       struct device_attribute *attr,
			       char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);

	return sprintf(buf, "%dMegs\n", solo_dev->sdram_size >> 20);
}

static ssize_t tw28xx_show(struct device *dev,
			   struct device_attribute *attr,
			   char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);

	return sprintf(buf, "tw2815[%d] tw2864[%d] tw2865[%d]\n",
		       hweight32(solo_dev->tw2815),
		       hweight32(solo_dev->tw2864),
		       hweight32(solo_dev->tw2865));
}

static ssize_t input_map_show(struct device *dev,
			      struct device_attribute *attr,
			      char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	unsigned int val;
	char *out = buf;

	val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_0);
	out += sprintf(out, "Channel 0   => Input %d\n", val & 0x1f);
	out += sprintf(out, "Channel 1   => Input %d\n", (val >> 5) & 0x1f);
	out += sprintf(out, "Channel 2   => Input %d\n", (val >> 10) & 0x1f);
	out += sprintf(out, "Channel 3   => Input %d\n", (val >> 15) & 0x1f);
	out += sprintf(out, "Channel 4   => Input %d\n", (val >> 20) & 0x1f);
	out += sprintf(out, "Channel 5   => Input %d\n", (val >> 25) & 0x1f);

	val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_1);
	out += sprintf(out, "Channel 6   => Input %d\n", val & 0x1f);
	out += sprintf(out, "Channel 7   => Input %d\n", (val >> 5) & 0x1f);
	out += sprintf(out, "Channel 8   => Input %d\n", (val >> 10) & 0x1f);
	out += sprintf(out, "Channel 9   => Input %d\n", (val >> 15) & 0x1f);
	out += sprintf(out, "Channel 10  => Input %d\n", (val >> 20) & 0x1f);
	out += sprintf(out, "Channel 11  => Input %d\n", (val >> 25) & 0x1f);

	val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_2);
	out += sprintf(out, "Channel 12  => Input %d\n", val & 0x1f);
	out += sprintf(out, "Channel 13  => Input %d\n", (val >> 5) & 0x1f);
	out += sprintf(out, "Channel 14  => Input %d\n", (val >> 10) & 0x1f);
	out += sprintf(out, "Channel 15  => Input %d\n", (val >> 15) & 0x1f);
	out += sprintf(out, "Spot Output => Input %d\n", (val >> 20) & 0x1f);

	return out - buf;
}

static ssize_t p2m_timeout_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t count)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	unsigned long ms;
	int ret = kstrtoul(buf, 10, &ms);

	if (ret < 0 || ms > 200)
		return -EINVAL;
	solo_dev->p2m_jiffies = msecs_to_jiffies(ms);

	return count;
}

static ssize_t p2m_timeout_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);

	return sprintf(buf, "%ums\n", jiffies_to_msecs(solo_dev->p2m_jiffies));
}

static ssize_t intervals_show(struct device *dev,
			      struct device_attribute *attr,
			      char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	char *out = buf;
	int fps = solo_dev->fps;
	int i;

	for (i = 0; i < solo_dev->nr_chans; i++) {
		out += sprintf(out, "Channel %d: %d/%d (0x%08x)\n",
			       i, solo_dev->v4l2_enc[i]->interval, fps,
			       solo_reg_read(solo_dev, SOLO_CAP_CH_INTV(i)));
	}

	return out - buf;
}

static ssize_t sdram_offsets_show(struct device *dev,
				  struct device_attribute *attr,
				  char *buf)
{
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	char *out = buf;

	out += sprintf(out, "DISP: 0x%08x @ 0x%08x\n",
		       SOLO_DISP_EXT_ADDR,
		       SOLO_DISP_EXT_SIZE);

	out += sprintf(out, "EOSD: 0x%08x @ 0x%08x (0x%08x * %d)\n",
		       SOLO_EOSD_EXT_ADDR,
		       SOLO_EOSD_EXT_AREA(solo_dev),
		       SOLO_EOSD_EXT_SIZE(solo_dev),
		       SOLO_EOSD_EXT_AREA(solo_dev) /
		       SOLO_EOSD_EXT_SIZE(solo_dev));

	out += sprintf(out, "MOTI: 0x%08x @ 0x%08x\n",
		       SOLO_MOTION_EXT_ADDR(solo_dev),
		       SOLO_MOTION_EXT_SIZE);

	out += sprintf(out, "G723: 0x%08x @ 0x%08x\n",
		       SOLO_G723_EXT_ADDR(solo_dev),
		       SOLO_G723_EXT_SIZE);

	out += sprintf(out, "CAPT: 0x%08x @ 0x%08x (0x%08x * %d)\n",
		       SOLO_CAP_EXT_ADDR(solo_dev),
		       SOLO_CAP_EXT_SIZE(solo_dev),
		       SOLO_CAP_PAGE_SIZE,
		       SOLO_CAP_EXT_SIZE(solo_dev) / SOLO_CAP_PAGE_SIZE);

	out += sprintf(out, "EREF: 0x%08x @ 0x%08x (0x%08x * %d)\n",
		       SOLO_EREF_EXT_ADDR(solo_dev),
		       SOLO_EREF_EXT_AREA(solo_dev),
		       SOLO_EREF_EXT_SIZE,
		       SOLO_EREF_EXT_AREA(solo_dev) / SOLO_EREF_EXT_SIZE);

	out += sprintf(out, "MPEG: 0x%08x @ 0x%08x\n",
		       SOLO_MP4E_EXT_ADDR(solo_dev),
		       SOLO_MP4E_EXT_SIZE(solo_dev));

	out += sprintf(out, "JPEG: 0x%08x @ 0x%08x\n",
		       SOLO_JPEG_EXT_ADDR(solo_dev),
		       SOLO_JPEG_EXT_SIZE(solo_dev));

	return out - buf;
}

static ssize_t sdram_show(struct file *file, struct kobject *kobj,
			  struct bin_attribute *a, char *buf,
			  loff_t off, size_t count)
{
	struct device *dev = container_of(kobj, struct device, kobj);
	struct solo_dev *solo_dev =
		container_of(dev, struct solo_dev, dev);
	const int size = solo_dev->sdram_size;

	if (off >= size)
		return 0;

	if (off + count > size)
		count = size - off;

	if (solo_p2m_dma(solo_dev, 0, buf, off, count, 0, 0))
		return -EIO;

	return count;
}

static const struct device_attribute solo_dev_attrs[] = {
	__ATTR(eeprom, 0640, eeprom_show, eeprom_store),
	__ATTR(p2m_timeout, 0644, p2m_timeout_show, p2m_timeout_store),
	__ATTR_RO(p2m_timeouts),
	__ATTR_RO(sdram_size),
	__ATTR_RO(tw28xx),
	__ATTR_RO(input_map),
	__ATTR_RO(intervals),
	__ATTR_RO(sdram_offsets),
};

static void solo_device_release(struct device *dev)
{
	/* Do nothing */
}

static int solo_sysfs_init(struct solo_dev *solo_dev)
{
	struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
	struct device *dev = &solo_dev->dev;
	const char *driver;
	int i;

	if (solo_dev->type == SOLO_DEV_6110)
		driver = "solo6110";
	else
		driver = "solo6010";

	dev->release = solo_device_release;
	dev->parent = &solo_dev->pdev->dev;
	set_dev_node(dev, dev_to_node(&solo_dev->pdev->dev));
	dev_set_name(dev, "%s-%d-%d", driver, solo_dev->vfd->num,
		     solo_dev->nr_chans);

	if (device_register(dev)) {
		dev->parent = NULL;
		return -ENOMEM;
	}

	for (i = 0; i < ARRAY_SIZE(solo_dev_attrs); i++) {
		if (device_create_file(dev, &solo_dev_attrs[i])) {
			device_unregister(dev);
			return -ENOMEM;
		}
	}

	sysfs_attr_init(&sdram_attr->attr);
	sdram_attr->attr.name = "sdram";
	sdram_attr->attr.mode = 0440;
	sdram_attr->read = sdram_show;
	sdram_attr->size = solo_dev->sdram_size;

	if (device_create_bin_file(dev, sdram_attr)) {
		device_unregister(dev);
		return -ENOMEM;
	}

	return 0;
}

static int solo_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
	struct solo_dev *solo_dev;
	int ret;
	u8 chip_id;

	solo_dev = kzalloc(sizeof(*solo_dev), GFP_KERNEL);
	if (solo_dev == NULL)
		return -ENOMEM;

	if (id->driver_data == SOLO_DEV_6010)
		dev_info(&pdev->dev, "Probing Softlogic 6010\n");
	else
		dev_info(&pdev->dev, "Probing Softlogic 6110\n");

	solo_dev->type = id->driver_data;
	solo_dev->pdev = pdev;
	ret = v4l2_device_register(&pdev->dev, &solo_dev->v4l2_dev);
	if (ret)
		goto fail_probe;

	/* Only for during init */
	solo_dev->p2m_jiffies = msecs_to_jiffies(100);

	ret = pci_enable_device(pdev);
	if (ret)
		goto fail_probe;

	pci_set_master(pdev);

	/* RETRY/TRDY Timeout disabled */
	pci_write_config_byte(pdev, 0x40, 0x00);
	pci_write_config_byte(pdev, 0x41, 0x00);

	ret = pci_request_regions(pdev, SOLO6X10_NAME);
	if (ret)
		goto fail_probe;

	solo_dev->reg_base = pci_ioremap_bar(pdev, 0);
	if (solo_dev->reg_base == NULL) {
		ret = -ENOMEM;
		goto fail_probe;
	}

	chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) &
				SOLO_CHIP_ID_MASK;
	switch (chip_id) {
	case 7:
		solo_dev->nr_chans = 16;
		solo_dev->nr_ext = 5;
		break;
	case 6:
		solo_dev->nr_chans = 8;
		solo_dev->nr_ext = 2;
		break;
	default:
		dev_warn(&pdev->dev, "Invalid chip_id 0x%02x, assuming 4 ch\n",
			 chip_id);
		/* fall through */
	case 5:
		solo_dev->nr_chans = 4;
		solo_dev->nr_ext = 1;
	}

	/* Disable all interrupts to start */
	solo_irq_off(solo_dev, ~0);

	/* Initial global settings */
	if (solo_dev->type == SOLO_DEV_6010) {
		solo_dev->clock_mhz = 108;
		solo_dev->sys_config = SOLO_SYS_CFG_SDRAM64BIT
			| SOLO_SYS_CFG_INPUTDIV(25)
			| SOLO_SYS_CFG_FEEDBACKDIV(solo_dev->clock_mhz * 2 - 2)
			| SOLO_SYS_CFG_OUTDIV(3);
		solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
	} else {
		u32 divq, divf;

		solo_dev->clock_mhz = 135;

		if (solo_dev->clock_mhz < 125) {
			divq = 3;
			divf = (solo_dev->clock_mhz * 4) / 3 - 1;
		} else {
			divq = 2;
			divf = (solo_dev->clock_mhz * 2) / 3 - 1;
		}

		solo_reg_write(solo_dev, SOLO_PLL_CONFIG,
			       (1 << 20) | /* PLL_RANGE */
			       (8 << 15) | /* PLL_DIVR  */
			       (divq << 12) |
			       (divf <<  4) |
			       (1 <<  1)   /* PLL_FSEN */);

		solo_dev->sys_config = SOLO_SYS_CFG_SDRAM64BIT;
	}

	solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
	solo_reg_write(solo_dev, SOLO_TIMER_CLOCK_NUM,
		       solo_dev->clock_mhz - 1);

	/* PLL locking time of 1ms */
	mdelay(1);

	ret = request_irq(pdev->irq, solo_isr, IRQF_SHARED, SOLO6X10_NAME,
			  solo_dev);
	if (ret)
		goto fail_probe;

	/* Handle this from the start */
	solo_irq_on(solo_dev, SOLO_IRQ_PCI_ERR);

	ret = solo_i2c_init(solo_dev);
	if (ret)
		goto fail_probe;

	/* Setup the DMA engine */
	solo_reg_write(solo_dev, SOLO_DMA_CTRL,
		       SOLO_DMA_CTRL_REFRESH_CYCLE(1) |
		       SOLO_DMA_CTRL_SDRAM_SIZE(2) |
		       SOLO_DMA_CTRL_SDRAM_CLK_INVERT |
		       SOLO_DMA_CTRL_READ_CLK_SELECT |
		       SOLO_DMA_CTRL_LATENCY(1));

	/* Undocumented crap */
	solo_reg_write(solo_dev, SOLO_DMA_CTRL1,
		       solo_dev->type == SOLO_DEV_6010 ? 0x100 : 0x300);

	if (solo_dev->type != SOLO_DEV_6010) {
		solo_dev->usec_lsb = 0x3f;
		solo_set_time(solo_dev);
	}

	/* Disable watchdog */
	solo_reg_write(solo_dev, SOLO_WATCHDOG, 0);

	/* Initialize sub components */

	ret = solo_p2m_init(solo_dev);
	if (ret)
		goto fail_probe;

	ret = solo_disp_init(solo_dev);
	if (ret)
		goto fail_probe;

	ret = solo_gpio_init(solo_dev);
	if (ret)
		goto fail_probe;

	ret = solo_tw28_init(solo_dev);
	if (ret)
		goto fail_probe;

	ret = solo_v4l2_init(solo_dev, video_nr);
	if (ret)
		goto fail_probe;

	ret = solo_enc_init(solo_dev);
	if (ret)
		goto fail_probe;

	ret = solo_enc_v4l2_init(solo_dev, video_nr);
	if (ret)
		goto fail_probe;

	ret = solo_g723_init(solo_dev);
	if (ret)
		goto fail_probe;

	ret = solo_sysfs_init(solo_dev);
	if (ret)
		goto fail_probe;

	/* Now that init is over, set this lower */
	solo_dev->p2m_jiffies = msecs_to_jiffies(20);

	return 0;

fail_probe:
	free_solo_dev(solo_dev);
	return ret;
}

static void solo_pci_remove(struct pci_dev *pdev)
{
	struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
	struct solo_dev *solo_dev = container_of(v4l2_dev, struct solo_dev, v4l2_dev);

	free_solo_dev(solo_dev);
}

static const struct pci_device_id solo_id_table[] = {
	/* 6010 based cards */
	{ PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6010),
	  .driver_data = SOLO_DEV_6010 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_4),
	  .driver_data = SOLO_DEV_6010 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_9),
	  .driver_data = SOLO_DEV_6010 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_16),
	  .driver_data = SOLO_DEV_6010 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_4),
	  .driver_data = SOLO_DEV_6010 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_9),
	  .driver_data = SOLO_DEV_6010 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_16),
	  .driver_data = SOLO_DEV_6010 },
	/* 6110 based cards */
	{ PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6110),
	  .driver_data = SOLO_DEV_6110 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_4),
	  .driver_data = SOLO_DEV_6110 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_8),
	  .driver_data = SOLO_DEV_6110 },
	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_16),
	  .driver_data = SOLO_DEV_6110 },
	{0,}
};

MODULE_DEVICE_TABLE(pci, solo_id_table);

static struct pci_driver solo_pci_driver = {
	.name = SOLO6X10_NAME,
	.id_table = solo_id_table,
	.probe = solo_pci_probe,
	.remove = solo_pci_remove,
};

module_pci_driver(solo_pci_driver);