blob: cecf7d7c2136da33af8918a7efdc02722f537934 [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>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040026#include <linux/module.h>
Richard Röjforsd44d1f32010-02-03 12:59:39 -030027#include <media/timb_radio.h>
28
29#define DRIVER_NAME "timb-radio"
30
31struct 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;
Hans Verkuil4f687752010-11-16 18:13:06 -030037 struct mutex lock;
Richard Röjforsd44d1f32010-02-03 12:59:39 -030038};
39
40
41static int timbradio_vidioc_querycap(struct file *file, void *priv,
42 struct v4l2_capability *v)
43{
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);
Hans Verkuild020f832013-02-03 09:05:16 -030047 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
48 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
Richard Röjforsd44d1f32010-02-03 12:59:39 -030049 return 0;
50}
51
52static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
53 struct v4l2_tuner *v)
54{
55 struct timbradio *tr = video_drvdata(file);
56 return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
57}
58
59static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -030060 const struct v4l2_tuner *v)
Richard Röjforsd44d1f32010-02-03 12:59:39 -030061{
62 struct timbradio *tr = video_drvdata(file);
63 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
64}
65
Richard Röjforsd44d1f32010-02-03 12:59:39 -030066static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
Hans Verkuilb530a442013-03-19 04:09:26 -030067 const struct v4l2_frequency *f)
Richard Röjforsd44d1f32010-02-03 12:59:39 -030068{
69 struct timbradio *tr = video_drvdata(file);
70 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
71}
72
73static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
74 struct v4l2_frequency *f)
75{
76 struct timbradio *tr = video_drvdata(file);
77 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
78}
79
80static int timbradio_vidioc_queryctrl(struct file *file, void *priv,
81 struct v4l2_queryctrl *qc)
82{
83 struct timbradio *tr = video_drvdata(file);
84 return v4l2_subdev_call(tr->sd_dsp, core, queryctrl, qc);
85}
86
87static int timbradio_vidioc_g_ctrl(struct file *file, void *priv,
88 struct v4l2_control *ctrl)
89{
90 struct timbradio *tr = video_drvdata(file);
91 return v4l2_subdev_call(tr->sd_dsp, core, g_ctrl, ctrl);
92}
93
94static int timbradio_vidioc_s_ctrl(struct file *file, void *priv,
95 struct v4l2_control *ctrl)
96{
97 struct timbradio *tr = video_drvdata(file);
98 return v4l2_subdev_call(tr->sd_dsp, core, s_ctrl, ctrl);
99}
100
101static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
102 .vidioc_querycap = timbradio_vidioc_querycap,
103 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
104 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
105 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
106 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300107 .vidioc_queryctrl = timbradio_vidioc_queryctrl,
108 .vidioc_g_ctrl = timbradio_vidioc_g_ctrl,
109 .vidioc_s_ctrl = timbradio_vidioc_s_ctrl
110};
111
112static const struct v4l2_file_operations timbradio_fops = {
113 .owner = THIS_MODULE,
Hans Verkuil4f687752010-11-16 18:13:06 -0300114 .unlocked_ioctl = video_ioctl2,
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300115};
116
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800117static int timbradio_probe(struct platform_device *pdev)
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300118{
Samuel Ortiz3271d382011-04-08 01:23:57 +0200119 struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300120 struct timbradio *tr;
121 int err;
122
123 if (!pdata) {
124 dev_err(&pdev->dev, "Platform data missing\n");
125 err = -EINVAL;
126 goto err;
127 }
128
Julia Lawall2f20c492012-07-31 05:21:37 -0300129 tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300130 if (!tr) {
131 err = -ENOMEM;
132 goto err;
133 }
134
135 tr->pdata = *pdata;
Hans Verkuil4f687752010-11-16 18:13:06 -0300136 mutex_init(&tr->lock);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300137
138 strlcpy(tr->video_dev.name, "Timberdale Radio",
139 sizeof(tr->video_dev.name));
140 tr->video_dev.fops = &timbradio_fops;
141 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
142 tr->video_dev.release = video_device_release_empty;
143 tr->video_dev.minor = -1;
Hans Verkuil4f687752010-11-16 18:13:06 -0300144 tr->video_dev.lock = &tr->lock;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300145
146 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
147 err = v4l2_device_register(NULL, &tr->v4l2_dev);
148 if (err)
Julia Lawall2f20c492012-07-31 05:21:37 -0300149 goto err;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300150
151 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
152
153 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
154 if (err) {
155 dev_err(&pdev->dev, "Error reg video\n");
156 goto err_video_req;
157 }
158
159 video_set_drvdata(&tr->video_dev, tr);
160
161 platform_set_drvdata(pdev, tr);
162 return 0;
163
164err_video_req:
165 video_device_release_empty(&tr->video_dev);
166 v4l2_device_unregister(&tr->v4l2_dev);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300167err:
168 dev_err(&pdev->dev, "Failed to register: %d\n", err);
169
170 return err;
171}
172
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800173static int timbradio_remove(struct platform_device *pdev)
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300174{
175 struct timbradio *tr = platform_get_drvdata(pdev);
176
177 video_unregister_device(&tr->video_dev);
178 video_device_release_empty(&tr->video_dev);
179
180 v4l2_device_unregister(&tr->v4l2_dev);
181
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300182 return 0;
183}
184
185static struct platform_driver timbradio_platform_driver = {
186 .driver = {
187 .name = DRIVER_NAME,
188 .owner = THIS_MODULE,
189 },
190 .probe = timbradio_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800191 .remove = timbradio_remove,
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300192};
193
Axel Lin1d6629b2012-01-10 03:21:49 -0300194module_platform_driver(timbradio_platform_driver);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300195
196MODULE_DESCRIPTION("Timberdale Radio driver");
197MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
198MODULE_LICENSE("GPL v2");
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -0300199MODULE_VERSION("0.0.2");
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300200MODULE_ALIAS("platform:"DRIVER_NAME);