blob: fc4d9a73ab17fc6ce41c466a43e761c2d2ea9576 [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.
Richard Röjforsd44d1f32010-02-03 12:59:39 -030013 */
14
Richard Röjforsd44d1f32010-02-03 12:59:39 -030015#include <linux/io.h>
16#include <media/v4l2-ioctl.h>
17#include <media/v4l2-device.h>
Hans Verkuil46821b12013-02-03 09:33:21 -030018#include <media/v4l2-ctrls.h>
19#include <media/v4l2-event.h>
Richard Röjforsd44d1f32010-02-03 12:59:39 -030020#include <linux/platform_device.h>
21#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Richard Röjforsd44d1f32010-02-03 12:59:39 -030023#include <linux/i2c.h>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040024#include <linux/module.h>
Mauro Carvalho Chehabeb4b0ec2015-11-16 08:35:53 -020025#include <linux/platform_data/media/timb_radio.h>
Richard Röjforsd44d1f32010-02-03 12:59:39 -030026
27#define DRIVER_NAME "timb-radio"
28
29struct timbradio {
30 struct timb_radio_platform_data pdata;
31 struct v4l2_subdev *sd_tuner;
32 struct v4l2_subdev *sd_dsp;
33 struct video_device video_dev;
34 struct v4l2_device v4l2_dev;
Hans Verkuil4f687752010-11-16 18:13:06 -030035 struct mutex lock;
Richard Röjforsd44d1f32010-02-03 12:59:39 -030036};
37
38
39static int timbradio_vidioc_querycap(struct file *file, void *priv,
40 struct v4l2_capability *v)
41{
42 strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
43 strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
44 snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
Hans Verkuild020f832013-02-03 09:05:16 -030045 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
46 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
Richard Röjforsd44d1f32010-02-03 12:59:39 -030047 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,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -030058 const struct v4l2_tuner *v)
Richard Röjforsd44d1f32010-02-03 12:59:39 -030059{
60 struct timbradio *tr = video_drvdata(file);
61 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
62}
63
Richard Röjforsd44d1f32010-02-03 12:59:39 -030064static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
Hans Verkuilb530a442013-03-19 04:09:26 -030065 const struct v4l2_frequency *f)
Richard Röjforsd44d1f32010-02-03 12:59:39 -030066{
67 struct timbradio *tr = video_drvdata(file);
68 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
69}
70
71static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
72 struct v4l2_frequency *f)
73{
74 struct timbradio *tr = video_drvdata(file);
75 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
76}
77
Richard Röjforsd44d1f32010-02-03 12:59:39 -030078static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
79 .vidioc_querycap = timbradio_vidioc_querycap,
80 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
81 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
82 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
83 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
Hans Verkuil46821b12013-02-03 09:33:21 -030084 .vidioc_log_status = v4l2_ctrl_log_status,
85 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
86 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Richard Röjforsd44d1f32010-02-03 12:59:39 -030087};
88
89static const struct v4l2_file_operations timbradio_fops = {
90 .owner = THIS_MODULE,
Hans Verkuil46821b12013-02-03 09:33:21 -030091 .open = v4l2_fh_open,
92 .release = v4l2_fh_release,
93 .poll = v4l2_ctrl_poll,
Hans Verkuil4f687752010-11-16 18:13:06 -030094 .unlocked_ioctl = video_ioctl2,
Richard Röjforsd44d1f32010-02-03 12:59:39 -030095};
96
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -080097static int timbradio_probe(struct platform_device *pdev)
Richard Röjforsd44d1f32010-02-03 12:59:39 -030098{
Samuel Ortiz3271d382011-04-08 01:23:57 +020099 struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300100 struct timbradio *tr;
101 int err;
102
103 if (!pdata) {
104 dev_err(&pdev->dev, "Platform data missing\n");
105 err = -EINVAL;
106 goto err;
107 }
108
Julia Lawall2f20c492012-07-31 05:21:37 -0300109 tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300110 if (!tr) {
111 err = -ENOMEM;
112 goto err;
113 }
114
115 tr->pdata = *pdata;
Hans Verkuil4f687752010-11-16 18:13:06 -0300116 mutex_init(&tr->lock);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300117
118 strlcpy(tr->video_dev.name, "Timberdale Radio",
119 sizeof(tr->video_dev.name));
120 tr->video_dev.fops = &timbradio_fops;
121 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
122 tr->video_dev.release = video_device_release_empty;
123 tr->video_dev.minor = -1;
Hans Verkuil4f687752010-11-16 18:13:06 -0300124 tr->video_dev.lock = &tr->lock;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300125
126 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
127 err = v4l2_device_register(NULL, &tr->v4l2_dev);
128 if (err)
Julia Lawall2f20c492012-07-31 05:21:37 -0300129 goto err;
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300130
131 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
132
Hans Verkuil5bd8d2a2013-05-31 06:50:50 -0300133 tr->sd_tuner = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
134 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL);
135 tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
136 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL);
Julia Lawall44b0c732015-04-05 09:06:24 -0300137 if (tr->sd_tuner == NULL || tr->sd_dsp == NULL) {
138 err = -ENODEV;
Hans Verkuil5bd8d2a2013-05-31 06:50:50 -0300139 goto err_video_req;
Julia Lawall44b0c732015-04-05 09:06:24 -0300140 }
Hans Verkuil5bd8d2a2013-05-31 06:50:50 -0300141
142 tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler;
143
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300144 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
145 if (err) {
146 dev_err(&pdev->dev, "Error reg video\n");
147 goto err_video_req;
148 }
149
150 video_set_drvdata(&tr->video_dev, tr);
151
152 platform_set_drvdata(pdev, tr);
153 return 0;
154
155err_video_req:
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300156 v4l2_device_unregister(&tr->v4l2_dev);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300157err:
158 dev_err(&pdev->dev, "Failed to register: %d\n", err);
159
160 return err;
161}
162
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800163static int timbradio_remove(struct platform_device *pdev)
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300164{
165 struct timbradio *tr = platform_get_drvdata(pdev);
166
167 video_unregister_device(&tr->video_dev);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300168 v4l2_device_unregister(&tr->v4l2_dev);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300169 return 0;
170}
171
172static struct platform_driver timbradio_platform_driver = {
173 .driver = {
174 .name = DRIVER_NAME,
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300175 },
176 .probe = timbradio_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800177 .remove = timbradio_remove,
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300178};
179
Axel Lin1d6629b2012-01-10 03:21:49 -0300180module_platform_driver(timbradio_platform_driver);
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300181
182MODULE_DESCRIPTION("Timberdale Radio driver");
183MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
184MODULE_LICENSE("GPL v2");
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -0300185MODULE_VERSION("0.0.2");
Richard Röjforsd44d1f32010-02-03 12:59:39 -0300186MODULE_ALIAS("platform:"DRIVER_NAME);