Alexey Klimov | fc55bcb | 2008-12-27 22:33:54 -0300 | [diff] [blame] | 1 | /* A driver for the D-Link DSB-R100 USB radio and Gemtek USB Radio 21. |
| 2 | The device plugs into both the USB and an analog audio input, so this thing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | only deals with initialisation and frequency setting, the |
| 4 | audio data has to be handled by a sound driver. |
| 5 | |
| 6 | Major issue: I can't find out where the device reports the signal |
| 7 | strength, and indeed the windows software appearantly just looks |
| 8 | at the stereo indicator as well. So, scanning will only find |
| 9 | stereo stations. Sad, but I can't help it. |
| 10 | |
| 11 | Also, the windows program sends oodles of messages over to the |
| 12 | device, and I couldn't figure out their meaning. My suspicion |
| 13 | is that they don't have any:-) |
| 14 | |
| 15 | You might find some interesting stuff about this module at |
| 16 | http://unimut.fsk.uni-heidelberg.de/unimut/demi/dsbr |
| 17 | |
| 18 | Copyright (c) 2000 Markus Demleitner <msdemlei@cl.uni-heidelberg.de> |
| 19 | |
| 20 | This program is free software; you can redistribute it and/or modify |
| 21 | it under the terms of the GNU General Public License as published by |
| 22 | the Free Software Foundation; either version 2 of the License, or |
| 23 | (at your option) any later version. |
| 24 | |
| 25 | This program is distributed in the hope that it will be useful, |
| 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | GNU General Public License for more details. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License |
| 31 | along with this program; if not, write to the Free Software |
| 32 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 33 | |
| 34 | History: |
| 35 | |
Alexey Klimov | 6076dbf | 2008-12-27 22:35:21 -0300 | [diff] [blame] | 36 | Version 0.44: |
| 37 | Add suspend/resume functions, fix unplug of device, |
| 38 | a lot of cleanups and fixes by Alexey Klimov <klimov.linux@gmail.com> |
| 39 | |
Oliver Neukum | 863c86d | 2007-12-03 06:48:43 -0300 | [diff] [blame] | 40 | Version 0.43: |
| 41 | Oliver Neukum: avoided DMA coherency issue |
| 42 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 43 | Version 0.42: |
| 44 | Converted dsbr100 to use video_ioctl2 |
| 45 | by Douglas Landgraf <dougsland@gmail.com> |
| 46 | |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 47 | Version 0.41-ac1: |
| 48 | Alan Cox: Some cleanups and fixes |
| 49 | |
| 50 | Version 0.41: |
| 51 | Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | Version 0.40: |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 54 | Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | Version 0.30: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 57 | Markus: Updates for 2.5.x kernel and more ISO compliant source |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | Version 0.25: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 60 | PSL and Markus: Cleanup, radio now doesn't stop on device close |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | Version 0.24: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 63 | Markus: Hope I got these silly VIDEO_TUNER_LOW issues finally |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | right. Some minor cleanup, improved standalone compilation |
| 65 | |
| 66 | Version 0.23: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 67 | Markus: Sign extension bug fixed by declaring transfer_buffer unsigned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | Version 0.22: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 70 | Markus: Some (brown bag) cleanup in what VIDIOCSTUNER returns, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | thanks to Mike Cox for pointing the problem out. |
| 72 | |
| 73 | Version 0.21: |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 74 | Markus: Minor cleanup, warnings if something goes wrong, lame attempt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | to adhere to Documentation/CodingStyle |
| 76 | |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 77 | Version 0.2: |
| 78 | Brad Hards <bradh@dynamite.com.au>: Fixes to make it work as non-module |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | Markus: Copyright clarification |
| 80 | |
| 81 | Version 0.01: Markus: initial release |
| 82 | |
| 83 | */ |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #include <linux/kernel.h> |
| 86 | #include <linux/module.h> |
| 87 | #include <linux/init.h> |
| 88 | #include <linux/slab.h> |
| 89 | #include <linux/input.h> |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 90 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 91 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 92 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #include <linux/usb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Version Information |
| 97 | */ |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 98 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
| 99 | |
Alexey Klimov | 6076dbf | 2008-12-27 22:35:21 -0300 | [diff] [blame] | 100 | #define DRIVER_VERSION "v0.44" |
| 101 | #define RADIO_VERSION KERNEL_VERSION(0, 4, 4) |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 102 | |
| 103 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 104 | { |
| 105 | .id = V4L2_CID_AUDIO_MUTE, |
| 106 | .name = "Mute", |
| 107 | .minimum = 0, |
| 108 | .maximum = 1, |
| 109 | .default_value = 1, |
| 110 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
Alexey Klimov | 54b7b0d | 2008-11-08 00:31:50 -0300 | [diff] [blame] | 111 | }, |
| 112 | /* HINT: the disabled controls are only here to satify kradio and such apps */ |
| 113 | { .id = V4L2_CID_AUDIO_VOLUME, |
| 114 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 115 | }, |
| 116 | { |
| 117 | .id = V4L2_CID_AUDIO_BALANCE, |
| 118 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 119 | }, |
| 120 | { |
| 121 | .id = V4L2_CID_AUDIO_BASS, |
| 122 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 123 | }, |
| 124 | { |
| 125 | .id = V4L2_CID_AUDIO_TREBLE, |
| 126 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 127 | }, |
| 128 | { |
| 129 | .id = V4L2_CID_AUDIO_LOUDNESS, |
| 130 | .flags = V4L2_CTRL_FLAG_DISABLED, |
| 131 | }, |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 132 | }; |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>" |
| 135 | #define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver" |
| 136 | |
| 137 | #define DSB100_VENDOR 0x04b4 |
| 138 | #define DSB100_PRODUCT 0x1002 |
| 139 | |
| 140 | /* Commands the device appears to understand */ |
| 141 | #define DSB100_TUNE 1 |
| 142 | #define DSB100_ONOFF 2 |
| 143 | |
| 144 | #define TB_LEN 16 |
| 145 | |
| 146 | /* Frequency limits in MHz -- these are European values. For Japanese |
| 147 | devices, that would be 76 and 91. */ |
| 148 | #define FREQ_MIN 87.5 |
| 149 | #define FREQ_MAX 108.0 |
| 150 | #define FREQ_MUL 16000 |
| 151 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 152 | #define videodev_to_radio(d) container_of(d, struct dsbr100_device, videodev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | static int usb_dsbr100_probe(struct usb_interface *intf, |
| 155 | const struct usb_device_id *id); |
| 156 | static void usb_dsbr100_disconnect(struct usb_interface *intf); |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 157 | static int usb_dsbr100_open(struct file *file); |
| 158 | static int usb_dsbr100_close(struct file *file); |
Alexey Klimov | 04e0ffb | 2008-11-08 00:40:46 -0300 | [diff] [blame] | 159 | static int usb_dsbr100_suspend(struct usb_interface *intf, |
| 160 | pm_message_t message); |
| 161 | static int usb_dsbr100_resume(struct usb_interface *intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | static int radio_nr = -1; |
| 164 | module_param(radio_nr, int, 0); |
| 165 | |
| 166 | /* Data for one (physical) device */ |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 167 | struct dsbr100_device { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | struct usb_device *usbdev; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 169 | struct video_device videodev; |
Oliver Neukum | 863c86d | 2007-12-03 06:48:43 -0300 | [diff] [blame] | 170 | u8 *transfer_buffer; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 171 | struct mutex lock; /* buffer locking */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | int curfreq; |
| 173 | int stereo; |
| 174 | int users; |
| 175 | int removed; |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 176 | int muted; |
| 177 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | static struct usb_device_id usb_dsbr100_device_table [] = { |
| 180 | { USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) }, |
| 181 | { } /* Terminating entry */ |
| 182 | }; |
| 183 | |
| 184 | MODULE_DEVICE_TABLE (usb, usb_dsbr100_device_table); |
| 185 | |
| 186 | /* USB subsystem interface */ |
| 187 | static struct usb_driver usb_dsbr100_driver = { |
Alexey Klimov | 04e0ffb | 2008-11-08 00:40:46 -0300 | [diff] [blame] | 188 | .name = "dsbr100", |
| 189 | .probe = usb_dsbr100_probe, |
| 190 | .disconnect = usb_dsbr100_disconnect, |
| 191 | .id_table = usb_dsbr100_device_table, |
| 192 | .suspend = usb_dsbr100_suspend, |
| 193 | .resume = usb_dsbr100_resume, |
| 194 | .reset_resume = usb_dsbr100_resume, |
| 195 | .supports_autosuspend = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | /* Low-level device interface begins here */ |
| 199 | |
| 200 | /* switch on radio */ |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 201 | static int dsbr100_start(struct dsbr100_device *radio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 203 | int retval; |
| 204 | int request; |
| 205 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 206 | mutex_lock(&radio->lock); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 207 | |
| 208 | retval = usb_control_msg(radio->usbdev, |
| 209 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 210 | USB_REQ_GET_STATUS, |
| 211 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 212 | 0x00, 0xC7, radio->transfer_buffer, 8, 300); |
| 213 | |
| 214 | if (retval < 0) { |
| 215 | request = USB_REQ_GET_STATUS; |
| 216 | goto usb_control_msg_failed; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 217 | } |
| 218 | |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 219 | retval = usb_control_msg(radio->usbdev, |
| 220 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 221 | DSB100_ONOFF, |
| 222 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 223 | 0x01, 0x00, radio->transfer_buffer, 8, 300); |
| 224 | |
| 225 | if (retval < 0) { |
| 226 | request = DSB100_ONOFF; |
| 227 | goto usb_control_msg_failed; |
| 228 | } |
| 229 | |
| 230 | radio->muted = 0; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 231 | mutex_unlock(&radio->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return (radio->transfer_buffer)[0]; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 233 | |
| 234 | usb_control_msg_failed: |
| 235 | mutex_unlock(&radio->lock); |
| 236 | dev_err(&radio->usbdev->dev, |
| 237 | "%s - usb_control_msg returned %i, request %i\n", |
| 238 | __func__, retval, request); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 239 | return retval; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* switch off radio */ |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 244 | static int dsbr100_stop(struct dsbr100_device *radio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 246 | int retval; |
| 247 | int request; |
| 248 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 249 | mutex_lock(&radio->lock); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 250 | |
| 251 | retval = usb_control_msg(radio->usbdev, |
| 252 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 253 | USB_REQ_GET_STATUS, |
| 254 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 255 | 0x16, 0x1C, radio->transfer_buffer, 8, 300); |
| 256 | |
| 257 | if (retval < 0) { |
| 258 | request = USB_REQ_GET_STATUS; |
| 259 | goto usb_control_msg_failed; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 260 | } |
| 261 | |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 262 | retval = usb_control_msg(radio->usbdev, |
| 263 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 264 | DSB100_ONOFF, |
| 265 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 266 | 0x00, 0x00, radio->transfer_buffer, 8, 300); |
| 267 | |
| 268 | if (retval < 0) { |
| 269 | request = DSB100_ONOFF; |
| 270 | goto usb_control_msg_failed; |
| 271 | } |
| 272 | |
| 273 | radio->muted = 1; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 274 | mutex_unlock(&radio->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | return (radio->transfer_buffer)[0]; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 276 | |
| 277 | usb_control_msg_failed: |
| 278 | mutex_unlock(&radio->lock); |
| 279 | dev_err(&radio->usbdev->dev, |
| 280 | "%s - usb_control_msg returned %i, request %i\n", |
| 281 | __func__, retval, request); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 282 | return retval; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 287 | static int dsbr100_setfreq(struct dsbr100_device *radio, int freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 289 | int retval; |
| 290 | int request; |
| 291 | |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 292 | freq = (freq / 16 * 80) / 1000 + 856; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 293 | mutex_lock(&radio->lock); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 294 | |
| 295 | retval = usb_control_msg(radio->usbdev, |
| 296 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 297 | DSB100_TUNE, |
| 298 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 299 | (freq >> 8) & 0x00ff, freq & 0xff, |
| 300 | radio->transfer_buffer, 8, 300); |
| 301 | |
| 302 | if (retval < 0) { |
| 303 | request = DSB100_TUNE; |
| 304 | goto usb_control_msg_failed; |
| 305 | } |
| 306 | |
| 307 | retval = usb_control_msg(radio->usbdev, |
| 308 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 309 | USB_REQ_GET_STATUS, |
| 310 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 311 | 0x96, 0xB7, radio->transfer_buffer, 8, 300); |
| 312 | |
| 313 | if (retval < 0) { |
| 314 | request = USB_REQ_GET_STATUS; |
| 315 | goto usb_control_msg_failed; |
| 316 | } |
| 317 | |
| 318 | retval = usb_control_msg(radio->usbdev, |
| 319 | usb_rcvctrlpipe(radio->usbdev, 0), |
| 320 | USB_REQ_GET_STATUS, |
| 321 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 322 | 0x00, 0x24, radio->transfer_buffer, 8, 300); |
| 323 | |
| 324 | if (retval < 0) { |
| 325 | request = USB_REQ_GET_STATUS; |
| 326 | goto usb_control_msg_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 328 | |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 329 | radio->stereo = !((radio->transfer_buffer)[0] & 0x01); |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 330 | mutex_unlock(&radio->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return (radio->transfer_buffer)[0]; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 332 | |
| 333 | usb_control_msg_failed: |
| 334 | radio->stereo = -1; |
| 335 | mutex_unlock(&radio->lock); |
| 336 | dev_err(&radio->usbdev->dev, |
| 337 | "%s - usb_control_msg returned %i, request %i\n", |
| 338 | __func__, retval, request); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 339 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* return the device status. This is, in effect, just whether it |
| 343 | sees a stereo signal or not. Pity. */ |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 344 | static void dsbr100_getstat(struct dsbr100_device *radio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 346 | int retval; |
| 347 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 348 | mutex_lock(&radio->lock); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 349 | |
| 350 | retval = usb_control_msg(radio->usbdev, |
| 351 | usb_rcvctrlpipe(radio->usbdev, 0), |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 352 | USB_REQ_GET_STATUS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 354 | 0x00 , 0x24, radio->transfer_buffer, 8, 300); |
| 355 | |
| 356 | if (retval < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | radio->stereo = -1; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 358 | dev_err(&radio->usbdev->dev, |
| 359 | "%s - usb_control_msg returned %i, request %i\n", |
| 360 | __func__, retval, USB_REQ_GET_STATUS); |
| 361 | } else { |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 362 | radio->stereo = !(radio->transfer_buffer[0] & 0x01); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 363 | } |
| 364 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 365 | mutex_unlock(&radio->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* USB subsystem interface begins here */ |
| 369 | |
Alexey Klimov | fc55bcb | 2008-12-27 22:33:54 -0300 | [diff] [blame] | 370 | /* |
| 371 | * Handle unplugging of the device. |
| 372 | * We call video_unregister_device in any case. |
| 373 | * The last function called in this procedure is |
| 374 | * usb_dsbr100_video_device_release |
| 375 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | static void usb_dsbr100_disconnect(struct usb_interface *intf) |
| 377 | { |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 378 | struct dsbr100_device *radio = usb_get_intfdata(intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | usb_set_intfdata (intf, NULL); |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 381 | |
| 382 | mutex_lock(&radio->lock); |
| 383 | radio->removed = 1; |
| 384 | mutex_unlock(&radio->lock); |
| 385 | |
| 386 | video_unregister_device(&radio->videodev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 390 | static int vidioc_querycap(struct file *file, void *priv, |
| 391 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Alexey Klimov | c7181cf | 2009-01-25 20:05:58 -0300 | [diff] [blame] | 393 | struct dsbr100_device *radio = video_drvdata(file); |
| 394 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 395 | strlcpy(v->driver, "dsbr100", sizeof(v->driver)); |
| 396 | strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card)); |
Alexey Klimov | c7181cf | 2009-01-25 20:05:58 -0300 | [diff] [blame] | 397 | usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info)); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 398 | v->version = RADIO_VERSION; |
| 399 | v->capabilities = V4L2_CAP_TUNER; |
| 400 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 403 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 404 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 406 | struct dsbr100_device *radio = video_drvdata(file); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 407 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 408 | /* safety check */ |
| 409 | if (radio->removed) |
| 410 | return -EIO; |
| 411 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 412 | if (v->index > 0) |
| 413 | return -EINVAL; |
| 414 | |
| 415 | dsbr100_getstat(radio); |
| 416 | strcpy(v->name, "FM"); |
| 417 | v->type = V4L2_TUNER_RADIO; |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 418 | v->rangelow = FREQ_MIN * FREQ_MUL; |
| 419 | v->rangehigh = FREQ_MAX * FREQ_MUL; |
| 420 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 421 | v->capability = V4L2_TUNER_CAP_LOW; |
| 422 | if(radio->stereo) |
| 423 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 424 | else |
| 425 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 426 | v->signal = 0xffff; /* We can't get the signal strength */ |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 431 | struct v4l2_tuner *v) |
| 432 | { |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 433 | struct dsbr100_device *radio = video_drvdata(file); |
| 434 | |
| 435 | /* safety check */ |
| 436 | if (radio->removed) |
| 437 | return -EIO; |
| 438 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 439 | if (v->index > 0) |
| 440 | return -EINVAL; |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 446 | struct v4l2_frequency *f) |
| 447 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 448 | struct dsbr100_device *radio = video_drvdata(file); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 449 | int retval; |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 450 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 451 | /* safety check */ |
| 452 | if (radio->removed) |
| 453 | return -EIO; |
| 454 | |
Alexey Klimov | fdf9c99 | 2009-02-08 02:00:14 -0300 | [diff] [blame^] | 455 | mutex_lock(&radio->lock); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 456 | radio->curfreq = f->frequency; |
Alexey Klimov | fdf9c99 | 2009-02-08 02:00:14 -0300 | [diff] [blame^] | 457 | mutex_unlock(&radio->lock); |
| 458 | |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 459 | retval = dsbr100_setfreq(radio, radio->curfreq); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 460 | if (retval < 0) |
Greg Kroah-Hartman | aa82661 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 461 | dev_warn(&radio->usbdev->dev, "Set frequency failed\n"); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 466 | struct v4l2_frequency *f) |
| 467 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 468 | struct dsbr100_device *radio = video_drvdata(file); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 469 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 470 | /* safety check */ |
| 471 | if (radio->removed) |
| 472 | return -EIO; |
| 473 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 474 | f->type = V4L2_TUNER_RADIO; |
| 475 | f->frequency = radio->curfreq; |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 480 | struct v4l2_queryctrl *qc) |
| 481 | { |
| 482 | int i; |
| 483 | |
| 484 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 485 | if (qc->id && qc->id == radio_qctrl[i].id) { |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 486 | memcpy(qc, &(radio_qctrl[i]), sizeof(*qc)); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | } |
| 490 | return -EINVAL; |
| 491 | } |
| 492 | |
| 493 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 494 | struct v4l2_control *ctrl) |
| 495 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 496 | struct dsbr100_device *radio = video_drvdata(file); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 497 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 498 | /* safety check */ |
| 499 | if (radio->removed) |
| 500 | return -EIO; |
| 501 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 502 | switch (ctrl->id) { |
| 503 | case V4L2_CID_AUDIO_MUTE: |
| 504 | ctrl->value = radio->muted; |
| 505 | return 0; |
| 506 | } |
| 507 | return -EINVAL; |
| 508 | } |
| 509 | |
| 510 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 511 | struct v4l2_control *ctrl) |
| 512 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 513 | struct dsbr100_device *radio = video_drvdata(file); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 514 | int retval; |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 515 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 516 | /* safety check */ |
| 517 | if (radio->removed) |
| 518 | return -EIO; |
| 519 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 520 | switch (ctrl->id) { |
| 521 | case V4L2_CID_AUDIO_MUTE: |
| 522 | if (ctrl->value) { |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 523 | retval = dsbr100_stop(radio); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 524 | if (retval < 0) { |
Greg Kroah-Hartman | aa82661 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 525 | dev_warn(&radio->usbdev->dev, |
| 526 | "Radio did not respond properly\n"); |
Alexey Klimov | 90b698d | 2008-10-09 13:42:32 -0300 | [diff] [blame] | 527 | return -EBUSY; |
| 528 | } |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 529 | } else { |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 530 | retval = dsbr100_start(radio); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 531 | if (retval < 0) { |
Greg Kroah-Hartman | aa82661 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 532 | dev_warn(&radio->usbdev->dev, |
| 533 | "Radio did not respond properly\n"); |
Alexey Klimov | 90b698d | 2008-10-09 13:42:32 -0300 | [diff] [blame] | 534 | return -EBUSY; |
| 535 | } |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 536 | } |
| 537 | return 0; |
| 538 | } |
| 539 | return -EINVAL; |
| 540 | } |
| 541 | |
| 542 | static int vidioc_g_audio(struct file *file, void *priv, |
| 543 | struct v4l2_audio *a) |
| 544 | { |
| 545 | if (a->index > 1) |
| 546 | return -EINVAL; |
| 547 | |
| 548 | strcpy(a->name, "Radio"); |
| 549 | a->capability = V4L2_AUDCAP_STEREO; |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 554 | { |
| 555 | *i = 0; |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 560 | { |
| 561 | if (i != 0) |
| 562 | return -EINVAL; |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int vidioc_s_audio(struct file *file, void *priv, |
| 567 | struct v4l2_audio *a) |
| 568 | { |
| 569 | if (a->index != 0) |
| 570 | return -EINVAL; |
| 571 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 574 | static int usb_dsbr100_open(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 576 | struct dsbr100_device *radio = video_drvdata(file); |
Alexey Klimov | b9f3573 | 2008-10-20 00:00:03 -0300 | [diff] [blame] | 577 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 579 | lock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | radio->users = 1; |
Alan Cox | 5aff308 | 2006-08-08 15:47:50 -0300 | [diff] [blame] | 581 | radio->muted = 1; |
| 582 | |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 583 | retval = dsbr100_start(radio); |
| 584 | if (retval < 0) { |
Greg Kroah-Hartman | aa82661 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 585 | dev_warn(&radio->usbdev->dev, |
| 586 | "Radio did not start up properly\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | radio->users = 0; |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 588 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | return -EIO; |
| 590 | } |
Alexey Klimov | b9f3573 | 2008-10-20 00:00:03 -0300 | [diff] [blame] | 591 | |
| 592 | retval = dsbr100_setfreq(radio, radio->curfreq); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 593 | if (retval < 0) |
Alexey Klimov | 290588e | 2008-12-27 21:42:39 -0300 | [diff] [blame] | 594 | dev_warn(&radio->usbdev->dev, |
| 595 | "set frequency failed\n"); |
Alexey Klimov | b9f3573 | 2008-10-20 00:00:03 -0300 | [diff] [blame] | 596 | |
Hans Verkuil | d56dc61 | 2008-07-30 08:43:36 -0300 | [diff] [blame] | 597 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | return 0; |
| 599 | } |
| 600 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 601 | static int usb_dsbr100_close(struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 603 | struct dsbr100_device *radio = video_drvdata(file); |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 604 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | if (!radio) |
| 607 | return -ENODEV; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 608 | |
Alexey Klimov | fdf9c99 | 2009-02-08 02:00:14 -0300 | [diff] [blame^] | 609 | mutex_lock(&radio->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | radio->users = 0; |
Alexey Klimov | fdf9c99 | 2009-02-08 02:00:14 -0300 | [diff] [blame^] | 611 | mutex_unlock(&radio->lock); |
| 612 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 613 | if (!radio->removed) { |
| 614 | retval = dsbr100_stop(radio); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 615 | if (retval < 0) { |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 616 | dev_warn(&radio->usbdev->dev, |
| 617 | "dsbr100_stop failed\n"); |
| 618 | } |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | return 0; |
| 622 | } |
| 623 | |
Alexey Klimov | 04e0ffb | 2008-11-08 00:40:46 -0300 | [diff] [blame] | 624 | /* Suspend device - stop device. */ |
| 625 | static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message) |
| 626 | { |
| 627 | struct dsbr100_device *radio = usb_get_intfdata(intf); |
| 628 | int retval; |
| 629 | |
| 630 | retval = dsbr100_stop(radio); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 631 | if (retval < 0) |
Alexey Klimov | 04e0ffb | 2008-11-08 00:40:46 -0300 | [diff] [blame] | 632 | dev_warn(&intf->dev, "dsbr100_stop failed\n"); |
| 633 | |
| 634 | dev_info(&intf->dev, "going into suspend..\n"); |
| 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | /* Resume device - start device. */ |
| 640 | static int usb_dsbr100_resume(struct usb_interface *intf) |
| 641 | { |
| 642 | struct dsbr100_device *radio = usb_get_intfdata(intf); |
| 643 | int retval; |
| 644 | |
| 645 | retval = dsbr100_start(radio); |
Alexey Klimov | d25cb64 | 2008-12-27 22:40:57 -0300 | [diff] [blame] | 646 | if (retval < 0) |
Alexey Klimov | 04e0ffb | 2008-11-08 00:40:46 -0300 | [diff] [blame] | 647 | dev_warn(&intf->dev, "dsbr100_start failed\n"); |
| 648 | |
| 649 | dev_info(&intf->dev, "coming out of suspend..\n"); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Alexey Klimov | fc55bcb | 2008-12-27 22:33:54 -0300 | [diff] [blame] | 654 | /* free data structures */ |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 655 | static void usb_dsbr100_video_device_release(struct video_device *videodev) |
| 656 | { |
| 657 | struct dsbr100_device *radio = videodev_to_radio(videodev); |
| 658 | |
| 659 | kfree(radio->transfer_buffer); |
| 660 | kfree(radio); |
| 661 | } |
| 662 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 663 | /* File system interface */ |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 664 | static const struct v4l2_file_operations usb_dsbr100_fops = { |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 665 | .owner = THIS_MODULE, |
| 666 | .open = usb_dsbr100_open, |
| 667 | .release = usb_dsbr100_close, |
| 668 | .ioctl = video_ioctl2, |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 669 | }; |
| 670 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 671 | static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = { |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 672 | .vidioc_querycap = vidioc_querycap, |
| 673 | .vidioc_g_tuner = vidioc_g_tuner, |
| 674 | .vidioc_s_tuner = vidioc_s_tuner, |
| 675 | .vidioc_g_frequency = vidioc_g_frequency, |
| 676 | .vidioc_s_frequency = vidioc_s_frequency, |
| 677 | .vidioc_queryctrl = vidioc_queryctrl, |
| 678 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 679 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 680 | .vidioc_g_audio = vidioc_g_audio, |
| 681 | .vidioc_s_audio = vidioc_s_audio, |
| 682 | .vidioc_g_input = vidioc_g_input, |
| 683 | .vidioc_s_input = vidioc_s_input, |
| 684 | }; |
| 685 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 686 | /* V4L2 interface */ |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 687 | static struct video_device dsbr100_videodev_data = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 688 | .name = "D-Link DSB-R 100", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 689 | .fops = &usb_dsbr100_fops, |
| 690 | .ioctl_ops = &usb_dsbr100_ioctl_ops, |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 691 | .release = usb_dsbr100_video_device_release, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 692 | }; |
| 693 | |
Alexey Klimov | fc55bcb | 2008-12-27 22:33:54 -0300 | [diff] [blame] | 694 | /* check if the device is present and register with v4l and usb if it is */ |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 695 | static int usb_dsbr100_probe(struct usb_interface *intf, |
| 696 | const struct usb_device_id *id) |
| 697 | { |
| 698 | struct dsbr100_device *radio; |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 699 | int retval; |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 700 | |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 701 | radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL); |
| 702 | |
| 703 | if (!radio) |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 704 | return -ENOMEM; |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 705 | |
| 706 | radio->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL); |
| 707 | |
| 708 | if (!(radio->transfer_buffer)) { |
Oliver Neukum | 863c86d | 2007-12-03 06:48:43 -0300 | [diff] [blame] | 709 | kfree(radio); |
| 710 | return -ENOMEM; |
| 711 | } |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 712 | |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 713 | mutex_init(&radio->lock); |
| 714 | radio->videodev = dsbr100_videodev_data; |
| 715 | |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 716 | radio->removed = 0; |
| 717 | radio->users = 0; |
| 718 | radio->usbdev = interface_to_usbdev(intf); |
Alexey Klimov | 223377e | 2008-10-19 23:50:27 -0300 | [diff] [blame] | 719 | radio->curfreq = FREQ_MIN * FREQ_MUL; |
Alexey Klimov | 3a0efc3 | 2008-12-27 21:32:49 -0300 | [diff] [blame] | 720 | video_set_drvdata(&radio->videodev, radio); |
Alexey Klimov | 417b795 | 2008-12-27 22:30:29 -0300 | [diff] [blame] | 721 | retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr); |
| 722 | if (retval < 0) { |
Alexey Klimov | 7e1ca84 | 2008-12-27 22:31:52 -0300 | [diff] [blame] | 723 | dev_err(&intf->dev, "couldn't register video device\n"); |
Oliver Neukum | 863c86d | 2007-12-03 06:48:43 -0300 | [diff] [blame] | 724 | kfree(radio->transfer_buffer); |
Douglas Landgraf | 7002a4f | 2007-05-07 16:43:01 -0300 | [diff] [blame] | 725 | kfree(radio); |
| 726 | return -EIO; |
| 727 | } |
| 728 | usb_set_intfdata(intf, radio); |
| 729 | return 0; |
| 730 | } |
| 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | static int __init dsbr100_init(void) |
| 733 | { |
| 734 | int retval = usb_register(&usb_dsbr100_driver); |
Greg Kroah-Hartman | a482f32 | 2008-10-10 05:08:23 -0300 | [diff] [blame] | 735 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 736 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return retval; |
| 738 | } |
| 739 | |
| 740 | static void __exit dsbr100_exit(void) |
| 741 | { |
| 742 | usb_deregister(&usb_dsbr100_driver); |
| 743 | } |
| 744 | |
| 745 | module_init (dsbr100_init); |
| 746 | module_exit (dsbr100_exit); |
| 747 | |
| 748 | MODULE_AUTHOR( DRIVER_AUTHOR ); |
| 749 | MODULE_DESCRIPTION( DRIVER_DESC ); |
| 750 | MODULE_LICENSE("GPL"); |