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