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.
19 #include <linux/version.h>
21 #include <media/v4l2-ioctl.h>
22 #include <media/v4l2-device.h>
23 #include <linux/platform_device.h>
24 #include <linux/interrupt.h>
25 #include <linux/i2c.h>
26 #include <media/timb_radio.h>
28 #define DRIVER_NAME "timb-radio"
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
;
39 static int timbradio_vidioc_querycap(struct file
*file
, void *priv
,
40 struct v4l2_capability
*v
)
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
);
45 v
->version
= KERNEL_VERSION(0, 0, 1);
46 v
->capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_RADIO
;
50 static int timbradio_vidioc_g_tuner(struct file
*file
, void *priv
,
53 struct timbradio
*tr
= video_drvdata(file
);
54 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, g_tuner
, v
);
57 static int timbradio_vidioc_s_tuner(struct file
*file
, void *priv
,
60 struct timbradio
*tr
= video_drvdata(file
);
61 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, s_tuner
, v
);
64 static int timbradio_vidioc_g_input(struct file
*filp
, void *priv
,
71 static int timbradio_vidioc_s_input(struct file
*filp
, void *priv
,
74 return i
? -EINVAL
: 0;
77 static int timbradio_vidioc_g_audio(struct file
*file
, void *priv
,
81 strlcpy(a
->name
, "Radio", sizeof(a
->name
));
82 a
->capability
= V4L2_AUDCAP_STEREO
;
86 static int timbradio_vidioc_s_audio(struct file
*file
, void *priv
,
89 return a
->index
? -EINVAL
: 0;
92 static int timbradio_vidioc_s_frequency(struct file
*file
, void *priv
,
93 struct v4l2_frequency
*f
)
95 struct timbradio
*tr
= video_drvdata(file
);
96 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, s_frequency
, f
);
99 static int timbradio_vidioc_g_frequency(struct file
*file
, void *priv
,
100 struct v4l2_frequency
*f
)
102 struct timbradio
*tr
= video_drvdata(file
);
103 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, g_frequency
, f
);
106 static int timbradio_vidioc_queryctrl(struct file
*file
, void *priv
,
107 struct v4l2_queryctrl
*qc
)
109 struct timbradio
*tr
= video_drvdata(file
);
110 return v4l2_subdev_call(tr
->sd_dsp
, core
, queryctrl
, qc
);
113 static int timbradio_vidioc_g_ctrl(struct file
*file
, void *priv
,
114 struct v4l2_control
*ctrl
)
116 struct timbradio
*tr
= video_drvdata(file
);
117 return v4l2_subdev_call(tr
->sd_dsp
, core
, g_ctrl
, ctrl
);
120 static int timbradio_vidioc_s_ctrl(struct file
*file
, void *priv
,
121 struct v4l2_control
*ctrl
)
123 struct timbradio
*tr
= video_drvdata(file
);
124 return v4l2_subdev_call(tr
->sd_dsp
, core
, s_ctrl
, ctrl
);
127 static 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
142 static const struct v4l2_file_operations timbradio_fops
= {
143 .owner
= THIS_MODULE
,
144 .ioctl
= video_ioctl2
,
147 static int __devinit
timbradio_probe(struct platform_device
*pdev
)
149 struct timb_radio_platform_data
*pdata
= pdev
->dev
.platform_data
;
150 struct timbradio
*tr
;
154 dev_err(&pdev
->dev
, "Platform data missing\n");
159 tr
= kzalloc(sizeof(*tr
), GFP_KERNEL
);
167 strlcpy(tr
->video_dev
.name
, "Timberdale Radio",
168 sizeof(tr
->video_dev
.name
));
169 tr
->video_dev
.fops
= &timbradio_fops
;
170 tr
->video_dev
.ioctl_ops
= &timbradio_ioctl_ops
;
171 tr
->video_dev
.release
= video_device_release_empty
;
172 tr
->video_dev
.minor
= -1;
174 strlcpy(tr
->v4l2_dev
.name
, DRIVER_NAME
, sizeof(tr
->v4l2_dev
.name
));
175 err
= v4l2_device_register(NULL
, &tr
->v4l2_dev
);
179 tr
->video_dev
.v4l2_dev
= &tr
->v4l2_dev
;
181 err
= video_register_device(&tr
->video_dev
, VFL_TYPE_RADIO
, -1);
183 dev_err(&pdev
->dev
, "Error reg video\n");
187 video_set_drvdata(&tr
->video_dev
, tr
);
189 platform_set_drvdata(pdev
, tr
);
193 video_device_release_empty(&tr
->video_dev
);
194 v4l2_device_unregister(&tr
->v4l2_dev
);
198 dev_err(&pdev
->dev
, "Failed to register: %d\n", err
);
203 static int __devexit
timbradio_remove(struct platform_device
*pdev
)
205 struct timbradio
*tr
= platform_get_drvdata(pdev
);
207 video_unregister_device(&tr
->video_dev
);
208 video_device_release_empty(&tr
->video_dev
);
210 v4l2_device_unregister(&tr
->v4l2_dev
);
217 static struct platform_driver timbradio_platform_driver
= {
220 .owner
= THIS_MODULE
,
222 .probe
= timbradio_probe
,
223 .remove
= timbradio_remove
,
226 /*--------------------------------------------------------------------------*/
228 static int __init
timbradio_init(void)
230 return platform_driver_register(&timbradio_platform_driver
);
233 static void __exit
timbradio_exit(void)
235 platform_driver_unregister(&timbradio_platform_driver
);
238 module_init(timbradio_init
);
239 module_exit(timbradio_exit
);
241 MODULE_DESCRIPTION("Timberdale Radio driver");
242 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
243 MODULE_LICENSE("GPL v2");
244 MODULE_ALIAS("platform:"DRIVER_NAME
);