1 // SPDX-License-Identifier: GPL-2.0-only
3 * radio-timb.c Timberdale FPGA Radio driver
4 * Copyright (c) 2009 Intel Corporation
8 #include <media/v4l2-ioctl.h>
9 #include <media/v4l2-device.h>
10 #include <media/v4l2-ctrls.h>
11 #include <media/v4l2-event.h>
12 #include <linux/platform_device.h>
13 #include <linux/interrupt.h>
14 #include <linux/slab.h>
15 #include <linux/i2c.h>
16 #include <linux/module.h>
17 #include <linux/platform_data/media/timb_radio.h>
19 #define DRIVER_NAME "timb-radio"
22 struct timb_radio_platform_data pdata;
23 struct v4l2_subdev *sd_tuner;
24 struct v4l2_subdev *sd_dsp;
25 struct video_device video_dev;
26 struct v4l2_device v4l2_dev;
31 static int timbradio_vidioc_querycap(struct file *file, void *priv,
32 struct v4l2_capability *v)
34 strscpy(v->driver, DRIVER_NAME, sizeof(v->driver));
35 strscpy(v->card, "Timberdale Radio", sizeof(v->card));
36 snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
37 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
38 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
42 static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
45 struct timbradio *tr = video_drvdata(file);
46 return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
49 static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
50 const struct v4l2_tuner *v)
52 struct timbradio *tr = video_drvdata(file);
53 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
56 static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
57 const struct v4l2_frequency *f)
59 struct timbradio *tr = video_drvdata(file);
60 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
63 static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
64 struct v4l2_frequency *f)
66 struct timbradio *tr = video_drvdata(file);
67 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
70 static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
71 .vidioc_querycap = timbradio_vidioc_querycap,
72 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
73 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
74 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
75 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
76 .vidioc_log_status = v4l2_ctrl_log_status,
77 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
78 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
81 static const struct v4l2_file_operations timbradio_fops = {
84 .release = v4l2_fh_release,
85 .poll = v4l2_ctrl_poll,
86 .unlocked_ioctl = video_ioctl2,
89 static int timbradio_probe(struct platform_device *pdev)
91 struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
96 dev_err(&pdev->dev, "Platform data missing\n");
101 tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL);
108 mutex_init(&tr->lock);
110 strscpy(tr->video_dev.name, "Timberdale Radio",
111 sizeof(tr->video_dev.name));
112 tr->video_dev.fops = &timbradio_fops;
113 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
114 tr->video_dev.release = video_device_release_empty;
115 tr->video_dev.minor = -1;
116 tr->video_dev.lock = &tr->lock;
118 strscpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
119 err = v4l2_device_register(NULL, &tr->v4l2_dev);
123 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
125 tr->sd_tuner = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
126 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL);
127 tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
128 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL);
129 if (tr->sd_tuner == NULL || tr->sd_dsp == NULL) {
134 tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler;
136 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
138 dev_err(&pdev->dev, "Error reg video\n");
142 video_set_drvdata(&tr->video_dev, tr);
144 platform_set_drvdata(pdev, tr);
148 v4l2_device_unregister(&tr->v4l2_dev);
150 dev_err(&pdev->dev, "Failed to register: %d\n", err);
155 static int timbradio_remove(struct platform_device *pdev)
157 struct timbradio *tr = platform_get_drvdata(pdev);
159 video_unregister_device(&tr->video_dev);
160 v4l2_device_unregister(&tr->v4l2_dev);
164 static struct platform_driver timbradio_platform_driver = {
168 .probe = timbradio_probe,
169 .remove = timbradio_remove,
172 module_platform_driver(timbradio_platform_driver);
174 MODULE_DESCRIPTION("Timberdale Radio driver");
175 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
176 MODULE_LICENSE("GPL v2");
177 MODULE_VERSION("0.0.2");
178 MODULE_ALIAS("platform:"DRIVER_NAME);