radio-mr800.c 17 KB

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