blob: f17b540d68a5e257662ab82afd1020ebce70872c [file] [log] [blame]
Richard Röjforsd44d1f32010-02-03 12:59:39 -03001/*
2 * radio-timb.c Timberdale FPGA Radio driver
3 * Copyright (c) 2009 Intel Corporation
4 *
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.
8 *
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.
13 *
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.
17 */
18
Richard Röjforsd44d1f32010-02-03 12:59:39 -030019#include <linux/io.h>
20#include <media/v4l2-ioctl.h>
21#include <media/v4l2-device.h>
22#include <linux/platform_device.h>
23#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Richard Röjforsd44d1f32010-02-03 12:59:39 -030025#include <linux/i2c.h>
26#include <media/timb_radio.h>
27
28#define DRIVER_NAME "timb-radio"
29
30struct timbradio {
31 struct timb_radio_platform_data pdata;
32 struct v4l2_subdev *sd_tuner;
33 struct v4l2_subdev *sd_dsp;
34 struct video_device video_dev;
35 struct v4l2_device v4l2_dev;
Hans Verkuil4f687752010-11-16 18:13:06 -030036 struct mutex lock;
Richard Röjforsd44d1f32010-02-03 12:59:39 -030037};
38
39
40static int timbradio_vidioc_querycap(struct file *file, void *priv,
41 struct v4l2_capability *v)
42{
43 strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
44 strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
45 snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
Richard Röjforsd44d1f32010-02-03 12:59:39 -030046 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
47 return 0;
48}
49
50static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
51 struct v4l2_tuner *v)
52{
53 struct timbradio *tr = video_drvdata(file);
54 return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
55}
56
57static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
58 struct v4l2_tuner *v)
59{
60 struct timbradio *tr = video_drvdata(file);
61 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
62}
63
64static int timbradio_vidioc_g_input(struct file *filp, void *priv,
65 unsigned int *i)
66{
67 *i = 0;
68 return 0;
69}
70
71static int timbradio_vidioc_s_input(struct file *filp, void *priv,
72 unsigned int i)
73{
74 return i ? -EINVAL : 0;
75}
76
77static int timbradio_vidioc_g_audio(struct file *file, void *priv,
78 struct v4l2_audio *a)
79{
80 a->index = 0;
81 strlcpy(a->name, "Radio", sizeof(a->name));
82 a->capability = V4L2_AUDCAP_STEREO;
83 return 0;
84}
85
86static int timbradio_vidioc_s_audio(struct file *file, void *priv,
87 struct v4l2_audio *a)
88{
89 return a->index ? -EINVAL : 0;
90}
91
92static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
93 struct v4l2_frequency *f)
94{
95 struct timbradio *tr = video_drvdata(file);
96 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
97}
98
99static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
100 struct v4l2_frequency *f)
101{
102 struct timbradio *tr = video_drvdata(file);
103 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
104}
105
106static int timbradio_vidioc_queryctrl(struct file *file, void *priv,
107 struct v4l2_queryctrl *qc)
108{
109 struct timbradio *tr = video_drvdata(file);
110 return v4l2_subdev_call(tr->sd_dsp, core, queryctrl, qc);
111}
112
113static int timbradio_vidioc_g_ctrl(struct file *file, void *priv,
114 struct v4l2_control *ctrl)
115{
116 struct timbradio *tr = video_drvdata(file);
117 return v4l2_subdev_call(tr->sd_dsp, core, g_ctrl, ctrl);
118}
119
120static int timbradio_vidioc_s_ctrl(struct file *file, void *priv,
121 struct v4l2_control *ctrl)
122{
123 struct timbradio *tr = video_drvdata(file);
124 return v4l2_subdev_call(tr->sd_dsp, core, s_ctrl, ctrl);
125}
126
127static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
128 .vidioc_querycap = timbradio_vidioc_querycap,
129 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
130 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
131 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
132 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
133 .vidioc_g_input = timbradio_vidioc_g_input,
134 .vidioc_s_input = timbradio_vidioc_s_input,
135 .vidioc_g_audio = timbradio_vidioc_g_audio,
136 .vidioc_s_audio = timbradio_vidioc_s_audio,
137 .vidioc_queryctrl = timbradio_vidioc_queryctrl,
138 .vidioc_g_ctrl = timbradio_vidioc_g_ctrl,
139 .vidioc_s_ctrl = timbradio_vidioc_s_ctrl
140};
141
142static const struct v4l2_file_operations timbradio_fops = {
143 .owner = THIS_MODULE,
Hans Verkuil4f687752010-11-16 18:13:06 -0300144 .unlocked_ioctl = video_ioctl2,
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300145};
146
147static int __devinit timbradio_probe(struct platform_device *pdev)
148{
Samuel Ortiz3271d382011-04-08 01:23:57 +0200149 struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300150 struct timbradio *tr;
151 int err;
152
153 if (!pdata) {
154 dev_err(&pdev->dev, "Platform data missing\n");
155 err = -EINVAL;
156 goto err;
157 }
158
159 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
160 if (!tr) {
161 err = -ENOMEM;
162 goto err;
163 }
164
165 tr->pdata = *pdata;
Hans Verkuil4f687752010-11-16 18:13:06 -0300166 mutex_init(&tr->lock);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300167
168 strlcpy(tr->video_dev.name, "Timberdale Radio",
169 sizeof(tr->video_dev.name));
170 tr->video_dev.fops = &timbradio_fops;
171 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
172 tr->video_dev.release = video_device_release_empty;
173 tr->video_dev.minor = -1;
Hans Verkuil4f687752010-11-16 18:13:06 -0300174 tr->video_dev.lock = &tr->lock;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300175
176 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
177 err = v4l2_device_register(NULL, &tr->v4l2_dev);
178 if (err)
179 goto err_v4l2_dev;
180
181 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
182
183 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
184 if (err) {
185 dev_err(&pdev->dev, "Error reg video\n");
186 goto err_video_req;
187 }
188
189 video_set_drvdata(&tr->video_dev, tr);
190
191 platform_set_drvdata(pdev, tr);
192 return 0;
193
194err_video_req:
195 video_device_release_empty(&tr->video_dev);
196 v4l2_device_unregister(&tr->v4l2_dev);
197err_v4l2_dev:
198 kfree(tr);
199err:
200 dev_err(&pdev->dev, "Failed to register: %d\n", err);
201
202 return err;
203}
204
205static int __devexit timbradio_remove(struct platform_device *pdev)
206{
207 struct timbradio *tr = platform_get_drvdata(pdev);
208
209 video_unregister_device(&tr->video_dev);
210 video_device_release_empty(&tr->video_dev);
211
212 v4l2_device_unregister(&tr->v4l2_dev);
213
214 kfree(tr);
215
216 return 0;
217}
218
219static struct platform_driver timbradio_platform_driver = {
220 .driver = {
221 .name = DRIVER_NAME,
222 .owner = THIS_MODULE,
223 },
224 .probe = timbradio_probe,
225 .remove = timbradio_remove,
226};
227
228/*--------------------------------------------------------------------------*/
229
230static int __init timbradio_init(void)
231{
232 return platform_driver_register(&timbradio_platform_driver);
233}
234
235static void __exit timbradio_exit(void)
236{
237 platform_driver_unregister(&timbradio_platform_driver);
238}
239
240module_init(timbradio_init);
241module_exit(timbradio_exit);
242
243MODULE_DESCRIPTION("Timberdale Radio driver");
244MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
245MODULE_LICENSE("GPL v2");
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -0300246MODULE_VERSION("0.0.2");
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300247MODULE_ALIAS("platform:"DRIVER_NAME);