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