1 /*
2  * Copyright (C) 2010-2013 Bluecherry, LLC <http://www.bluecherrydvr.com>
3  *
4  * Original author:
5  * Ben Collins <bcollins@ubuntu.com>
6  *
7  * Additional work by:
8  * John Brooks <john.brooks@bluecherry.net>
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, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25 #include <linux/videodev2.h>
26 #include <linux/delay.h>
27 #include <linux/sysfs.h>
28 #include <linux/ktime.h>
29 #include <linux/slab.h>
30 
31 #include "solo6x10.h"
32 #include "solo6x10-tw28.h"
33 
34 MODULE_DESCRIPTION("Softlogic 6x10 MPEG4/H.264/G.723 CODEC V4L2/ALSA Driver");
35 MODULE_AUTHOR("Bluecherry <maintainers@bluecherrydvr.com>");
36 MODULE_VERSION(SOLO6X10_VERSION);
37 MODULE_LICENSE("GPL");
38 
39 static unsigned video_nr = -1;
40 module_param(video_nr, uint, 0644);
41 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect (default)");
42 
43 static int full_eeprom; /* default is only top 64B */
44 module_param(full_eeprom, uint, 0644);
45 MODULE_PARM_DESC(full_eeprom, "Allow access to full 128B EEPROM (dangerous)");
46 
47 
48 static void solo_set_time(struct solo_dev *solo_dev)
49 {
50 	struct timespec ts;
51 
52 	ktime_get_ts(&ts);
53 
54 	solo_reg_write(solo_dev, SOLO_TIMER_SEC, ts.tv_sec);
55 	solo_reg_write(solo_dev, SOLO_TIMER_USEC, ts.tv_nsec / NSEC_PER_USEC);
56 }
57 
58 static void solo_timer_sync(struct solo_dev *solo_dev)
59 {
60 	u32 sec, usec;
61 	struct timespec ts;
62 	long diff;
63 
64 	if (solo_dev->type != SOLO_DEV_6110)
65 		return;
66 
67 	if (++solo_dev->time_sync < 60)
68 		return;
69 
70 	solo_dev->time_sync = 0;
71 
72 	sec = solo_reg_read(solo_dev, SOLO_TIMER_SEC);
73 	usec = solo_reg_read(solo_dev, SOLO_TIMER_USEC);
74 
75 	ktime_get_ts(&ts);
76 
77 	diff = (long)ts.tv_sec - (long)sec;
78 	diff = (diff * 1000000)
79 		+ ((long)(ts.tv_nsec / NSEC_PER_USEC) - (long)usec);
80 
81 	if (diff > 1000 || diff < -1000) {
82 		solo_set_time(solo_dev);
83 	} else if (diff) {
84 		long usec_lsb = solo_dev->usec_lsb;
85 
86 		usec_lsb -= diff / 4;
87 		if (usec_lsb < 0)
88 			usec_lsb = 0;
89 		else if (usec_lsb > 255)
90 			usec_lsb = 255;
91 
92 		solo_dev->usec_lsb = usec_lsb;
93 		solo_reg_write(solo_dev, SOLO_TIMER_USEC_LSB,
94 			       solo_dev->usec_lsb);
95 	}
96 }
97 
98 static irqreturn_t solo_isr(int irq, void *data)
99 {
100 	struct solo_dev *solo_dev = data;
101 	u32 status;
102 	int i;
103 
104 	status = solo_reg_read(solo_dev, SOLO_IRQ_STAT);
105 	if (!status)
106 		return IRQ_NONE;
107 
108 	if (status & ~solo_dev->irq_mask) {
109 		solo_reg_write(solo_dev, SOLO_IRQ_STAT,
110 			       status & ~solo_dev->irq_mask);
111 		status &= solo_dev->irq_mask;
112 	}
113 
114 	if (status & SOLO_IRQ_PCI_ERR)
115 		solo_p2m_error_isr(solo_dev);
116 
117 	for (i = 0; i < SOLO_NR_P2M; i++)
118 		if (status & SOLO_IRQ_P2M(i))
119 			solo_p2m_isr(solo_dev, i);
120 
121 	if (status & SOLO_IRQ_IIC)
122 		solo_i2c_isr(solo_dev);
123 
124 	if (status & SOLO_IRQ_VIDEO_IN) {
125 		solo_video_in_isr(solo_dev);
126 		solo_timer_sync(solo_dev);
127 	}
128 
129 	if (status & SOLO_IRQ_ENCODER)
130 		solo_enc_v4l2_isr(solo_dev);
131 
132 	if (status & SOLO_IRQ_G723)
133 		solo_g723_isr(solo_dev);
134 
135 	/* Clear all interrupts handled */
136 	solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);
137 
138 	return IRQ_HANDLED;
139 }
140 
141 static void free_solo_dev(struct solo_dev *solo_dev)
142 {
143 	struct pci_dev *pdev;
144 
145 	if (!solo_dev)
146 		return;
147 
148 	if (solo_dev->dev.parent)
149 		device_unregister(&solo_dev->dev);
150 
151 	pdev = solo_dev->pdev;
152 
153 	/* If we never initialized the PCI device, then nothing else
154 	 * below here needs cleanup */
155 	if (!pdev) {
156 		kfree(solo_dev);
157 		return;
158 	}
159 
160 	if (solo_dev->reg_base) {
161 		/* Bring down the sub-devices first */
162 		solo_g723_exit(solo_dev);
163 		solo_enc_v4l2_exit(solo_dev);
164 		solo_enc_exit(solo_dev);
165 		solo_v4l2_exit(solo_dev);
166 		solo_disp_exit(solo_dev);
167 		solo_gpio_exit(solo_dev);
168 		solo_p2m_exit(solo_dev);
169 		solo_i2c_exit(solo_dev);
170 
171 		/* Now cleanup the PCI device */
172 		solo_irq_off(solo_dev, ~0);
173 		pci_iounmap(pdev, solo_dev->reg_base);
174 		if (pdev->irq)
175 			free_irq(pdev->irq, solo_dev);
176 	}
177 
178 	pci_release_regions(pdev);
179 	pci_disable_device(pdev);
180 	v4l2_device_unregister(&solo_dev->v4l2_dev);
181 	pci_set_drvdata(pdev, NULL);
182 
183 	kfree(solo_dev);
184 }
185 
186 static ssize_t eeprom_store(struct device *dev, struct device_attribute *attr,
187 			    const char *buf, size_t count)
188 {
189 	struct solo_dev *solo_dev =
190 		container_of(dev, struct solo_dev, dev);
191 	unsigned short *p = (unsigned short *)buf;
192 	int i;
193 
194 	if (count & 0x1)
195 		dev_warn(dev, "EEPROM Write not aligned (truncating)\n");
196 
197 	if (!full_eeprom && count > 64) {
198 		dev_warn(dev, "EEPROM Write truncated to 64 bytes\n");
199 		count = 64;
200 	} else if (full_eeprom && count > 128) {
201 		dev_warn(dev, "EEPROM Write truncated to 128 bytes\n");
202 		count = 128;
203 	}
204 
205 	solo_eeprom_ewen(solo_dev, 1);
206 
207 	for (i = full_eeprom ? 0 : 32; i < min((int)(full_eeprom ? 64 : 32),
208 					       (int)(count / 2)); i++)
209 		solo_eeprom_write(solo_dev, i, cpu_to_be16(p[i]));
210 
211 	solo_eeprom_ewen(solo_dev, 0);
212 
213 	return count;
214 }
215 
216 static ssize_t eeprom_show(struct device *dev, struct device_attribute *attr,
217 			   char *buf)
218 {
219 	struct solo_dev *solo_dev =
220 		container_of(dev, struct solo_dev, dev);
221 	unsigned short *p = (unsigned short *)buf;
222 	int count = (full_eeprom ? 128 : 64);
223 	int i;
224 
225 	for (i = (full_eeprom ? 0 : 32); i < (count / 2); i++)
226 		p[i] = be16_to_cpu(solo_eeprom_read(solo_dev, i));
227 
228 	return count;
229 }
230 
231 static ssize_t p2m_timeouts_show(struct device *dev,
232 				 struct device_attribute *attr,
233 				 char *buf)
234 {
235 	struct solo_dev *solo_dev =
236 		container_of(dev, struct solo_dev, dev);
237 
238 	return sprintf(buf, "%d\n", solo_dev->p2m_timeouts);
239 }
240 
241 static ssize_t sdram_size_show(struct device *dev,
242 			       struct device_attribute *attr,
243 			       char *buf)
244 {
245 	struct solo_dev *solo_dev =
246 		container_of(dev, struct solo_dev, dev);
247 
248 	return sprintf(buf, "%dMegs\n", solo_dev->sdram_size >> 20);
249 }
250 
251 static ssize_t tw28xx_show(struct device *dev,
252 			   struct device_attribute *attr,
253 			   char *buf)
254 {
255 	struct solo_dev *solo_dev =
256 		container_of(dev, struct solo_dev, dev);
257 
258 	return sprintf(buf, "tw2815[%d] tw2864[%d] tw2865[%d]\n",
259 		       hweight32(solo_dev->tw2815),
260 		       hweight32(solo_dev->tw2864),
261 		       hweight32(solo_dev->tw2865));
262 }
263 
264 static ssize_t input_map_show(struct device *dev,
265 			      struct device_attribute *attr,
266 			      char *buf)
267 {
268 	struct solo_dev *solo_dev =
269 		container_of(dev, struct solo_dev, dev);
270 	unsigned int val;
271 	char *out = buf;
272 
273 	val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_0);
274 	out += sprintf(out, "Channel 0   => Input %d\n", val & 0x1f);
275 	out += sprintf(out, "Channel 1   => Input %d\n", (val >> 5) & 0x1f);
276 	out += sprintf(out, "Channel 2   => Input %d\n", (val >> 10) & 0x1f);
277 	out += sprintf(out, "Channel 3   => Input %d\n", (val >> 15) & 0x1f);
278 	out += sprintf(out, "Channel 4   => Input %d\n", (val >> 20) & 0x1f);
279 	out += sprintf(out, "Channel 5   => Input %d\n", (val >> 25) & 0x1f);
280 
281 	val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_1);
282 	out += sprintf(out, "Channel 6   => Input %d\n", val & 0x1f);
283 	out += sprintf(out, "Channel 7   => Input %d\n", (val >> 5) & 0x1f);
284 	out += sprintf(out, "Channel 8   => Input %d\n", (val >> 10) & 0x1f);
285 	out += sprintf(out, "Channel 9   => Input %d\n", (val >> 15) & 0x1f);
286 	out += sprintf(out, "Channel 10  => Input %d\n", (val >> 20) & 0x1f);
287 	out += sprintf(out, "Channel 11  => Input %d\n", (val >> 25) & 0x1f);
288 
289 	val = solo_reg_read(solo_dev, SOLO_VI_CH_SWITCH_2);
290 	out += sprintf(out, "Channel 12  => Input %d\n", val & 0x1f);
291 	out += sprintf(out, "Channel 13  => Input %d\n", (val >> 5) & 0x1f);
292 	out += sprintf(out, "Channel 14  => Input %d\n", (val >> 10) & 0x1f);
293 	out += sprintf(out, "Channel 15  => Input %d\n", (val >> 15) & 0x1f);
294 	out += sprintf(out, "Spot Output => Input %d\n", (val >> 20) & 0x1f);
295 
296 	return out - buf;
297 }
298 
299 static ssize_t p2m_timeout_store(struct device *dev,
300 				 struct device_attribute *attr,
301 				 const char *buf, size_t count)
302 {
303 	struct solo_dev *solo_dev =
304 		container_of(dev, struct solo_dev, dev);
305 	unsigned long ms;
306 	int ret = kstrtoul(buf, 10, &ms);
307 
308 	if (ret < 0 || ms > 200)
309 		return -EINVAL;
310 	solo_dev->p2m_jiffies = msecs_to_jiffies(ms);
311 
312 	return count;
313 }
314 
315 static ssize_t p2m_timeout_show(struct device *dev,
316 				struct device_attribute *attr,
317 				char *buf)
318 {
319 	struct solo_dev *solo_dev =
320 		container_of(dev, struct solo_dev, dev);
321 
322 	return sprintf(buf, "%ums\n", jiffies_to_msecs(solo_dev->p2m_jiffies));
323 }
324 
325 static ssize_t intervals_show(struct device *dev,
326 			      struct device_attribute *attr,
327 			      char *buf)
328 {
329 	struct solo_dev *solo_dev =
330 		container_of(dev, struct solo_dev, dev);
331 	char *out = buf;
332 	int fps = solo_dev->fps;
333 	int i;
334 
335 	for (i = 0; i < solo_dev->nr_chans; i++) {
336 		out += sprintf(out, "Channel %d: %d/%d (0x%08x)\n",
337 			       i, solo_dev->v4l2_enc[i]->interval, fps,
338 			       solo_reg_read(solo_dev, SOLO_CAP_CH_INTV(i)));
339 	}
340 
341 	return out - buf;
342 }
343 
344 static ssize_t sdram_offsets_show(struct device *dev,
345 				  struct device_attribute *attr,
346 				  char *buf)
347 {
348 	struct solo_dev *solo_dev =
349 		container_of(dev, struct solo_dev, dev);
350 	char *out = buf;
351 
352 	out += sprintf(out, "DISP: 0x%08x @ 0x%08x\n",
353 		       SOLO_DISP_EXT_ADDR,
354 		       SOLO_DISP_EXT_SIZE);
355 
356 	out += sprintf(out, "EOSD: 0x%08x @ 0x%08x (0x%08x * %d)\n",
357 		       SOLO_EOSD_EXT_ADDR,
358 		       SOLO_EOSD_EXT_AREA(solo_dev),
359 		       SOLO_EOSD_EXT_SIZE(solo_dev),
360 		       SOLO_EOSD_EXT_AREA(solo_dev) /
361 		       SOLO_EOSD_EXT_SIZE(solo_dev));
362 
363 	out += sprintf(out, "MOTI: 0x%08x @ 0x%08x\n",
364 		       SOLO_MOTION_EXT_ADDR(solo_dev),
365 		       SOLO_MOTION_EXT_SIZE);
366 
367 	out += sprintf(out, "G723: 0x%08x @ 0x%08x\n",
368 		       SOLO_G723_EXT_ADDR(solo_dev),
369 		       SOLO_G723_EXT_SIZE);
370 
371 	out += sprintf(out, "CAPT: 0x%08x @ 0x%08x (0x%08x * %d)\n",
372 		       SOLO_CAP_EXT_ADDR(solo_dev),
373 		       SOLO_CAP_EXT_SIZE(solo_dev),
374 		       SOLO_CAP_PAGE_SIZE,
375 		       SOLO_CAP_EXT_SIZE(solo_dev) / SOLO_CAP_PAGE_SIZE);
376 
377 	out += sprintf(out, "EREF: 0x%08x @ 0x%08x (0x%08x * %d)\n",
378 		       SOLO_EREF_EXT_ADDR(solo_dev),
379 		       SOLO_EREF_EXT_AREA(solo_dev),
380 		       SOLO_EREF_EXT_SIZE,
381 		       SOLO_EREF_EXT_AREA(solo_dev) / SOLO_EREF_EXT_SIZE);
382 
383 	out += sprintf(out, "MPEG: 0x%08x @ 0x%08x\n",
384 		       SOLO_MP4E_EXT_ADDR(solo_dev),
385 		       SOLO_MP4E_EXT_SIZE(solo_dev));
386 
387 	out += sprintf(out, "JPEG: 0x%08x @ 0x%08x\n",
388 		       SOLO_JPEG_EXT_ADDR(solo_dev),
389 		       SOLO_JPEG_EXT_SIZE(solo_dev));
390 
391 	return out - buf;
392 }
393 
394 static ssize_t sdram_show(struct file *file, struct kobject *kobj,
395 			  struct bin_attribute *a, char *buf,
396 			  loff_t off, size_t count)
397 {
398 	struct device *dev = container_of(kobj, struct device, kobj);
399 	struct solo_dev *solo_dev =
400 		container_of(dev, struct solo_dev, dev);
401 	const int size = solo_dev->sdram_size;
402 
403 	if (off >= size)
404 		return 0;
405 
406 	if (off + count > size)
407 		count = size - off;
408 
409 	if (solo_p2m_dma(solo_dev, 0, buf, off, count, 0, 0))
410 		return -EIO;
411 
412 	return count;
413 }
414 
415 static const struct device_attribute solo_dev_attrs[] = {
416 	__ATTR(eeprom, 0640, eeprom_show, eeprom_store),
417 	__ATTR(p2m_timeout, 0644, p2m_timeout_show, p2m_timeout_store),
418 	__ATTR_RO(p2m_timeouts),
419 	__ATTR_RO(sdram_size),
420 	__ATTR_RO(tw28xx),
421 	__ATTR_RO(input_map),
422 	__ATTR_RO(intervals),
423 	__ATTR_RO(sdram_offsets),
424 };
425 
426 static void solo_device_release(struct device *dev)
427 {
428 	/* Do nothing */
429 }
430 
431 static int solo_sysfs_init(struct solo_dev *solo_dev)
432 {
433 	struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
434 	struct device *dev = &solo_dev->dev;
435 	const char *driver;
436 	int i;
437 
438 	if (solo_dev->type == SOLO_DEV_6110)
439 		driver = "solo6110";
440 	else
441 		driver = "solo6010";
442 
443 	dev->release = solo_device_release;
444 	dev->parent = &solo_dev->pdev->dev;
445 	set_dev_node(dev, dev_to_node(&solo_dev->pdev->dev));
446 	dev_set_name(dev, "%s-%d-%d", driver, solo_dev->vfd->num,
447 		     solo_dev->nr_chans);
448 
449 	if (device_register(dev)) {
450 		dev->parent = NULL;
451 		return -ENOMEM;
452 	}
453 
454 	for (i = 0; i < ARRAY_SIZE(solo_dev_attrs); i++) {
455 		if (device_create_file(dev, &solo_dev_attrs[i])) {
456 			device_unregister(dev);
457 			return -ENOMEM;
458 		}
459 	}
460 
461 	sysfs_attr_init(&sdram_attr->attr);
462 	sdram_attr->attr.name = "sdram";
463 	sdram_attr->attr.mode = 0440;
464 	sdram_attr->read = sdram_show;
465 	sdram_attr->size = solo_dev->sdram_size;
466 
467 	if (device_create_bin_file(dev, sdram_attr)) {
468 		device_unregister(dev);
469 		return -ENOMEM;
470 	}
471 
472 	return 0;
473 }
474 
475 static int solo_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
476 {
477 	struct solo_dev *solo_dev;
478 	int ret;
479 	u8 chip_id;
480 
481 	solo_dev = kzalloc(sizeof(*solo_dev), GFP_KERNEL);
482 	if (solo_dev == NULL)
483 		return -ENOMEM;
484 
485 	if (id->driver_data == SOLO_DEV_6010)
486 		dev_info(&pdev->dev, "Probing Softlogic 6010\n");
487 	else
488 		dev_info(&pdev->dev, "Probing Softlogic 6110\n");
489 
490 	solo_dev->type = id->driver_data;
491 	solo_dev->pdev = pdev;
492 	spin_lock_init(&solo_dev->reg_io_lock);
493 	ret = v4l2_device_register(&pdev->dev, &solo_dev->v4l2_dev);
494 	if (ret)
495 		goto fail_probe;
496 
497 	/* Only for during init */
498 	solo_dev->p2m_jiffies = msecs_to_jiffies(100);
499 
500 	ret = pci_enable_device(pdev);
501 	if (ret)
502 		goto fail_probe;
503 
504 	pci_set_master(pdev);
505 
506 	/* RETRY/TRDY Timeout disabled */
507 	pci_write_config_byte(pdev, 0x40, 0x00);
508 	pci_write_config_byte(pdev, 0x41, 0x00);
509 
510 	ret = pci_request_regions(pdev, SOLO6X10_NAME);
511 	if (ret)
512 		goto fail_probe;
513 
514 	solo_dev->reg_base = pci_ioremap_bar(pdev, 0);
515 	if (solo_dev->reg_base == NULL) {
516 		ret = -ENOMEM;
517 		goto fail_probe;
518 	}
519 
520 	chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) &
521 				SOLO_CHIP_ID_MASK;
522 	switch (chip_id) {
523 	case 7:
524 		solo_dev->nr_chans = 16;
525 		solo_dev->nr_ext = 5;
526 		break;
527 	case 6:
528 		solo_dev->nr_chans = 8;
529 		solo_dev->nr_ext = 2;
530 		break;
531 	default:
532 		dev_warn(&pdev->dev, "Invalid chip_id 0x%02x, assuming 4 ch\n",
533 			 chip_id);
534 	case 5:
535 		solo_dev->nr_chans = 4;
536 		solo_dev->nr_ext = 1;
537 	}
538 
539 	/* Disable all interrupts to start */
540 	solo_irq_off(solo_dev, ~0);
541 
542 	/* Initial global settings */
543 	if (solo_dev->type == SOLO_DEV_6010) {
544 		solo_dev->clock_mhz = 108;
545 		solo_dev->sys_config = SOLO_SYS_CFG_SDRAM64BIT
546 			| SOLO_SYS_CFG_INPUTDIV(25)
547 			| SOLO_SYS_CFG_FEEDBACKDIV(solo_dev->clock_mhz * 2 - 2)
548 			| SOLO_SYS_CFG_OUTDIV(3);
549 		solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
550 	} else {
551 		u32 divq, divf;
552 
553 		solo_dev->clock_mhz = 135;
554 
555 		if (solo_dev->clock_mhz < 125) {
556 			divq = 3;
557 			divf = (solo_dev->clock_mhz * 4) / 3 - 1;
558 		} else {
559 			divq = 2;
560 			divf = (solo_dev->clock_mhz * 2) / 3 - 1;
561 		}
562 
563 		solo_reg_write(solo_dev, SOLO_PLL_CONFIG,
564 			       (1 << 20) | /* PLL_RANGE */
565 			       (8 << 15) | /* PLL_DIVR  */
566 			       (divq << 12) |
567 			       (divf <<  4) |
568 			       (1 <<  1)   /* PLL_FSEN */);
569 
570 		solo_dev->sys_config = SOLO_SYS_CFG_SDRAM64BIT;
571 	}
572 
573 	solo_reg_write(solo_dev, SOLO_SYS_CFG, solo_dev->sys_config);
574 	solo_reg_write(solo_dev, SOLO_TIMER_CLOCK_NUM,
575 		       solo_dev->clock_mhz - 1);
576 
577 	/* PLL locking time of 1ms */
578 	mdelay(1);
579 
580 	ret = request_irq(pdev->irq, solo_isr, IRQF_SHARED, SOLO6X10_NAME,
581 			  solo_dev);
582 	if (ret)
583 		goto fail_probe;
584 
585 	/* Handle this from the start */
586 	solo_irq_on(solo_dev, SOLO_IRQ_PCI_ERR);
587 
588 	ret = solo_i2c_init(solo_dev);
589 	if (ret)
590 		goto fail_probe;
591 
592 	/* Setup the DMA engine */
593 	solo_reg_write(solo_dev, SOLO_DMA_CTRL,
594 		       SOLO_DMA_CTRL_REFRESH_CYCLE(1) |
595 		       SOLO_DMA_CTRL_SDRAM_SIZE(2) |
596 		       SOLO_DMA_CTRL_SDRAM_CLK_INVERT |
597 		       SOLO_DMA_CTRL_READ_CLK_SELECT |
598 		       SOLO_DMA_CTRL_LATENCY(1));
599 
600 	/* Undocumented crap */
601 	solo_reg_write(solo_dev, SOLO_DMA_CTRL1,
602 		       solo_dev->type == SOLO_DEV_6010 ? 0x100 : 0x300);
603 
604 	if (solo_dev->type != SOLO_DEV_6010) {
605 		solo_dev->usec_lsb = 0x3f;
606 		solo_set_time(solo_dev);
607 	}
608 
609 	/* Disable watchdog */
610 	solo_reg_write(solo_dev, SOLO_WATCHDOG, 0);
611 
612 	/* Initialize sub components */
613 
614 	ret = solo_p2m_init(solo_dev);
615 	if (ret)
616 		goto fail_probe;
617 
618 	ret = solo_disp_init(solo_dev);
619 	if (ret)
620 		goto fail_probe;
621 
622 	ret = solo_gpio_init(solo_dev);
623 	if (ret)
624 		goto fail_probe;
625 
626 	ret = solo_tw28_init(solo_dev);
627 	if (ret)
628 		goto fail_probe;
629 
630 	ret = solo_v4l2_init(solo_dev, video_nr);
631 	if (ret)
632 		goto fail_probe;
633 
634 	ret = solo_enc_init(solo_dev);
635 	if (ret)
636 		goto fail_probe;
637 
638 	ret = solo_enc_v4l2_init(solo_dev, video_nr);
639 	if (ret)
640 		goto fail_probe;
641 
642 	ret = solo_g723_init(solo_dev);
643 	if (ret)
644 		goto fail_probe;
645 
646 	ret = solo_sysfs_init(solo_dev);
647 	if (ret)
648 		goto fail_probe;
649 
650 	/* Now that init is over, set this lower */
651 	solo_dev->p2m_jiffies = msecs_to_jiffies(20);
652 
653 	return 0;
654 
655 fail_probe:
656 	free_solo_dev(solo_dev);
657 	return ret;
658 }
659 
660 static void solo_pci_remove(struct pci_dev *pdev)
661 {
662 	struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
663 	struct solo_dev *solo_dev = container_of(v4l2_dev, struct solo_dev, v4l2_dev);
664 
665 	free_solo_dev(solo_dev);
666 }
667 
668 static const struct pci_device_id solo_id_table[] = {
669 	/* 6010 based cards */
670 	{ PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6010),
671 	  .driver_data = SOLO_DEV_6010 },
672 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_4),
673 	  .driver_data = SOLO_DEV_6010 },
674 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_9),
675 	  .driver_data = SOLO_DEV_6010 },
676 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_16),
677 	  .driver_data = SOLO_DEV_6010 },
678 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_4),
679 	  .driver_data = SOLO_DEV_6010 },
680 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_9),
681 	  .driver_data = SOLO_DEV_6010 },
682 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_16),
683 	  .driver_data = SOLO_DEV_6010 },
684 	/* 6110 based cards */
685 	{ PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6110),
686 	  .driver_data = SOLO_DEV_6110 },
687 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_4),
688 	  .driver_data = SOLO_DEV_6110 },
689 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_8),
690 	  .driver_data = SOLO_DEV_6110 },
691 	{ PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_16),
692 	  .driver_data = SOLO_DEV_6110 },
693 	{0,}
694 };
695 
696 MODULE_DEVICE_TABLE(pci, solo_id_table);
697 
698 static struct pci_driver solo_pci_driver = {
699 	.name = SOLO6X10_NAME,
700 	.id_table = solo_id_table,
701 	.probe = solo_pci_probe,
702 	.remove = solo_pci_remove,
703 };
704 
705 module_pci_driver(solo_pci_driver);
706