57 #include <linux/kernel.h>
58 #include <linux/module.h>
60 #include <linux/slab.h>
61 #include <linux/input.h>
62 #include <linux/videodev2.h>
72 #define DRIVER_DESC "AverMedia MR 800 USB FM radio driver"
73 #define DRIVER_VERSION "0.1.2"
80 #define USB_AMRADIO_VENDOR 0x07ca
81 #define USB_AMRADIO_PRODUCT 0xb800
84 #define MR800_DRIVER_NAME "radio-mr800"
85 #define amradio_dev_warn(dev, fmt, arg...) \
86 dev_warn(dev, MR800_DRIVER_NAME " - " fmt, ##arg)
88 #define amradio_dev_err(dev, fmt, arg...) \
89 dev_err(dev, MR800_DRIVER_NAME " - " fmt, ##arg)
92 #define BUFFER_LENGTH 8
93 #define USB_TIMEOUT 500
98 #define FREQ_MAX 108.0
99 #define FREQ_MUL 16000
105 #define AMRADIO_SET_FREQ 0xa4
106 #define AMRADIO_GET_READY_FLAG 0xa5
107 #define AMRADIO_GET_SIGNAL 0xa7
108 #define AMRADIO_GET_FREQ 0xa8
109 #define AMRADIO_SET_SEARCH_UP 0xa9
110 #define AMRADIO_SET_SEARCH_DOWN 0xaa
111 #define AMRADIO_SET_MUTE 0xab
112 #define AMRADIO_SET_RIGHT_MUTE 0xac
113 #define AMRADIO_SET_LEFT_MUTE 0xad
114 #define AMRADIO_SET_MONO 0xae
115 #define AMRADIO_SET_SEARCH_LVL 0xb0
116 #define AMRADIO_STOP_SEARCH 0xb1
119 #define WANT_STEREO 0x00
120 #define WANT_MONO 0x01
123 static int radio_nr = -1;
157 radio->
buffer[3] = extralen;
161 radio->
buffer[7] = extra || reply ? 8 : 0;
167 if (video_is_registered(&radio->
vdev))
169 "cmd %02x failed\n", cmd);
170 return retval ? retval : -
EIO;
172 if (!extra && !reply)
189 return retval ? retval : -
EIO;
195 int ret = amradio_send_cmd(radio,
206 unsigned short freq_send = 0x10 + (freq >> 3) / 25;
211 buf[0] = (freq_send >> 8) & 0xff;
212 buf[1] = freq_send & 0xff;
225 int ret = amradio_send_cmd(radio,
233 static int amradio_get_stat(
struct amradio_device *radio,
bool *is_stereo,
u32 *signal)
235 int ret = amradio_send_cmd(radio,
240 *is_stereo = radio->
buffer[2] >> 7;
241 *signal = (radio->
buffer[3] & 0xf0) << 8;
252 struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
256 amradio_set_mute(radio,
true);
257 usb_set_intfdata(intf,
NULL);
264 static int vidioc_querycap(
struct file *
file,
void *
priv,
279 static int vidioc_g_tuner(
struct file *
file,
void *
priv,
283 bool is_stereo =
false;
290 retval = amradio_get_stat(radio, &is_stereo, &v->
signal);
307 static int vidioc_s_tuner(
struct file *file,
void *priv,
318 return amradio_set_stereo(radio,
WANT_MONO);
325 static int vidioc_s_frequency(
struct file *file,
void *priv,
337 static int vidioc_g_frequency(
struct file *file,
void *priv,
350 static int vidioc_s_hw_freq_seek(
struct file *file,
void *priv,
354 0x3d, 0x32, 0x0f, 0x08, 0x3d, 0x32, 0x0f, 0x08
366 retval = amradio_send_cmd(radio,
370 amradio_set_freq(radio, radio->
curfreq);
371 retval = amradio_send_cmd(radio,
396 amradio_set_freq(radio, radio->
curfreq);
402 amradio_set_freq(radio, radio->
curfreq);
413 return amradio_set_mute(radio, ctrl->
val);
423 retval = amradio_set_mute(radio,
true);
426 retval = amradio_set_stereo(radio,
true);
429 retval = amradio_set_freq(radio, radio->
curfreq);
442 struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
446 amradio_set_mute(radio,
true);
447 radio->
muted =
false;
451 dev_info(&intf->dev,
"going into suspend..\n");
458 struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
461 amradio_set_stereo(radio, radio->
stereo);
462 amradio_set_freq(radio, radio->
curfreq);
465 amradio_set_mute(radio,
false);
469 dev_info(&intf->dev,
"coming out of suspend..\n");
474 .s_ctrl = usb_amradio_s_ctrl,
498 static void usb_amradio_release(
struct v4l2_device *v4l2_dev)
519 dev_err(&intf->dev,
"kmalloc for amradio_device failed\n");
527 dev_err(&intf->dev,
"kmalloc for radio->buffer failed\n");
534 dev_err(&intf->dev,
"couldn't register v4l2_device\n");
541 if (radio->
hdl.error) {
542 retval = radio->
hdl.error;
543 dev_err(&intf->dev,
"couldn't register control\n");
549 radio->
v4l2_dev.release = usb_amradio_release;
551 sizeof(radio->
vdev.name));
553 radio->
vdev.fops = &usb_amradio_fops;
554 radio->
vdev.ioctl_ops = &usb_amradio_ioctl_ops;
559 radio->
usbdev = interface_to_usbdev(intf);
561 usb_set_intfdata(intf, &radio->
v4l2_dev);
564 video_set_drvdata(&radio->
vdev, radio);
565 retval = usb_amradio_init(radio);
572 dev_err(&intf->dev,
"could not register video device\n");
600 static struct usb_driver usb_amradio_driver = {
602 .probe = usb_amradio_probe,
603 .disconnect = usb_amradio_disconnect,
604 .suspend = usb_amradio_suspend,
605 .resume = usb_amradio_resume,
606 .reset_resume = usb_amradio_resume,
607 .id_table = usb_amradio_device_table,