solo6x10-core.c 18 KB

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