au0828-dvb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * Driver for the Auvitek USB bridge
  3. *
  4. * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. */
  17. #include "au0828.h"
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/init.h>
  21. #include <linux/device.h>
  22. #include <media/v4l2-common.h>
  23. #include <media/tuner.h>
  24. #include "au8522.h"
  25. #include "xc5000.h"
  26. #include "mxl5007t.h"
  27. #include "tda18271.h"
  28. static int preallocate_big_buffers;
  29. module_param_named(preallocate_big_buffers, preallocate_big_buffers, int, 0644);
  30. MODULE_PARM_DESC(preallocate_big_buffers, "Preallocate the larger transfer buffers at module load time");
  31. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  32. #define _AU0828_BULKPIPE 0x83
  33. #define _BULKPIPESIZE 0xe522
  34. static u8 hauppauge_hvr950q_led_states[] = {
  35. 0x00, /* off */
  36. 0x02, /* yellow */
  37. 0x04, /* green */
  38. };
  39. static struct au8522_led_config hauppauge_hvr950q_led_cfg = {
  40. .gpio_output = 0x00e0,
  41. .gpio_output_enable = 0x6006,
  42. .gpio_output_disable = 0x0660,
  43. .gpio_leds = 0x00e2,
  44. .led_states = hauppauge_hvr950q_led_states,
  45. .num_led_states = sizeof(hauppauge_hvr950q_led_states),
  46. .vsb8_strong = 20 /* dB */ * 10,
  47. .qam64_strong = 25 /* dB */ * 10,
  48. .qam256_strong = 32 /* dB */ * 10,
  49. };
  50. static struct au8522_config hauppauge_hvr950q_config = {
  51. .demod_address = 0x8e >> 1,
  52. .status_mode = AU8522_DEMODLOCKING,
  53. .qam_if = AU8522_IF_6MHZ,
  54. .vsb_if = AU8522_IF_6MHZ,
  55. .led_cfg = &hauppauge_hvr950q_led_cfg,
  56. };
  57. static struct au8522_config fusionhdtv7usb_config = {
  58. .demod_address = 0x8e >> 1,
  59. .status_mode = AU8522_DEMODLOCKING,
  60. .qam_if = AU8522_IF_6MHZ,
  61. .vsb_if = AU8522_IF_6MHZ,
  62. };
  63. static struct au8522_config hauppauge_woodbury_config = {
  64. .demod_address = 0x8e >> 1,
  65. .status_mode = AU8522_DEMODLOCKING,
  66. .qam_if = AU8522_IF_4MHZ,
  67. .vsb_if = AU8522_IF_3_25MHZ,
  68. };
  69. static struct xc5000_config hauppauge_xc5000a_config = {
  70. .i2c_address = 0x61,
  71. .if_khz = 6000,
  72. .chip_id = XC5000A,
  73. .output_amp = 0x8f,
  74. };
  75. static struct xc5000_config hauppauge_xc5000c_config = {
  76. .i2c_address = 0x61,
  77. .if_khz = 6000,
  78. .chip_id = XC5000C,
  79. .output_amp = 0x8f,
  80. };
  81. static struct mxl5007t_config mxl5007t_hvr950q_config = {
  82. .xtal_freq_hz = MxL_XTAL_24_MHZ,
  83. .if_freq_hz = MxL_IF_6_MHZ,
  84. };
  85. static struct tda18271_config hauppauge_woodbury_tunerconfig = {
  86. .gate = TDA18271_GATE_DIGITAL,
  87. };
  88. static void au0828_restart_dvb_streaming(struct work_struct *work);
  89. static void au0828_bulk_timeout(struct timer_list *t)
  90. {
  91. struct au0828_dev *dev = from_timer(dev, t, bulk_timeout);
  92. dprintk(1, "%s called\n", __func__);
  93. dev->bulk_timeout_running = 0;
  94. schedule_work(&dev->restart_streaming);
  95. }
  96. /*-------------------------------------------------------------------*/
  97. static void urb_completion(struct urb *purb)
  98. {
  99. struct au0828_dev *dev = purb->context;
  100. int ptype = usb_pipetype(purb->pipe);
  101. unsigned char *ptr;
  102. dprintk(2, "%s: %d\n", __func__, purb->actual_length);
  103. if (!dev) {
  104. dprintk(2, "%s: no dev!\n", __func__);
  105. return;
  106. }
  107. if (!dev->urb_streaming) {
  108. dprintk(2, "%s: not streaming!\n", __func__);
  109. return;
  110. }
  111. if (ptype != PIPE_BULK) {
  112. pr_err("%s: Unsupported URB type %d\n",
  113. __func__, ptype);
  114. return;
  115. }
  116. /* See if the stream is corrupted (to work around a hardware
  117. bug where the stream gets misaligned */
  118. ptr = purb->transfer_buffer;
  119. if (purb->actual_length > 0 && ptr[0] != 0x47) {
  120. dprintk(1, "Need to restart streaming %02x len=%d!\n",
  121. ptr[0], purb->actual_length);
  122. schedule_work(&dev->restart_streaming);
  123. return;
  124. } else if (dev->bulk_timeout_running == 1) {
  125. /* The URB handler has fired, so cancel timer which would
  126. * restart endpoint if we hadn't
  127. */
  128. dprintk(1, "%s cancelling bulk timeout\n", __func__);
  129. dev->bulk_timeout_running = 0;
  130. del_timer(&dev->bulk_timeout);
  131. }
  132. /* Feed the transport payload into the kernel demux */
  133. dvb_dmx_swfilter_packets(&dev->dvb.demux,
  134. purb->transfer_buffer, purb->actual_length / 188);
  135. /* Clean the buffer before we requeue */
  136. memset(purb->transfer_buffer, 0, URB_BUFSIZE);
  137. /* Requeue URB */
  138. usb_submit_urb(purb, GFP_ATOMIC);
  139. }
  140. static int stop_urb_transfer(struct au0828_dev *dev)
  141. {
  142. int i;
  143. dprintk(2, "%s()\n", __func__);
  144. if (!dev->urb_streaming)
  145. return 0;
  146. if (dev->bulk_timeout_running == 1) {
  147. dev->bulk_timeout_running = 0;
  148. del_timer(&dev->bulk_timeout);
  149. }
  150. dev->urb_streaming = false;
  151. for (i = 0; i < URB_COUNT; i++) {
  152. if (dev->urbs[i]) {
  153. usb_kill_urb(dev->urbs[i]);
  154. if (!preallocate_big_buffers)
  155. kfree(dev->urbs[i]->transfer_buffer);
  156. usb_free_urb(dev->urbs[i]);
  157. }
  158. }
  159. return 0;
  160. }
  161. static int start_urb_transfer(struct au0828_dev *dev)
  162. {
  163. struct urb *purb;
  164. int i, ret;
  165. dprintk(2, "%s()\n", __func__);
  166. if (dev->urb_streaming) {
  167. dprintk(2, "%s: bulk xfer already running!\n", __func__);
  168. return 0;
  169. }
  170. for (i = 0; i < URB_COUNT; i++) {
  171. dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
  172. if (!dev->urbs[i])
  173. return -ENOMEM;
  174. purb = dev->urbs[i];
  175. if (preallocate_big_buffers)
  176. purb->transfer_buffer = dev->dig_transfer_buffer[i];
  177. else
  178. purb->transfer_buffer = kzalloc(URB_BUFSIZE,
  179. GFP_KERNEL);
  180. if (!purb->transfer_buffer) {
  181. usb_free_urb(purb);
  182. dev->urbs[i] = NULL;
  183. ret = -ENOMEM;
  184. pr_err("%s: failed big buffer allocation, err = %d\n",
  185. __func__, ret);
  186. return ret;
  187. }
  188. purb->status = -EINPROGRESS;
  189. usb_fill_bulk_urb(purb,
  190. dev->usbdev,
  191. usb_rcvbulkpipe(dev->usbdev,
  192. _AU0828_BULKPIPE),
  193. purb->transfer_buffer,
  194. URB_BUFSIZE,
  195. urb_completion,
  196. dev);
  197. }
  198. for (i = 0; i < URB_COUNT; i++) {
  199. ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC);
  200. if (ret != 0) {
  201. stop_urb_transfer(dev);
  202. pr_err("%s: failed urb submission, err = %d\n",
  203. __func__, ret);
  204. return ret;
  205. }
  206. }
  207. dev->urb_streaming = true;
  208. /* If we don't valid data within 1 second, restart stream */
  209. mod_timer(&dev->bulk_timeout, jiffies + (HZ));
  210. dev->bulk_timeout_running = 1;
  211. return 0;
  212. }
  213. static void au0828_start_transport(struct au0828_dev *dev)
  214. {
  215. au0828_write(dev, 0x608, 0x90);
  216. au0828_write(dev, 0x609, 0x72);
  217. au0828_write(dev, 0x60a, 0x71);
  218. au0828_write(dev, 0x60b, 0x01);
  219. }
  220. static void au0828_stop_transport(struct au0828_dev *dev, int full_stop)
  221. {
  222. if (full_stop) {
  223. au0828_write(dev, 0x608, 0x00);
  224. au0828_write(dev, 0x609, 0x00);
  225. au0828_write(dev, 0x60a, 0x00);
  226. }
  227. au0828_write(dev, 0x60b, 0x00);
  228. }
  229. static int au0828_dvb_start_feed(struct dvb_demux_feed *feed)
  230. {
  231. struct dvb_demux *demux = feed->demux;
  232. struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
  233. struct au0828_dvb *dvb = &dev->dvb;
  234. int ret = 0;
  235. dprintk(1, "%s()\n", __func__);
  236. if (!demux->dmx.frontend)
  237. return -EINVAL;
  238. if (dvb->frontend) {
  239. mutex_lock(&dvb->lock);
  240. dvb->start_count++;
  241. dprintk(1, "%s(), start_count: %d, stop_count: %d\n", __func__,
  242. dvb->start_count, dvb->stop_count);
  243. if (dvb->feeding++ == 0) {
  244. /* Start transport */
  245. au0828_start_transport(dev);
  246. ret = start_urb_transfer(dev);
  247. if (ret < 0) {
  248. au0828_stop_transport(dev, 0);
  249. dvb->feeding--; /* We ran out of memory... */
  250. }
  251. }
  252. mutex_unlock(&dvb->lock);
  253. }
  254. return ret;
  255. }
  256. static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed)
  257. {
  258. struct dvb_demux *demux = feed->demux;
  259. struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
  260. struct au0828_dvb *dvb = &dev->dvb;
  261. int ret = 0;
  262. dprintk(1, "%s()\n", __func__);
  263. if (dvb->frontend) {
  264. cancel_work_sync(&dev->restart_streaming);
  265. mutex_lock(&dvb->lock);
  266. dvb->stop_count++;
  267. dprintk(1, "%s(), start_count: %d, stop_count: %d\n", __func__,
  268. dvb->start_count, dvb->stop_count);
  269. if (dvb->feeding > 0) {
  270. dvb->feeding--;
  271. if (dvb->feeding == 0) {
  272. /* Stop transport */
  273. ret = stop_urb_transfer(dev);
  274. au0828_stop_transport(dev, 0);
  275. }
  276. }
  277. mutex_unlock(&dvb->lock);
  278. }
  279. return ret;
  280. }
  281. static void au0828_restart_dvb_streaming(struct work_struct *work)
  282. {
  283. struct au0828_dev *dev = container_of(work, struct au0828_dev,
  284. restart_streaming);
  285. struct au0828_dvb *dvb = &dev->dvb;
  286. if (!dev->urb_streaming)
  287. return;
  288. dprintk(1, "Restarting streaming...!\n");
  289. mutex_lock(&dvb->lock);
  290. /* Stop transport */
  291. stop_urb_transfer(dev);
  292. au0828_stop_transport(dev, 1);
  293. /* Start transport */
  294. au0828_start_transport(dev);
  295. start_urb_transfer(dev);
  296. mutex_unlock(&dvb->lock);
  297. }
  298. static int au0828_set_frontend(struct dvb_frontend *fe)
  299. {
  300. struct au0828_dev *dev = fe->dvb->priv;
  301. struct au0828_dvb *dvb = &dev->dvb;
  302. int ret, was_streaming;
  303. mutex_lock(&dvb->lock);
  304. was_streaming = dev->urb_streaming;
  305. if (was_streaming) {
  306. au0828_stop_transport(dev, 1);
  307. /*
  308. * We can't hold a mutex here, as the restart_streaming
  309. * kthread may also hold it.
  310. */
  311. mutex_unlock(&dvb->lock);
  312. cancel_work_sync(&dev->restart_streaming);
  313. mutex_lock(&dvb->lock);
  314. stop_urb_transfer(dev);
  315. }
  316. mutex_unlock(&dvb->lock);
  317. ret = dvb->set_frontend(fe);
  318. if (was_streaming) {
  319. mutex_lock(&dvb->lock);
  320. au0828_start_transport(dev);
  321. start_urb_transfer(dev);
  322. mutex_unlock(&dvb->lock);
  323. }
  324. return ret;
  325. }
  326. static int dvb_register(struct au0828_dev *dev)
  327. {
  328. struct au0828_dvb *dvb = &dev->dvb;
  329. int result;
  330. dprintk(1, "%s()\n", __func__);
  331. if (preallocate_big_buffers) {
  332. int i;
  333. for (i = 0; i < URB_COUNT; i++) {
  334. dev->dig_transfer_buffer[i] = kzalloc(URB_BUFSIZE,
  335. GFP_KERNEL);
  336. if (!dev->dig_transfer_buffer[i]) {
  337. result = -ENOMEM;
  338. pr_err("failed buffer allocation (errno = %d)\n",
  339. result);
  340. goto fail_adapter;
  341. }
  342. }
  343. }
  344. INIT_WORK(&dev->restart_streaming, au0828_restart_dvb_streaming);
  345. /* register adapter */
  346. result = dvb_register_adapter(&dvb->adapter,
  347. KBUILD_MODNAME, THIS_MODULE,
  348. &dev->usbdev->dev, adapter_nr);
  349. if (result < 0) {
  350. pr_err("dvb_register_adapter failed (errno = %d)\n",
  351. result);
  352. goto fail_adapter;
  353. }
  354. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  355. dvb->adapter.mdev = dev->media_dev;
  356. #endif
  357. dvb->adapter.priv = dev;
  358. /* register frontend */
  359. result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
  360. if (result < 0) {
  361. pr_err("dvb_register_frontend failed (errno = %d)\n",
  362. result);
  363. goto fail_frontend;
  364. }
  365. /* Hook dvb frontend */
  366. dvb->set_frontend = dvb->frontend->ops.set_frontend;
  367. dvb->frontend->ops.set_frontend = au0828_set_frontend;
  368. /* register demux stuff */
  369. dvb->demux.dmx.capabilities =
  370. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  371. DMX_MEMORY_BASED_FILTERING;
  372. dvb->demux.priv = dev;
  373. dvb->demux.filternum = 256;
  374. dvb->demux.feednum = 256;
  375. dvb->demux.start_feed = au0828_dvb_start_feed;
  376. dvb->demux.stop_feed = au0828_dvb_stop_feed;
  377. result = dvb_dmx_init(&dvb->demux);
  378. if (result < 0) {
  379. pr_err("dvb_dmx_init failed (errno = %d)\n", result);
  380. goto fail_dmx;
  381. }
  382. dvb->dmxdev.filternum = 256;
  383. dvb->dmxdev.demux = &dvb->demux.dmx;
  384. dvb->dmxdev.capabilities = 0;
  385. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  386. if (result < 0) {
  387. pr_err("dvb_dmxdev_init failed (errno = %d)\n", result);
  388. goto fail_dmxdev;
  389. }
  390. dvb->fe_hw.source = DMX_FRONTEND_0;
  391. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  392. if (result < 0) {
  393. pr_err("add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  394. result);
  395. goto fail_fe_hw;
  396. }
  397. dvb->fe_mem.source = DMX_MEMORY_FE;
  398. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  399. if (result < 0) {
  400. pr_err("add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  401. result);
  402. goto fail_fe_mem;
  403. }
  404. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  405. if (result < 0) {
  406. pr_err("connect_frontend failed (errno = %d)\n", result);
  407. goto fail_fe_conn;
  408. }
  409. /* register network adapter */
  410. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  411. dvb->start_count = 0;
  412. dvb->stop_count = 0;
  413. result = dvb_create_media_graph(&dvb->adapter, false);
  414. if (result < 0)
  415. goto fail_create_graph;
  416. return 0;
  417. fail_create_graph:
  418. dvb_net_release(&dvb->net);
  419. fail_fe_conn:
  420. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  421. fail_fe_mem:
  422. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  423. fail_fe_hw:
  424. dvb_dmxdev_release(&dvb->dmxdev);
  425. fail_dmxdev:
  426. dvb_dmx_release(&dvb->demux);
  427. fail_dmx:
  428. dvb_unregister_frontend(dvb->frontend);
  429. fail_frontend:
  430. dvb_frontend_detach(dvb->frontend);
  431. dvb_unregister_adapter(&dvb->adapter);
  432. fail_adapter:
  433. if (preallocate_big_buffers) {
  434. int i;
  435. for (i = 0; i < URB_COUNT; i++)
  436. kfree(dev->dig_transfer_buffer[i]);
  437. }
  438. return result;
  439. }
  440. void au0828_dvb_unregister(struct au0828_dev *dev)
  441. {
  442. struct au0828_dvb *dvb = &dev->dvb;
  443. dprintk(1, "%s()\n", __func__);
  444. if (dvb->frontend == NULL)
  445. return;
  446. cancel_work_sync(&dev->restart_streaming);
  447. dvb_net_release(&dvb->net);
  448. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  449. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  450. dvb_dmxdev_release(&dvb->dmxdev);
  451. dvb_dmx_release(&dvb->demux);
  452. dvb_unregister_frontend(dvb->frontend);
  453. dvb_frontend_detach(dvb->frontend);
  454. dvb_unregister_adapter(&dvb->adapter);
  455. if (preallocate_big_buffers) {
  456. int i;
  457. for (i = 0; i < URB_COUNT; i++)
  458. kfree(dev->dig_transfer_buffer[i]);
  459. }
  460. dvb->frontend = NULL;
  461. }
  462. /* All the DVB attach calls go here, this function get's modified
  463. * for each new card. No other function in this file needs
  464. * to change.
  465. */
  466. int au0828_dvb_register(struct au0828_dev *dev)
  467. {
  468. struct au0828_dvb *dvb = &dev->dvb;
  469. int ret;
  470. dprintk(1, "%s()\n", __func__);
  471. /* init frontend */
  472. switch (dev->boardnr) {
  473. case AU0828_BOARD_HAUPPAUGE_HVR850:
  474. case AU0828_BOARD_HAUPPAUGE_HVR950Q:
  475. dvb->frontend = dvb_attach(au8522_attach,
  476. &hauppauge_hvr950q_config,
  477. &dev->i2c_adap);
  478. if (dvb->frontend != NULL)
  479. switch (dev->board.tuner_type) {
  480. default:
  481. case TUNER_XC5000:
  482. dvb_attach(xc5000_attach, dvb->frontend,
  483. &dev->i2c_adap,
  484. &hauppauge_xc5000a_config);
  485. break;
  486. case TUNER_XC5000C:
  487. dvb_attach(xc5000_attach, dvb->frontend,
  488. &dev->i2c_adap,
  489. &hauppauge_xc5000c_config);
  490. break;
  491. }
  492. break;
  493. case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
  494. dvb->frontend = dvb_attach(au8522_attach,
  495. &hauppauge_hvr950q_config,
  496. &dev->i2c_adap);
  497. if (dvb->frontend != NULL)
  498. dvb_attach(mxl5007t_attach, dvb->frontend,
  499. &dev->i2c_adap, 0x60,
  500. &mxl5007t_hvr950q_config);
  501. break;
  502. case AU0828_BOARD_HAUPPAUGE_WOODBURY:
  503. dvb->frontend = dvb_attach(au8522_attach,
  504. &hauppauge_woodbury_config,
  505. &dev->i2c_adap);
  506. if (dvb->frontend != NULL)
  507. dvb_attach(tda18271_attach, dvb->frontend,
  508. 0x60, &dev->i2c_adap,
  509. &hauppauge_woodbury_tunerconfig);
  510. break;
  511. case AU0828_BOARD_DVICO_FUSIONHDTV7:
  512. dvb->frontend = dvb_attach(au8522_attach,
  513. &fusionhdtv7usb_config,
  514. &dev->i2c_adap);
  515. if (dvb->frontend != NULL) {
  516. dvb_attach(xc5000_attach, dvb->frontend,
  517. &dev->i2c_adap,
  518. &hauppauge_xc5000a_config);
  519. }
  520. break;
  521. default:
  522. pr_warn("The frontend of your DVB/ATSC card isn't supported yet\n");
  523. break;
  524. }
  525. if (NULL == dvb->frontend) {
  526. pr_err("%s() Frontend initialization failed\n",
  527. __func__);
  528. return -1;
  529. }
  530. /* define general-purpose callback pointer */
  531. dvb->frontend->callback = au0828_tuner_callback;
  532. /* register everything */
  533. ret = dvb_register(dev);
  534. if (ret < 0) {
  535. if (dvb->frontend->ops.release)
  536. dvb->frontend->ops.release(dvb->frontend);
  537. dvb->frontend = NULL;
  538. return ret;
  539. }
  540. timer_setup(&dev->bulk_timeout, au0828_bulk_timeout, 0);
  541. return 0;
  542. }
  543. void au0828_dvb_suspend(struct au0828_dev *dev)
  544. {
  545. struct au0828_dvb *dvb = &dev->dvb;
  546. int rc;
  547. if (dvb->frontend) {
  548. if (dev->urb_streaming) {
  549. cancel_work_sync(&dev->restart_streaming);
  550. /* Stop transport */
  551. mutex_lock(&dvb->lock);
  552. stop_urb_transfer(dev);
  553. au0828_stop_transport(dev, 1);
  554. mutex_unlock(&dvb->lock);
  555. dev->need_urb_start = true;
  556. }
  557. /* suspend frontend - does tuner and fe to sleep */
  558. rc = dvb_frontend_suspend(dvb->frontend);
  559. pr_info("au0828_dvb_suspend(): Suspending DVB fe %d\n", rc);
  560. }
  561. }
  562. void au0828_dvb_resume(struct au0828_dev *dev)
  563. {
  564. struct au0828_dvb *dvb = &dev->dvb;
  565. int rc;
  566. if (dvb->frontend) {
  567. /* resume frontend - does fe and tuner init */
  568. rc = dvb_frontend_resume(dvb->frontend);
  569. pr_info("au0828_dvb_resume(): Resuming DVB fe %d\n", rc);
  570. if (dev->need_urb_start) {
  571. /* Start transport */
  572. mutex_lock(&dvb->lock);
  573. au0828_start_transport(dev);
  574. start_urb_transfer(dev);
  575. mutex_unlock(&dvb->lock);
  576. }
  577. }
  578. }