radio-mr800.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * A driver for the AverMedia MR 800 USB FM radio. This device plugs
  3. * into both the USB and an analog audio input, so this thing
  4. * only deals with initialization and frequency setting, the
  5. * audio data has to be handled by a sound driver.
  6. *
  7. * Copyright (c) 2008 Alexey Klimov <klimov.linux@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. /*
  20. * Big thanks to authors and contributors of dsbr100.c and radio-si470x.c
  21. *
  22. * When work was looked pretty good, i discover this:
  23. * http://av-usbradio.sourceforge.net/index.php
  24. * http://sourceforge.net/projects/av-usbradio/
  25. * Latest release of theirs project was in 2005.
  26. * Probably, this driver could be improved through using their
  27. * achievements (specifications given).
  28. * Also, Faidon Liambotis <paravoid@debian.org> wrote nice driver for this radio
  29. * in 2007. He allowed to use his driver to improve current mr800 radio driver.
  30. * http://www.spinics.net/lists/linux-usb-devel/msg10109.html
  31. *
  32. * Version 0.01: First working version.
  33. * It's required to blacklist AverMedia USB Radio
  34. * in usbhid/hid-quirks.c
  35. * Version 0.10: A lot of cleanups and fixes: unpluging the device,
  36. * few mutex locks were added, codinstyle issues, etc.
  37. * Added stereo support. Thanks to
  38. * Douglas Schilling Landgraf <dougsland@gmail.com> and
  39. * David Ellingsworth <david@identd.dyndns.org>
  40. * for discussion, help and support.
  41. * Version 0.11: Converted to v4l2_device.
  42. *
  43. * Many things to do:
  44. * - Correct power management of device (suspend & resume)
  45. * - Add code for scanning and smooth tuning
  46. * - Add code for sensitivity value
  47. * - Correct mistakes
  48. * - In Japan another FREQ_MIN and FREQ_MAX
  49. */
  50. /* kernel includes */
  51. #include <linux/kernel.h>
  52. #include <linux/module.h>
  53. #include <linux/init.h>
  54. #include <linux/slab.h>
  55. #include <linux/input.h>
  56. #include <linux/videodev2.h>
  57. #include <media/v4l2-device.h>
  58. #include <media/v4l2-ioctl.h>
  59. #include <media/v4l2-ctrls.h>
  60. #include <media/v4l2-event.h>
  61. #include <linux/usb.h>
  62. #include <linux/mutex.h>
  63. /* driver and module definitions */
  64. #define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>"
  65. #define DRIVER_DESC "AverMedia MR 800 USB FM radio driver"
  66. #define DRIVER_VERSION "0.1.2"
  67. MODULE_AUTHOR(DRIVER_AUTHOR);
  68. MODULE_DESCRIPTION(DRIVER_DESC);
  69. MODULE_LICENSE("GPL");
  70. MODULE_VERSION(DRIVER_VERSION);
  71. #define USB_AMRADIO_VENDOR 0x07ca
  72. #define USB_AMRADIO_PRODUCT 0xb800
  73. /* dev_warn macro with driver name */
  74. #define MR800_DRIVER_NAME "radio-mr800"
  75. #define amradio_dev_warn(dev, fmt, arg...) \
  76. dev_warn(dev, MR800_DRIVER_NAME " - " fmt, ##arg)
  77. #define amradio_dev_err(dev, fmt, arg...) \
  78. dev_err(dev, MR800_DRIVER_NAME " - " fmt, ##arg)
  79. /* Probably USB_TIMEOUT should be modified in module parameter */
  80. #define BUFFER_LENGTH 8
  81. #define USB_TIMEOUT 500
  82. /* Frequency limits in MHz -- these are European values. For Japanese
  83. devices, that would be 76 and 91. */
  84. #define FREQ_MIN 87.5
  85. #define FREQ_MAX 108.0
  86. #define FREQ_MUL 16000
  87. /*
  88. * Commands that device should understand
  89. * List isn't full and will be updated with implementation of new functions
  90. */
  91. #define AMRADIO_SET_FREQ 0xa4
  92. #define AMRADIO_GET_READY_FLAG 0xa5
  93. #define AMRADIO_GET_SIGNAL 0xa7
  94. #define AMRADIO_GET_FREQ 0xa8
  95. #define AMRADIO_SET_SEARCH_UP 0xa9
  96. #define AMRADIO_SET_SEARCH_DOWN 0xaa
  97. #define AMRADIO_SET_MUTE 0xab
  98. #define AMRADIO_SET_RIGHT_MUTE 0xac
  99. #define AMRADIO_SET_LEFT_MUTE 0xad
  100. #define AMRADIO_SET_MONO 0xae
  101. #define AMRADIO_SET_SEARCH_LVL 0xb0
  102. #define AMRADIO_STOP_SEARCH 0xb1
  103. /* Comfortable defines for amradio_set_stereo */
  104. #define WANT_STEREO 0x00
  105. #define WANT_MONO 0x01
  106. /* module parameter */
  107. static int radio_nr = -1;
  108. module_param(radio_nr, int, 0);
  109. MODULE_PARM_DESC(radio_nr, "Radio Nr");
  110. /* Data for one (physical) device */
  111. struct amradio_device {
  112. /* reference to USB and video device */
  113. struct usb_device *usbdev;
  114. struct usb_interface *intf;
  115. struct video_device vdev;
  116. struct v4l2_device v4l2_dev;
  117. struct v4l2_ctrl_handler hdl;
  118. u8 *buffer;
  119. struct mutex lock; /* buffer locking */
  120. int curfreq;
  121. int stereo;
  122. int muted;
  123. };
  124. static inline struct amradio_device *to_amradio_dev(struct v4l2_device *v4l2_dev)
  125. {
  126. return container_of(v4l2_dev, struct amradio_device, v4l2_dev);
  127. }
  128. static int amradio_send_cmd(struct amradio_device *radio, u8 cmd, u8 arg,
  129. u8 *extra, u8 extralen, bool reply)
  130. {
  131. int retval;
  132. int size;
  133. radio->buffer[0] = 0x00;
  134. radio->buffer[1] = 0x55;
  135. radio->buffer[2] = 0xaa;
  136. radio->buffer[3] = extralen;
  137. radio->buffer[4] = cmd;
  138. radio->buffer[5] = arg;
  139. radio->buffer[6] = 0x00;
  140. radio->buffer[7] = extra || reply ? 8 : 0;
  141. retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
  142. radio->buffer, BUFFER_LENGTH, &size, USB_TIMEOUT);
  143. if (retval < 0 || size != BUFFER_LENGTH) {
  144. if (video_is_registered(&radio->vdev))
  145. amradio_dev_warn(&radio->vdev.dev,
  146. "cmd %02x failed\n", cmd);
  147. return retval ? retval : -EIO;
  148. }
  149. if (!extra && !reply)
  150. return 0;
  151. if (extra) {
  152. memcpy(radio->buffer, extra, extralen);
  153. memset(radio->buffer + extralen, 0, 8 - extralen);
  154. retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
  155. radio->buffer, BUFFER_LENGTH, &size, USB_TIMEOUT);
  156. } else {
  157. memset(radio->buffer, 0, 8);
  158. retval = usb_bulk_msg(radio->usbdev, usb_rcvbulkpipe(radio->usbdev, 0x81),
  159. radio->buffer, BUFFER_LENGTH, &size, USB_TIMEOUT);
  160. }
  161. if (retval == 0 && size == BUFFER_LENGTH)
  162. return 0;
  163. if (video_is_registered(&radio->vdev) && cmd != AMRADIO_GET_READY_FLAG)
  164. amradio_dev_warn(&radio->vdev.dev, "follow-up to cmd %02x failed\n", cmd);
  165. return retval ? retval : -EIO;
  166. }
  167. /* switch on/off the radio. Send 8 bytes to device */
  168. static int amradio_set_mute(struct amradio_device *radio, bool mute)
  169. {
  170. int ret = amradio_send_cmd(radio,
  171. AMRADIO_SET_MUTE, mute, NULL, 0, false);
  172. if (!ret)
  173. radio->muted = mute;
  174. return ret;
  175. }
  176. /* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
  177. static int amradio_set_freq(struct amradio_device *radio, int freq)
  178. {
  179. unsigned short freq_send;
  180. u8 buf[3];
  181. int retval;
  182. /* we need to be sure that frequency isn't out of range */
  183. freq = clamp_t(unsigned, freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
  184. freq_send = 0x10 + (freq >> 3) / 25;
  185. /* frequency is calculated from freq_send and placed in first 2 bytes */
  186. buf[0] = (freq_send >> 8) & 0xff;
  187. buf[1] = freq_send & 0xff;
  188. buf[2] = 0x01;
  189. retval = amradio_send_cmd(radio, AMRADIO_SET_FREQ, 0, buf, 3, false);
  190. if (retval)
  191. return retval;
  192. radio->curfreq = freq;
  193. msleep(40);
  194. return 0;
  195. }
  196. static int amradio_set_stereo(struct amradio_device *radio, bool stereo)
  197. {
  198. int ret = amradio_send_cmd(radio,
  199. AMRADIO_SET_MONO, !stereo, NULL, 0, false);
  200. if (!ret)
  201. radio->stereo = stereo;
  202. return ret;
  203. }
  204. static int amradio_get_stat(struct amradio_device *radio, bool *is_stereo, u32 *signal)
  205. {
  206. int ret = amradio_send_cmd(radio,
  207. AMRADIO_GET_SIGNAL, 0, NULL, 0, true);
  208. if (ret)
  209. return ret;
  210. *is_stereo = radio->buffer[2] >> 7;
  211. *signal = (radio->buffer[3] & 0xf0) << 8;
  212. return 0;
  213. }
  214. /* Handle unplugging the device.
  215. * We call video_unregister_device in any case.
  216. * The last function called in this procedure is
  217. * usb_amradio_device_release.
  218. */
  219. static void usb_amradio_disconnect(struct usb_interface *intf)
  220. {
  221. struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
  222. mutex_lock(&radio->lock);
  223. video_unregister_device(&radio->vdev);
  224. amradio_set_mute(radio, true);
  225. usb_set_intfdata(intf, NULL);
  226. v4l2_device_disconnect(&radio->v4l2_dev);
  227. mutex_unlock(&radio->lock);
  228. v4l2_device_put(&radio->v4l2_dev);
  229. }
  230. /* vidioc_querycap - query device capabilities */
  231. static int vidioc_querycap(struct file *file, void *priv,
  232. struct v4l2_capability *v)
  233. {
  234. struct amradio_device *radio = video_drvdata(file);
  235. strlcpy(v->driver, "radio-mr800", sizeof(v->driver));
  236. strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card));
  237. usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
  238. v->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER |
  239. V4L2_CAP_HW_FREQ_SEEK;
  240. v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
  241. return 0;
  242. }
  243. /* vidioc_g_tuner - get tuner attributes */
  244. static int vidioc_g_tuner(struct file *file, void *priv,
  245. struct v4l2_tuner *v)
  246. {
  247. struct amradio_device *radio = video_drvdata(file);
  248. bool is_stereo = false;
  249. int retval;
  250. if (v->index > 0)
  251. return -EINVAL;
  252. v->signal = 0;
  253. retval = amradio_get_stat(radio, &is_stereo, &v->signal);
  254. if (retval)
  255. return retval;
  256. strcpy(v->name, "FM");
  257. v->type = V4L2_TUNER_RADIO;
  258. v->rangelow = FREQ_MIN * FREQ_MUL;
  259. v->rangehigh = FREQ_MAX * FREQ_MUL;
  260. v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO |
  261. V4L2_TUNER_CAP_HWSEEK_WRAP;
  262. v->rxsubchans = is_stereo ? V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
  263. v->audmode = radio->stereo ?
  264. V4L2_TUNER_MODE_STEREO : V4L2_TUNER_MODE_MONO;
  265. return 0;
  266. }
  267. /* vidioc_s_tuner - set tuner attributes */
  268. static int vidioc_s_tuner(struct file *file, void *priv,
  269. const struct v4l2_tuner *v)
  270. {
  271. struct amradio_device *radio = video_drvdata(file);
  272. if (v->index > 0)
  273. return -EINVAL;
  274. /* mono/stereo selector */
  275. switch (v->audmode) {
  276. case V4L2_TUNER_MODE_MONO:
  277. return amradio_set_stereo(radio, WANT_MONO);
  278. default:
  279. return amradio_set_stereo(radio, WANT_STEREO);
  280. }
  281. }
  282. /* vidioc_s_frequency - set tuner radio frequency */
  283. static int vidioc_s_frequency(struct file *file, void *priv,
  284. const struct v4l2_frequency *f)
  285. {
  286. struct amradio_device *radio = video_drvdata(file);
  287. if (f->tuner != 0)
  288. return -EINVAL;
  289. return amradio_set_freq(radio, f->frequency);
  290. }
  291. /* vidioc_g_frequency - get tuner radio frequency */
  292. static int vidioc_g_frequency(struct file *file, void *priv,
  293. struct v4l2_frequency *f)
  294. {
  295. struct amradio_device *radio = video_drvdata(file);
  296. if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
  297. return -EINVAL;
  298. f->type = V4L2_TUNER_RADIO;
  299. f->frequency = radio->curfreq;
  300. return 0;
  301. }
  302. static int vidioc_s_hw_freq_seek(struct file *file, void *priv,
  303. const struct v4l2_hw_freq_seek *seek)
  304. {
  305. static u8 buf[8] = {
  306. 0x3d, 0x32, 0x0f, 0x08, 0x3d, 0x32, 0x0f, 0x08
  307. };
  308. struct amradio_device *radio = video_drvdata(file);
  309. unsigned long timeout;
  310. int retval;
  311. if (seek->tuner != 0 || !seek->wrap_around)
  312. return -EINVAL;
  313. if (file->f_flags & O_NONBLOCK)
  314. return -EWOULDBLOCK;
  315. retval = amradio_send_cmd(radio,
  316. AMRADIO_SET_SEARCH_LVL, 0, buf, 8, false);
  317. if (retval)
  318. return retval;
  319. amradio_set_freq(radio, radio->curfreq);
  320. retval = amradio_send_cmd(radio,
  321. seek->seek_upward ? AMRADIO_SET_SEARCH_UP : AMRADIO_SET_SEARCH_DOWN,
  322. 0, NULL, 0, false);
  323. if (retval)
  324. return retval;
  325. timeout = jiffies + msecs_to_jiffies(30000);
  326. for (;;) {
  327. if (time_after(jiffies, timeout)) {
  328. retval = -ENODATA;
  329. break;
  330. }
  331. if (schedule_timeout_interruptible(msecs_to_jiffies(10))) {
  332. retval = -ERESTARTSYS;
  333. break;
  334. }
  335. retval = amradio_send_cmd(radio, AMRADIO_GET_READY_FLAG,
  336. 0, NULL, 0, true);
  337. if (retval)
  338. continue;
  339. amradio_send_cmd(radio, AMRADIO_GET_FREQ, 0, NULL, 0, true);
  340. if (radio->buffer[1] || radio->buffer[2]) {
  341. /* To check: sometimes radio->curfreq is set to out of range value */
  342. radio->curfreq = (radio->buffer[1] << 8) | radio->buffer[2];
  343. radio->curfreq = (radio->curfreq - 0x10) * 200;
  344. amradio_send_cmd(radio, AMRADIO_STOP_SEARCH,
  345. 0, NULL, 0, false);
  346. amradio_set_freq(radio, radio->curfreq);
  347. retval = 0;
  348. break;
  349. }
  350. }
  351. amradio_send_cmd(radio, AMRADIO_STOP_SEARCH, 0, NULL, 0, false);
  352. amradio_set_freq(radio, radio->curfreq);
  353. return retval;
  354. }
  355. static int usb_amradio_s_ctrl(struct v4l2_ctrl *ctrl)
  356. {
  357. struct amradio_device *radio =
  358. container_of(ctrl->handler, struct amradio_device, hdl);
  359. switch (ctrl->id) {
  360. case V4L2_CID_AUDIO_MUTE:
  361. return amradio_set_mute(radio, ctrl->val);
  362. }
  363. return -EINVAL;
  364. }
  365. static int usb_amradio_init(struct amradio_device *radio)
  366. {
  367. int retval;
  368. retval = amradio_set_mute(radio, true);
  369. if (retval)
  370. goto out_err;
  371. retval = amradio_set_stereo(radio, true);
  372. if (retval)
  373. goto out_err;
  374. retval = amradio_set_freq(radio, radio->curfreq);
  375. if (retval)
  376. goto out_err;
  377. return 0;
  378. out_err:
  379. amradio_dev_err(&radio->vdev.dev, "initialization failed\n");
  380. return retval;
  381. }
  382. /* Suspend device - stop device. Need to be checked and fixed */
  383. static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
  384. {
  385. struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
  386. mutex_lock(&radio->lock);
  387. if (!radio->muted) {
  388. amradio_set_mute(radio, true);
  389. radio->muted = false;
  390. }
  391. mutex_unlock(&radio->lock);
  392. dev_info(&intf->dev, "going into suspend..\n");
  393. return 0;
  394. }
  395. /* Resume device - start device. Need to be checked and fixed */
  396. static int usb_amradio_resume(struct usb_interface *intf)
  397. {
  398. struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
  399. mutex_lock(&radio->lock);
  400. amradio_set_stereo(radio, radio->stereo);
  401. amradio_set_freq(radio, radio->curfreq);
  402. if (!radio->muted)
  403. amradio_set_mute(radio, false);
  404. mutex_unlock(&radio->lock);
  405. dev_info(&intf->dev, "coming out of suspend..\n");
  406. return 0;
  407. }
  408. static const struct v4l2_ctrl_ops usb_amradio_ctrl_ops = {
  409. .s_ctrl = usb_amradio_s_ctrl,
  410. };
  411. /* File system interface */
  412. static const struct v4l2_file_operations usb_amradio_fops = {
  413. .owner = THIS_MODULE,
  414. .open = v4l2_fh_open,
  415. .release = v4l2_fh_release,
  416. .poll = v4l2_ctrl_poll,
  417. .unlocked_ioctl = video_ioctl2,
  418. };
  419. static const struct v4l2_ioctl_ops usb_amradio_ioctl_ops = {
  420. .vidioc_querycap = vidioc_querycap,
  421. .vidioc_g_tuner = vidioc_g_tuner,
  422. .vidioc_s_tuner = vidioc_s_tuner,
  423. .vidioc_g_frequency = vidioc_g_frequency,
  424. .vidioc_s_frequency = vidioc_s_frequency,
  425. .vidioc_s_hw_freq_seek = vidioc_s_hw_freq_seek,
  426. .vidioc_log_status = v4l2_ctrl_log_status,
  427. .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  428. .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  429. };
  430. static void usb_amradio_release(struct v4l2_device *v4l2_dev)
  431. {
  432. struct amradio_device *radio = to_amradio_dev(v4l2_dev);
  433. /* free rest memory */
  434. v4l2_ctrl_handler_free(&radio->hdl);
  435. v4l2_device_unregister(&radio->v4l2_dev);
  436. kfree(radio->buffer);
  437. kfree(radio);
  438. }
  439. /* check if the device is present and register with v4l and usb if it is */
  440. static int usb_amradio_probe(struct usb_interface *intf,
  441. const struct usb_device_id *id)
  442. {
  443. struct amradio_device *radio;
  444. int retval;
  445. radio = kzalloc(sizeof(struct amradio_device), GFP_KERNEL);
  446. if (!radio) {
  447. dev_err(&intf->dev, "kmalloc for amradio_device failed\n");
  448. retval = -ENOMEM;
  449. goto err;
  450. }
  451. radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
  452. if (!radio->buffer) {
  453. dev_err(&intf->dev, "kmalloc for radio->buffer failed\n");
  454. retval = -ENOMEM;
  455. goto err_nobuf;
  456. }
  457. retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
  458. if (retval < 0) {
  459. dev_err(&intf->dev, "couldn't register v4l2_device\n");
  460. goto err_v4l2;
  461. }
  462. v4l2_ctrl_handler_init(&radio->hdl, 1);
  463. v4l2_ctrl_new_std(&radio->hdl, &usb_amradio_ctrl_ops,
  464. V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
  465. if (radio->hdl.error) {
  466. retval = radio->hdl.error;
  467. dev_err(&intf->dev, "couldn't register control\n");
  468. goto err_ctrl;
  469. }
  470. mutex_init(&radio->lock);
  471. radio->v4l2_dev.ctrl_handler = &radio->hdl;
  472. radio->v4l2_dev.release = usb_amradio_release;
  473. strlcpy(radio->vdev.name, radio->v4l2_dev.name,
  474. sizeof(radio->vdev.name));
  475. radio->vdev.v4l2_dev = &radio->v4l2_dev;
  476. radio->vdev.fops = &usb_amradio_fops;
  477. radio->vdev.ioctl_ops = &usb_amradio_ioctl_ops;
  478. radio->vdev.release = video_device_release_empty;
  479. radio->vdev.lock = &radio->lock;
  480. radio->usbdev = interface_to_usbdev(intf);
  481. radio->intf = intf;
  482. usb_set_intfdata(intf, &radio->v4l2_dev);
  483. radio->curfreq = 95.16 * FREQ_MUL;
  484. video_set_drvdata(&radio->vdev, radio);
  485. retval = usb_amradio_init(radio);
  486. if (retval)
  487. goto err_vdev;
  488. retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO,
  489. radio_nr);
  490. if (retval < 0) {
  491. dev_err(&intf->dev, "could not register video device\n");
  492. goto err_vdev;
  493. }
  494. return 0;
  495. err_vdev:
  496. v4l2_ctrl_handler_free(&radio->hdl);
  497. err_ctrl:
  498. v4l2_device_unregister(&radio->v4l2_dev);
  499. err_v4l2:
  500. kfree(radio->buffer);
  501. err_nobuf:
  502. kfree(radio);
  503. err:
  504. return retval;
  505. }
  506. /* USB Device ID List */
  507. static const struct usb_device_id usb_amradio_device_table[] = {
  508. { USB_DEVICE_AND_INTERFACE_INFO(USB_AMRADIO_VENDOR, USB_AMRADIO_PRODUCT,
  509. USB_CLASS_HID, 0, 0) },
  510. { } /* Terminating entry */
  511. };
  512. MODULE_DEVICE_TABLE(usb, usb_amradio_device_table);
  513. /* USB subsystem interface */
  514. static struct usb_driver usb_amradio_driver = {
  515. .name = MR800_DRIVER_NAME,
  516. .probe = usb_amradio_probe,
  517. .disconnect = usb_amradio_disconnect,
  518. .suspend = usb_amradio_suspend,
  519. .resume = usb_amradio_resume,
  520. .reset_resume = usb_amradio_resume,
  521. .id_table = usb_amradio_device_table,
  522. };
  523. module_usb_driver(usb_amradio_driver);