Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / drivers / media / radio / radio-timb.c
bloba185610b376be1a14e79b52751c7f95aab777dd0
1 /*
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>
20 #include <linux/io.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"
31 struct timbradio {
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;
37 struct mutex lock;
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;
49 return 0;
52 static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
53 struct v4l2_tuner *v)
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,
60 struct v4l2_tuner *v)
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,
67 unsigned int *i)
69 *i = 0;
70 return 0;
73 static int timbradio_vidioc_s_input(struct file *filp, void *priv,
74 unsigned int i)
76 return i ? -EINVAL : 0;
79 static int timbradio_vidioc_g_audio(struct file *file, void *priv,
80 struct v4l2_audio *a)
82 a->index = 0;
83 strlcpy(a->name, "Radio", sizeof(a->name));
84 a->capability = V4L2_AUDCAP_STEREO;
85 return 0;
88 static int timbradio_vidioc_s_audio(struct file *file, void *priv,
89 struct v4l2_audio *a)
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;
153 int err;
155 if (!pdata) {
156 dev_err(&pdev->dev, "Platform data missing\n");
157 err = -EINVAL;
158 goto err;
161 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
162 if (!tr) {
163 err = -ENOMEM;
164 goto err;
167 tr->pdata = *pdata;
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);
180 if (err)
181 goto err_v4l2_dev;
183 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
185 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
186 if (err) {
187 dev_err(&pdev->dev, "Error reg video\n");
188 goto err_video_req;
191 video_set_drvdata(&tr->video_dev, tr);
193 platform_set_drvdata(pdev, tr);
194 return 0;
196 err_video_req:
197 video_device_release_empty(&tr->video_dev);
198 v4l2_device_unregister(&tr->v4l2_dev);
199 err_v4l2_dev:
200 kfree(tr);
201 err:
202 dev_err(&pdev->dev, "Failed to register: %d\n", err);
204 return 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);
216 kfree(tr);
218 return 0;
221 static struct platform_driver timbradio_platform_driver = {
222 .driver = {
223 .name = DRIVER_NAME,
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);