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.
20 #include <media/v4l2-ioctl.h>
21 #include <media/v4l2-device.h>
22 #include <linux/platform_device.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/i2c.h>
26 #include <linux/module.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->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
48 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
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,
60 const 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_s_frequency(struct file *file, void *priv,
67 const struct v4l2_frequency *f)
69 struct timbradio *tr = video_drvdata(file);
70 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
73 static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
74 struct v4l2_frequency *f)
76 struct timbradio *tr = video_drvdata(file);
77 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
80 static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
81 .vidioc_querycap = timbradio_vidioc_querycap,
82 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
83 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
84 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
85 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
88 static const struct v4l2_file_operations timbradio_fops = {
90 .unlocked_ioctl = video_ioctl2,
93 static int timbradio_probe(struct platform_device *pdev)
95 struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
100 dev_err(&pdev->dev, "Platform data missing\n");
105 tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL);
112 mutex_init(&tr->lock);
114 strlcpy(tr->video_dev.name, "Timberdale Radio",
115 sizeof(tr->video_dev.name));
116 tr->video_dev.fops = &timbradio_fops;
117 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
118 tr->video_dev.release = video_device_release_empty;
119 tr->video_dev.minor = -1;
120 tr->video_dev.lock = &tr->lock;
122 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
123 err = v4l2_device_register(NULL, &tr->v4l2_dev);
127 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
129 tr->sd_tuner = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
130 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL);
131 tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
132 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL);
133 if (tr->sd_tuner == NULL || tr->sd_dsp == NULL)
136 tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler;
138 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
140 dev_err(&pdev->dev, "Error reg video\n");
144 video_set_drvdata(&tr->video_dev, tr);
146 platform_set_drvdata(pdev, tr);
150 v4l2_device_unregister(&tr->v4l2_dev);
152 dev_err(&pdev->dev, "Failed to register: %d\n", err);
157 static int timbradio_remove(struct platform_device *pdev)
159 struct timbradio *tr = platform_get_drvdata(pdev);
161 video_unregister_device(&tr->video_dev);
162 v4l2_device_unregister(&tr->v4l2_dev);
166 static struct platform_driver timbradio_platform_driver = {
169 .owner = THIS_MODULE,
171 .probe = timbradio_probe,
172 .remove = timbradio_remove,
175 module_platform_driver(timbradio_platform_driver);
177 MODULE_DESCRIPTION("Timberdale Radio driver");
178 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
179 MODULE_LICENSE("GPL v2");
180 MODULE_VERSION("0.0.2");
181 MODULE_ALIAS("platform:"DRIVER_NAME);