31 #include <linux/export.h>
40 static u8 radio_disconnected;
46 size_t count, loff_t *ppos)
52 fmdev = video_drvdata(file);
54 if (!radio_disconnected) {
55 fmerr(
"FM device is already disconnected\n");
65 fmerr(
"Unable to read current rds mode\n");
72 fmerr(
"Failed to enable rds mode\n");
85 static ssize_t fm_v4l2_fops_write(
struct file *file,
const char __user * buf,
86 size_t count, loff_t *ppos)
93 rds.text[
sizeof(rds.text) - 1] =
'\0';
94 fmdbg(
"(%d)type: %d, text %s, af %d\n",
95 ret, rds.text_type, rds.text, rds.af_freq);
99 fmdev = video_drvdata(file);
114 fmdev = video_drvdata(file);
128 static int fm_v4l2_fops_open(
struct file *file)
131 struct fmdev *fmdev =
NULL;
134 if (radio_disconnected) {
135 fmerr(
"FM device is already opened\n");
139 fmdev = video_drvdata(file);
145 fmerr(
"Unable to prepare FM CORE\n");
149 fmdbg(
"Load FM RX firmware..\n");
153 fmerr(
"Unable to load FM RX firmware\n");
156 radio_disconnected = 1;
163 static int fm_v4l2_fops_release(
struct file *file)
168 fmdev = video_drvdata(file);
169 if (!radio_disconnected) {
170 fmdbg(
"FM device is already closed\n");
177 fmerr(
"Unable to turn off the chip\n");
183 fmerr(
"FM CORE release failed\n");
186 radio_disconnected = 0;
194 static int fm_v4l2_vidioc_querycap(
struct file *file,
void *
priv,
199 sizeof(capability->
card));
219 fmwarn(
"%s: Unknown IOCTL: %d\n", __func__, ctrl->
id);
226 static int fm_v4l2_s_ctrl(
struct v4l2_ctrl *ctrl)
250 static int fm_v4l2_vidioc_g_audio(
struct file *file,
void *
priv,
253 memset(audio, 0,
sizeof(*audio));
260 static int fm_v4l2_vidioc_s_audio(
struct file *file,
void *priv,
263 if (audio->
index != 0)
270 static int fm_v4l2_vidioc_g_tuner(
struct file *file,
void *priv,
273 struct fmdev *fmdev = video_drvdata(file);
276 u16 stereo_mono_mode;
280 if (tuner->
index != 0)
309 tuner->
audmode = (stereo_mono_mode ?
322 tuner->
signal = rssilvl * 257;
333 static int fm_v4l2_vidioc_s_tuner(
struct file *file,
void *priv,
336 struct fmdev *fmdev = video_drvdata(file);
341 if (tuner->
index != 0)
352 fmerr(
"Failed to set RX mode\n");
359 fmerr(
"Failed to set RX stereo/mono mode\n");
365 fmerr(
"Failed to set RX RDS mode\n");
371 static int fm_v4l2_vidioc_g_freq(
struct file *file,
void *priv,
374 struct fmdev *fmdev = video_drvdata(file);
379 fmerr(
"Failed to get frequency\n");
390 static int fm_v4l2_vidioc_s_freq(
struct file *file,
void *priv,
393 struct fmdev *fmdev = video_drvdata(file);
405 static int fm_v4l2_vidioc_s_hw_freq_seek(
struct file *file,
void *priv,
408 struct fmdev *fmdev = video_drvdata(file);
417 fmerr(
"Failed to set RX mode\n");
425 fmerr(
"RX seek failed - %d\n", ret);
430 static int fm_v4l2_vidioc_g_modulator(
struct file *file,
void *priv,
433 struct fmdev *fmdev = video_drvdata(file);
453 static int fm_v4l2_vidioc_s_modulator(
struct file *file,
void *priv,
456 struct fmdev *fmdev = video_drvdata(file);
467 fmerr(
"Failed to set TX mode\n");
478 fmerr(
"Failed to set mono/stereo mode for TX\n");
483 fmerr(
"Failed to set rds mode for TX\n");
490 .read = fm_v4l2_fops_read,
491 .write = fm_v4l2_fops_write,
492 .poll = fm_v4l2_fops_poll,
494 .open = fm_v4l2_fops_open,
495 .release = fm_v4l2_fops_release,
499 .s_ctrl = fm_v4l2_s_ctrl,
500 .g_volatile_ctrl = fm_g_volatile_ctrl,
503 .vidioc_querycap = fm_v4l2_vidioc_querycap,
504 .vidioc_g_audio = fm_v4l2_vidioc_g_audio,
505 .vidioc_s_audio = fm_v4l2_vidioc_s_audio,
506 .vidioc_g_tuner = fm_v4l2_vidioc_g_tuner,
507 .vidioc_s_tuner = fm_v4l2_vidioc_s_tuner,
508 .vidioc_g_frequency = fm_v4l2_vidioc_g_freq,
509 .vidioc_s_frequency = fm_v4l2_vidioc_s_freq,
510 .vidioc_s_hw_freq_seek = fm_v4l2_vidioc_s_hw_freq_seek,
511 .vidioc_g_modulator = fm_v4l2_vidioc_g_modulator,
512 .vidioc_s_modulator = fm_v4l2_vidioc_s_modulator
517 .fops = &fm_drv_fops,
518 .ioctl_ops = &fm_drv_ioctl_ops,
533 if (
NULL == gradio_dev) {
534 fmerr(
"Can't allocate video device\n");
539 memcpy(gradio_dev, &fm_viddev_template,
sizeof(fm_viddev_template));
541 video_set_drvdata(gradio_dev, fmdev);
546 if (video_register_device(gradio_dev,
VFL_TYPE_RADIO, radio_nr)) {
548 fmerr(
"Could not register video device\n");
559 fmerr(
"(fmdev): Can't init ctrl handler\n");
598 fmdev = video_get_drvdata(gradio_dev);