go7007-driver.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * Copyright (C) 2005-2006 Micronas USA Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/delay.h>
  20. #include <linux/sched.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/unistd.h>
  23. #include <linux/time.h>
  24. #include <linux/mm.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/device.h>
  27. #include <linux/i2c.h>
  28. #include <linux/firmware.h>
  29. #include <linux/mutex.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/slab.h>
  32. #include <asm/system.h>
  33. #include <linux/videodev2.h>
  34. #include <media/tuner.h>
  35. #include <media/v4l2-common.h>
  36. #include "go7007-priv.h"
  37. #include "wis-i2c.h"
  38. /*
  39. * Wait for an interrupt to be delivered from the GO7007SB and return
  40. * the associated value and data.
  41. *
  42. * Must be called with the hw_lock held.
  43. */
  44. int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data)
  45. {
  46. go->interrupt_available = 0;
  47. go->hpi_ops->read_interrupt(go);
  48. if (wait_event_timeout(go->interrupt_waitq,
  49. go->interrupt_available, 5*HZ) < 0) {
  50. v4l2_err(&go->v4l2_dev, "timeout waiting for read interrupt\n");
  51. return -1;
  52. }
  53. if (!go->interrupt_available)
  54. return -1;
  55. go->interrupt_available = 0;
  56. *value = go->interrupt_value & 0xfffe;
  57. *data = go->interrupt_data;
  58. return 0;
  59. }
  60. EXPORT_SYMBOL(go7007_read_interrupt);
  61. /*
  62. * Read a register/address on the GO7007SB.
  63. *
  64. * Must be called with the hw_lock held.
  65. */
  66. int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data)
  67. {
  68. int count = 100;
  69. u16 value;
  70. if (go7007_write_interrupt(go, 0x0010, addr) < 0)
  71. return -EIO;
  72. while (count-- > 0) {
  73. if (go7007_read_interrupt(go, &value, data) == 0 &&
  74. value == 0xa000)
  75. return 0;
  76. }
  77. return -EIO;
  78. }
  79. EXPORT_SYMBOL(go7007_read_addr);
  80. /*
  81. * Send the boot firmware to the encoder, which just wakes it up and lets
  82. * us talk to the GPIO pins and on-board I2C adapter.
  83. *
  84. * Must be called with the hw_lock held.
  85. */
  86. static int go7007_load_encoder(struct go7007 *go)
  87. {
  88. const struct firmware *fw_entry;
  89. char fw_name[] = "go7007fw.bin";
  90. void *bounce;
  91. int fw_len, rv = 0;
  92. u16 intr_val, intr_data;
  93. if (request_firmware(&fw_entry, fw_name, go->dev)) {
  94. v4l2_err(go, "unable to load firmware from file "
  95. "\"%s\"\n", fw_name);
  96. return -1;
  97. }
  98. if (fw_entry->size < 16 || memcmp(fw_entry->data, "WISGO7007FW", 11)) {
  99. v4l2_err(go, "file \"%s\" does not appear to be "
  100. "go7007 firmware\n", fw_name);
  101. release_firmware(fw_entry);
  102. return -1;
  103. }
  104. fw_len = fw_entry->size - 16;
  105. bounce = kmalloc(fw_len, GFP_KERNEL);
  106. if (bounce == NULL) {
  107. v4l2_err(go, "unable to allocate %d bytes for "
  108. "firmware transfer\n", fw_len);
  109. release_firmware(fw_entry);
  110. return -1;
  111. }
  112. memcpy(bounce, fw_entry->data + 16, fw_len);
  113. release_firmware(fw_entry);
  114. if (go7007_interface_reset(go) < 0 ||
  115. go7007_send_firmware(go, bounce, fw_len) < 0 ||
  116. go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
  117. (intr_val & ~0x1) != 0x5a5a) {
  118. v4l2_err(go, "error transferring firmware\n");
  119. rv = -1;
  120. }
  121. kfree(bounce);
  122. return rv;
  123. }
  124. MODULE_FIRMWARE("go7007fw.bin");
  125. /*
  126. * Boot the encoder and register the I2C adapter if requested. Do the
  127. * minimum initialization necessary, since the board-specific code may
  128. * still need to probe the board ID.
  129. *
  130. * Must NOT be called with the hw_lock held.
  131. */
  132. int go7007_boot_encoder(struct go7007 *go, int init_i2c)
  133. {
  134. int ret;
  135. mutex_lock(&go->hw_lock);
  136. ret = go7007_load_encoder(go);
  137. mutex_unlock(&go->hw_lock);
  138. if (ret < 0)
  139. return -1;
  140. if (!init_i2c)
  141. return 0;
  142. if (go7007_i2c_init(go) < 0)
  143. return -1;
  144. go->i2c_adapter_online = 1;
  145. return 0;
  146. }
  147. EXPORT_SYMBOL(go7007_boot_encoder);
  148. /*
  149. * Configure any hardware-related registers in the GO7007, such as GPIO
  150. * pins and bus parameters, which are board-specific. This assumes
  151. * the boot firmware has already been downloaded.
  152. *
  153. * Must be called with the hw_lock held.
  154. */
  155. static int go7007_init_encoder(struct go7007 *go)
  156. {
  157. if (go->board_info->audio_flags & GO7007_AUDIO_I2S_MASTER) {
  158. go7007_write_addr(go, 0x1000, 0x0811);
  159. go7007_write_addr(go, 0x1000, 0x0c11);
  160. }
  161. if (go->board_id == GO7007_BOARDID_MATRIX_REV) {
  162. /* Set GPIO pin 0 to be an output (audio clock control) */
  163. go7007_write_addr(go, 0x3c82, 0x0001);
  164. go7007_write_addr(go, 0x3c80, 0x00fe);
  165. }
  166. return 0;
  167. }
  168. /*
  169. * Send the boot firmware to the GO7007 and configure the registers. This
  170. * is the only way to stop the encoder once it has started streaming video.
  171. *
  172. * Must be called with the hw_lock held.
  173. */
  174. int go7007_reset_encoder(struct go7007 *go)
  175. {
  176. if (go7007_load_encoder(go) < 0)
  177. return -1;
  178. return go7007_init_encoder(go);
  179. }
  180. /*
  181. * Attempt to instantiate an I2C client by ID, probably loading a module.
  182. */
  183. static int init_i2c_module(struct i2c_adapter *adapter, const char *type,
  184. int addr)
  185. {
  186. struct go7007 *go = i2c_get_adapdata(adapter);
  187. struct v4l2_device *v4l2_dev = &go->v4l2_dev;
  188. if (v4l2_i2c_new_subdev(v4l2_dev, adapter, type, addr, NULL))
  189. return 0;
  190. printk(KERN_INFO "go7007: probing for module i2c:%s failed\n", type);
  191. return -1;
  192. }
  193. /*
  194. * Finalize the GO7007 hardware setup, register the on-board I2C adapter
  195. * (if used on this board), load the I2C client driver for the sensor
  196. * (SAA7115 or whatever) and other devices, and register the ALSA and V4L2
  197. * interfaces.
  198. *
  199. * Must NOT be called with the hw_lock held.
  200. */
  201. int go7007_register_encoder(struct go7007 *go)
  202. {
  203. int i, ret;
  204. printk(KERN_INFO "go7007: registering new %s\n", go->name);
  205. mutex_lock(&go->hw_lock);
  206. ret = go7007_init_encoder(go);
  207. mutex_unlock(&go->hw_lock);
  208. if (ret < 0)
  209. return -1;
  210. /* v4l2 init must happen before i2c subdevs */
  211. ret = go7007_v4l2_init(go);
  212. if (ret < 0)
  213. return ret;
  214. if (!go->i2c_adapter_online &&
  215. go->board_info->flags & GO7007_BOARD_USE_ONBOARD_I2C) {
  216. if (go7007_i2c_init(go) < 0)
  217. return -1;
  218. go->i2c_adapter_online = 1;
  219. }
  220. if (go->i2c_adapter_online) {
  221. for (i = 0; i < go->board_info->num_i2c_devs; ++i)
  222. init_i2c_module(&go->i2c_adapter,
  223. go->board_info->i2c_devs[i].type,
  224. go->board_info->i2c_devs[i].addr);
  225. if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
  226. i2c_clients_command(&go->i2c_adapter,
  227. DECODER_SET_CHANNEL, &go->channel_number);
  228. }
  229. if (go->board_info->flags & GO7007_BOARD_HAS_AUDIO) {
  230. go->audio_enabled = 1;
  231. go7007_snd_init(go);
  232. }
  233. return 0;
  234. }
  235. EXPORT_SYMBOL(go7007_register_encoder);
  236. /*
  237. * Send the encode firmware to the encoder, which will cause it
  238. * to immediately start delivering the video and audio streams.
  239. *
  240. * Must be called with the hw_lock held.
  241. */
  242. int go7007_start_encoder(struct go7007 *go)
  243. {
  244. u8 *fw;
  245. int fw_len, rv = 0, i;
  246. u16 intr_val, intr_data;
  247. go->modet_enable = 0;
  248. if (!go->dvd_mode)
  249. for (i = 0; i < 4; ++i) {
  250. if (go->modet[i].enable) {
  251. go->modet_enable = 1;
  252. continue;
  253. }
  254. go->modet[i].pixel_threshold = 32767;
  255. go->modet[i].motion_threshold = 32767;
  256. go->modet[i].mb_threshold = 32767;
  257. }
  258. if (go7007_construct_fw_image(go, &fw, &fw_len) < 0)
  259. return -1;
  260. if (go7007_send_firmware(go, fw, fw_len) < 0 ||
  261. go7007_read_interrupt(go, &intr_val, &intr_data) < 0) {
  262. v4l2_err(&go->v4l2_dev, "error transferring firmware\n");
  263. rv = -1;
  264. goto start_error;
  265. }
  266. go->state = STATE_DATA;
  267. go->parse_length = 0;
  268. go->seen_frame = 0;
  269. if (go7007_stream_start(go) < 0) {
  270. v4l2_err(&go->v4l2_dev, "error starting stream transfer\n");
  271. rv = -1;
  272. goto start_error;
  273. }
  274. start_error:
  275. kfree(fw);
  276. return rv;
  277. }
  278. /*
  279. * Store a byte in the current video buffer, if there is one.
  280. */
  281. static inline void store_byte(struct go7007_buffer *gobuf, u8 byte)
  282. {
  283. if (gobuf != NULL && gobuf->bytesused < GO7007_BUF_SIZE) {
  284. unsigned int pgidx = gobuf->offset >> PAGE_SHIFT;
  285. unsigned int pgoff = gobuf->offset & ~PAGE_MASK;
  286. *((u8 *)page_address(gobuf->pages[pgidx]) + pgoff) = byte;
  287. ++gobuf->offset;
  288. ++gobuf->bytesused;
  289. }
  290. }
  291. /*
  292. * Deliver the last video buffer and get a new one to start writing to.
  293. */
  294. static void frame_boundary(struct go7007 *go)
  295. {
  296. struct go7007_buffer *gobuf;
  297. int i;
  298. if (go->active_buf) {
  299. if (go->active_buf->modet_active) {
  300. if (go->active_buf->bytesused + 216 < GO7007_BUF_SIZE) {
  301. for (i = 0; i < 216; ++i)
  302. store_byte(go->active_buf,
  303. go->active_map[i]);
  304. go->active_buf->bytesused -= 216;
  305. } else
  306. go->active_buf->modet_active = 0;
  307. }
  308. go->active_buf->state = BUF_STATE_DONE;
  309. wake_up_interruptible(&go->frame_waitq);
  310. go->active_buf = NULL;
  311. }
  312. list_for_each_entry(gobuf, &go->stream, stream)
  313. if (gobuf->state == BUF_STATE_QUEUED) {
  314. gobuf->seq = go->next_seq;
  315. do_gettimeofday(&gobuf->timestamp);
  316. go->active_buf = gobuf;
  317. break;
  318. }
  319. ++go->next_seq;
  320. }
  321. static void write_bitmap_word(struct go7007 *go)
  322. {
  323. int x, y, i, stride = ((go->width >> 4) + 7) >> 3;
  324. for (i = 0; i < 16; ++i) {
  325. y = (((go->parse_length - 1) << 3) + i) / (go->width >> 4);
  326. x = (((go->parse_length - 1) << 3) + i) % (go->width >> 4);
  327. if (stride * y + (x >> 3) < sizeof(go->active_map))
  328. go->active_map[stride * y + (x >> 3)] |=
  329. (go->modet_word & 1) << (x & 0x7);
  330. go->modet_word >>= 1;
  331. }
  332. }
  333. /*
  334. * Parse a chunk of the video stream into frames. The frames are not
  335. * delimited by the hardware, so we have to parse the frame boundaries
  336. * based on the type of video stream we're receiving.
  337. */
  338. void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length)
  339. {
  340. int i, seq_start_code = -1, frame_start_code = -1;
  341. spin_lock(&go->spinlock);
  342. switch (go->format) {
  343. case GO7007_FORMAT_MPEG4:
  344. seq_start_code = 0xB0;
  345. frame_start_code = 0xB6;
  346. break;
  347. case GO7007_FORMAT_MPEG1:
  348. case GO7007_FORMAT_MPEG2:
  349. seq_start_code = 0xB3;
  350. frame_start_code = 0x00;
  351. break;
  352. }
  353. for (i = 0; i < length; ++i) {
  354. if (go->active_buf != NULL &&
  355. go->active_buf->bytesused >= GO7007_BUF_SIZE - 3) {
  356. v4l2_info(&go->v4l2_dev, "dropping oversized frame\n");
  357. go->active_buf->offset -= go->active_buf->bytesused;
  358. go->active_buf->bytesused = 0;
  359. go->active_buf->modet_active = 0;
  360. go->active_buf = NULL;
  361. }
  362. switch (go->state) {
  363. case STATE_DATA:
  364. switch (buf[i]) {
  365. case 0x00:
  366. go->state = STATE_00;
  367. break;
  368. case 0xFF:
  369. go->state = STATE_FF;
  370. break;
  371. default:
  372. store_byte(go->active_buf, buf[i]);
  373. break;
  374. }
  375. break;
  376. case STATE_00:
  377. switch (buf[i]) {
  378. case 0x00:
  379. go->state = STATE_00_00;
  380. break;
  381. case 0xFF:
  382. store_byte(go->active_buf, 0x00);
  383. go->state = STATE_FF;
  384. break;
  385. default:
  386. store_byte(go->active_buf, 0x00);
  387. store_byte(go->active_buf, buf[i]);
  388. go->state = STATE_DATA;
  389. break;
  390. }
  391. break;
  392. case STATE_00_00:
  393. switch (buf[i]) {
  394. case 0x00:
  395. store_byte(go->active_buf, 0x00);
  396. /* go->state remains STATE_00_00 */
  397. break;
  398. case 0x01:
  399. go->state = STATE_00_00_01;
  400. break;
  401. case 0xFF:
  402. store_byte(go->active_buf, 0x00);
  403. store_byte(go->active_buf, 0x00);
  404. go->state = STATE_FF;
  405. break;
  406. default:
  407. store_byte(go->active_buf, 0x00);
  408. store_byte(go->active_buf, 0x00);
  409. store_byte(go->active_buf, buf[i]);
  410. go->state = STATE_DATA;
  411. break;
  412. }
  413. break;
  414. case STATE_00_00_01:
  415. if (buf[i] == 0xF8 && go->modet_enable == 0) {
  416. /* MODET start code, but MODET not enabled */
  417. store_byte(go->active_buf, 0x00);
  418. store_byte(go->active_buf, 0x00);
  419. store_byte(go->active_buf, 0x01);
  420. store_byte(go->active_buf, 0xF8);
  421. go->state = STATE_DATA;
  422. break;
  423. }
  424. /* If this is the start of a new MPEG frame,
  425. * get a new buffer */
  426. if ((go->format == GO7007_FORMAT_MPEG1 ||
  427. go->format == GO7007_FORMAT_MPEG2 ||
  428. go->format == GO7007_FORMAT_MPEG4) &&
  429. (buf[i] == seq_start_code ||
  430. buf[i] == 0xB8 || /* GOP code */
  431. buf[i] == frame_start_code)) {
  432. if (go->active_buf == NULL || go->seen_frame)
  433. frame_boundary(go);
  434. if (buf[i] == frame_start_code) {
  435. if (go->active_buf != NULL)
  436. go->active_buf->frame_offset =
  437. go->active_buf->offset;
  438. go->seen_frame = 1;
  439. } else {
  440. go->seen_frame = 0;
  441. }
  442. }
  443. /* Handle any special chunk types, or just write the
  444. * start code to the (potentially new) buffer */
  445. switch (buf[i]) {
  446. case 0xF5: /* timestamp */
  447. go->parse_length = 12;
  448. go->state = STATE_UNPARSED;
  449. break;
  450. case 0xF6: /* vbi */
  451. go->state = STATE_VBI_LEN_A;
  452. break;
  453. case 0xF8: /* MD map */
  454. go->parse_length = 0;
  455. memset(go->active_map, 0,
  456. sizeof(go->active_map));
  457. go->state = STATE_MODET_MAP;
  458. break;
  459. case 0xFF: /* Potential JPEG start code */
  460. store_byte(go->active_buf, 0x00);
  461. store_byte(go->active_buf, 0x00);
  462. store_byte(go->active_buf, 0x01);
  463. go->state = STATE_FF;
  464. break;
  465. default:
  466. store_byte(go->active_buf, 0x00);
  467. store_byte(go->active_buf, 0x00);
  468. store_byte(go->active_buf, 0x01);
  469. store_byte(go->active_buf, buf[i]);
  470. go->state = STATE_DATA;
  471. break;
  472. }
  473. break;
  474. case STATE_FF:
  475. switch (buf[i]) {
  476. case 0x00:
  477. store_byte(go->active_buf, 0xFF);
  478. go->state = STATE_00;
  479. break;
  480. case 0xFF:
  481. store_byte(go->active_buf, 0xFF);
  482. /* go->state remains STATE_FF */
  483. break;
  484. case 0xD8:
  485. if (go->format == GO7007_FORMAT_MJPEG)
  486. frame_boundary(go);
  487. /* fall through */
  488. default:
  489. store_byte(go->active_buf, 0xFF);
  490. store_byte(go->active_buf, buf[i]);
  491. go->state = STATE_DATA;
  492. break;
  493. }
  494. break;
  495. case STATE_VBI_LEN_A:
  496. go->parse_length = buf[i] << 8;
  497. go->state = STATE_VBI_LEN_B;
  498. break;
  499. case STATE_VBI_LEN_B:
  500. go->parse_length |= buf[i];
  501. if (go->parse_length > 0)
  502. go->state = STATE_UNPARSED;
  503. else
  504. go->state = STATE_DATA;
  505. break;
  506. case STATE_MODET_MAP:
  507. if (go->parse_length < 204) {
  508. if (go->parse_length & 1) {
  509. go->modet_word |= buf[i];
  510. write_bitmap_word(go);
  511. } else
  512. go->modet_word = buf[i] << 8;
  513. } else if (go->parse_length == 207 && go->active_buf) {
  514. go->active_buf->modet_active = buf[i];
  515. }
  516. if (++go->parse_length == 208)
  517. go->state = STATE_DATA;
  518. break;
  519. case STATE_UNPARSED:
  520. if (--go->parse_length == 0)
  521. go->state = STATE_DATA;
  522. break;
  523. }
  524. }
  525. spin_unlock(&go->spinlock);
  526. }
  527. EXPORT_SYMBOL(go7007_parse_video_stream);
  528. /*
  529. * Allocate a new go7007 struct. Used by the hardware-specific probe.
  530. */
  531. struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev)
  532. {
  533. struct go7007 *go;
  534. int i;
  535. go = kmalloc(sizeof(struct go7007), GFP_KERNEL);
  536. if (go == NULL)
  537. return NULL;
  538. go->dev = dev;
  539. go->board_info = board;
  540. go->board_id = 0;
  541. go->tuner_type = -1;
  542. go->channel_number = 0;
  543. go->name[0] = 0;
  544. mutex_init(&go->hw_lock);
  545. init_waitqueue_head(&go->frame_waitq);
  546. spin_lock_init(&go->spinlock);
  547. go->video_dev = NULL;
  548. go->ref_count = 0;
  549. go->status = STATUS_INIT;
  550. memset(&go->i2c_adapter, 0, sizeof(go->i2c_adapter));
  551. go->i2c_adapter_online = 0;
  552. go->interrupt_available = 0;
  553. init_waitqueue_head(&go->interrupt_waitq);
  554. go->in_use = 0;
  555. go->input = 0;
  556. if (board->sensor_flags & GO7007_SENSOR_TV) {
  557. go->standard = GO7007_STD_NTSC;
  558. go->width = 720;
  559. go->height = 480;
  560. go->sensor_framerate = 30000;
  561. } else {
  562. go->standard = GO7007_STD_OTHER;
  563. go->width = board->sensor_width;
  564. go->height = board->sensor_height;
  565. go->sensor_framerate = board->sensor_framerate;
  566. }
  567. go->encoder_v_offset = board->sensor_v_offset;
  568. go->encoder_h_offset = board->sensor_h_offset;
  569. go->encoder_h_halve = 0;
  570. go->encoder_v_halve = 0;
  571. go->encoder_subsample = 0;
  572. go->streaming = 0;
  573. go->format = GO7007_FORMAT_MJPEG;
  574. go->bitrate = 1500000;
  575. go->fps_scale = 1;
  576. go->pali = 0;
  577. go->aspect_ratio = GO7007_RATIO_1_1;
  578. go->gop_size = 0;
  579. go->ipb = 0;
  580. go->closed_gop = 0;
  581. go->repeat_seqhead = 0;
  582. go->seq_header_enable = 0;
  583. go->gop_header_enable = 0;
  584. go->dvd_mode = 0;
  585. go->interlace_coding = 0;
  586. for (i = 0; i < 4; ++i)
  587. go->modet[i].enable = 0;
  588. for (i = 0; i < 1624; ++i)
  589. go->modet_map[i] = 0;
  590. go->audio_deliver = NULL;
  591. go->audio_enabled = 0;
  592. INIT_LIST_HEAD(&go->stream);
  593. return go;
  594. }
  595. EXPORT_SYMBOL(go7007_alloc);
  596. /*
  597. * Detach and unregister the encoder. The go7007 struct won't be freed
  598. * until v4l2 finishes releasing its resources and all associated fds are
  599. * closed by applications.
  600. */
  601. void go7007_remove(struct go7007 *go)
  602. {
  603. if (go->i2c_adapter_online) {
  604. if (i2c_del_adapter(&go->i2c_adapter) == 0)
  605. go->i2c_adapter_online = 0;
  606. else
  607. v4l2_err(&go->v4l2_dev,
  608. "error removing I2C adapter!\n");
  609. }
  610. if (go->audio_enabled)
  611. go7007_snd_remove(go);
  612. go7007_v4l2_remove(go);
  613. }
  614. EXPORT_SYMBOL(go7007_remove);
  615. MODULE_LICENSE("GPL v2");