2 * radio-timb.c Timberdale FPGA Radio driver
3 * Copyright (c) 2009 Intel Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <linux/version.h>
21 #include <media/v4l2-ioctl.h>
22 #include <media/v4l2-device.h>
23 #include <linux/platform_device.h>
24 #include <linux/interrupt.h>
25 #include <linux/slab.h>
26 #include <linux/i2c.h>
27 #include <media/timb_radio.h>
29 #define DRIVER_NAME "timb-radio"
32 struct timb_radio_platform_data pdata
;
33 struct v4l2_subdev
*sd_tuner
;
34 struct v4l2_subdev
*sd_dsp
;
35 struct video_device video_dev
;
36 struct v4l2_device v4l2_dev
;
41 static int timbradio_vidioc_querycap(struct file
*file
, void *priv
,
42 struct v4l2_capability
*v
)
44 strlcpy(v
->driver
, DRIVER_NAME
, sizeof(v
->driver
));
45 strlcpy(v
->card
, "Timberdale Radio", sizeof(v
->card
));
46 snprintf(v
->bus_info
, sizeof(v
->bus_info
), "platform:"DRIVER_NAME
);
47 v
->version
= KERNEL_VERSION(0, 0, 1);
48 v
->capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_RADIO
;
52 static int timbradio_vidioc_g_tuner(struct file
*file
, void *priv
,
55 struct timbradio
*tr
= video_drvdata(file
);
56 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, g_tuner
, v
);
59 static int timbradio_vidioc_s_tuner(struct file
*file
, void *priv
,
62 struct timbradio
*tr
= video_drvdata(file
);
63 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, s_tuner
, v
);
66 static int timbradio_vidioc_g_input(struct file
*filp
, void *priv
,
73 static int timbradio_vidioc_s_input(struct file
*filp
, void *priv
,
76 return i
? -EINVAL
: 0;
79 static int timbradio_vidioc_g_audio(struct file
*file
, void *priv
,
83 strlcpy(a
->name
, "Radio", sizeof(a
->name
));
84 a
->capability
= V4L2_AUDCAP_STEREO
;
88 static int timbradio_vidioc_s_audio(struct file
*file
, void *priv
,
91 return a
->index
? -EINVAL
: 0;
94 static int timbradio_vidioc_s_frequency(struct file
*file
, void *priv
,
95 struct v4l2_frequency
*f
)
97 struct timbradio
*tr
= video_drvdata(file
);
98 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, s_frequency
, f
);
101 static int timbradio_vidioc_g_frequency(struct file
*file
, void *priv
,
102 struct v4l2_frequency
*f
)
104 struct timbradio
*tr
= video_drvdata(file
);
105 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, g_frequency
, f
);
108 static int timbradio_vidioc_queryctrl(struct file
*file
, void *priv
,
109 struct v4l2_queryctrl
*qc
)
111 struct timbradio
*tr
= video_drvdata(file
);
112 return v4l2_subdev_call(tr
->sd_dsp
, core
, queryctrl
, qc
);
115 static int timbradio_vidioc_g_ctrl(struct file
*file
, void *priv
,
116 struct v4l2_control
*ctrl
)
118 struct timbradio
*tr
= video_drvdata(file
);
119 return v4l2_subdev_call(tr
->sd_dsp
, core
, g_ctrl
, ctrl
);
122 static int timbradio_vidioc_s_ctrl(struct file
*file
, void *priv
,
123 struct v4l2_control
*ctrl
)
125 struct timbradio
*tr
= video_drvdata(file
);
126 return v4l2_subdev_call(tr
->sd_dsp
, core
, s_ctrl
, ctrl
);
129 static const struct v4l2_ioctl_ops timbradio_ioctl_ops
= {
130 .vidioc_querycap
= timbradio_vidioc_querycap
,
131 .vidioc_g_tuner
= timbradio_vidioc_g_tuner
,
132 .vidioc_s_tuner
= timbradio_vidioc_s_tuner
,
133 .vidioc_g_frequency
= timbradio_vidioc_g_frequency
,
134 .vidioc_s_frequency
= timbradio_vidioc_s_frequency
,
135 .vidioc_g_input
= timbradio_vidioc_g_input
,
136 .vidioc_s_input
= timbradio_vidioc_s_input
,
137 .vidioc_g_audio
= timbradio_vidioc_g_audio
,
138 .vidioc_s_audio
= timbradio_vidioc_s_audio
,
139 .vidioc_queryctrl
= timbradio_vidioc_queryctrl
,
140 .vidioc_g_ctrl
= timbradio_vidioc_g_ctrl
,
141 .vidioc_s_ctrl
= timbradio_vidioc_s_ctrl
144 static const struct v4l2_file_operations timbradio_fops
= {
145 .owner
= THIS_MODULE
,
146 .unlocked_ioctl
= video_ioctl2
,
149 static int __devinit
timbradio_probe(struct platform_device
*pdev
)
151 struct timb_radio_platform_data
*pdata
= pdev
->dev
.platform_data
;
152 struct timbradio
*tr
;
156 dev_err(&pdev
->dev
, "Platform data missing\n");
161 tr
= kzalloc(sizeof(*tr
), GFP_KERNEL
);
168 mutex_init(&tr
->lock
);
170 strlcpy(tr
->video_dev
.name
, "Timberdale Radio",
171 sizeof(tr
->video_dev
.name
));
172 tr
->video_dev
.fops
= &timbradio_fops
;
173 tr
->video_dev
.ioctl_ops
= &timbradio_ioctl_ops
;
174 tr
->video_dev
.release
= video_device_release_empty
;
175 tr
->video_dev
.minor
= -1;
176 tr
->video_dev
.lock
= &tr
->lock
;
178 strlcpy(tr
->v4l2_dev
.name
, DRIVER_NAME
, sizeof(tr
->v4l2_dev
.name
));
179 err
= v4l2_device_register(NULL
, &tr
->v4l2_dev
);
183 tr
->video_dev
.v4l2_dev
= &tr
->v4l2_dev
;
185 err
= video_register_device(&tr
->video_dev
, VFL_TYPE_RADIO
, -1);
187 dev_err(&pdev
->dev
, "Error reg video\n");
191 video_set_drvdata(&tr
->video_dev
, tr
);
193 platform_set_drvdata(pdev
, tr
);
197 video_device_release_empty(&tr
->video_dev
);
198 v4l2_device_unregister(&tr
->v4l2_dev
);
202 dev_err(&pdev
->dev
, "Failed to register: %d\n", err
);
207 static int __devexit
timbradio_remove(struct platform_device
*pdev
)
209 struct timbradio
*tr
= platform_get_drvdata(pdev
);
211 video_unregister_device(&tr
->video_dev
);
212 video_device_release_empty(&tr
->video_dev
);
214 v4l2_device_unregister(&tr
->v4l2_dev
);
221 static struct platform_driver timbradio_platform_driver
= {
224 .owner
= THIS_MODULE
,
226 .probe
= timbradio_probe
,
227 .remove
= timbradio_remove
,
230 /*--------------------------------------------------------------------------*/
232 static int __init
timbradio_init(void)
234 return platform_driver_register(&timbradio_platform_driver
);
237 static void __exit
timbradio_exit(void)
239 platform_driver_unregister(&timbradio_platform_driver
);
242 module_init(timbradio_init
);
243 module_exit(timbradio_exit
);
245 MODULE_DESCRIPTION("Timberdale Radio driver");
246 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
247 MODULE_LICENSE("GPL v2");
248 MODULE_ALIAS("platform:"DRIVER_NAME
);