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
);
40 static int timbradio_vidioc_g_tuner(struct file
*file
, void *priv
,
43 struct timbradio
*tr
= video_drvdata(file
);
44 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, g_tuner
, v
);
47 static int timbradio_vidioc_s_tuner(struct file
*file
, void *priv
,
48 const struct v4l2_tuner
*v
)
50 struct timbradio
*tr
= video_drvdata(file
);
51 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, s_tuner
, v
);
54 static int timbradio_vidioc_s_frequency(struct file
*file
, void *priv
,
55 const struct v4l2_frequency
*f
)
57 struct timbradio
*tr
= video_drvdata(file
);
58 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, s_frequency
, f
);
61 static int timbradio_vidioc_g_frequency(struct file
*file
, void *priv
,
62 struct v4l2_frequency
*f
)
64 struct timbradio
*tr
= video_drvdata(file
);
65 return v4l2_subdev_call(tr
->sd_tuner
, tuner
, g_frequency
, f
);
68 static const struct v4l2_ioctl_ops timbradio_ioctl_ops
= {
69 .vidioc_querycap
= timbradio_vidioc_querycap
,
70 .vidioc_g_tuner
= timbradio_vidioc_g_tuner
,
71 .vidioc_s_tuner
= timbradio_vidioc_s_tuner
,
72 .vidioc_g_frequency
= timbradio_vidioc_g_frequency
,
73 .vidioc_s_frequency
= timbradio_vidioc_s_frequency
,
74 .vidioc_log_status
= v4l2_ctrl_log_status
,
75 .vidioc_subscribe_event
= v4l2_ctrl_subscribe_event
,
76 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
79 static const struct v4l2_file_operations timbradio_fops
= {
82 .release
= v4l2_fh_release
,
83 .poll
= v4l2_ctrl_poll
,
84 .unlocked_ioctl
= video_ioctl2
,
87 static int timbradio_probe(struct platform_device
*pdev
)
89 struct timb_radio_platform_data
*pdata
= pdev
->dev
.platform_data
;
94 dev_err(&pdev
->dev
, "Platform data missing\n");
99 tr
= devm_kzalloc(&pdev
->dev
, sizeof(*tr
), GFP_KERNEL
);
106 mutex_init(&tr
->lock
);
108 strscpy(tr
->video_dev
.name
, "Timberdale Radio",
109 sizeof(tr
->video_dev
.name
));
110 tr
->video_dev
.fops
= &timbradio_fops
;
111 tr
->video_dev
.ioctl_ops
= &timbradio_ioctl_ops
;
112 tr
->video_dev
.release
= video_device_release_empty
;
113 tr
->video_dev
.minor
= -1;
114 tr
->video_dev
.lock
= &tr
->lock
;
115 tr
->video_dev
.device_caps
= V4L2_CAP_TUNER
| V4L2_CAP_RADIO
;
117 strscpy(tr
->v4l2_dev
.name
, DRIVER_NAME
, sizeof(tr
->v4l2_dev
.name
));
118 err
= v4l2_device_register(NULL
, &tr
->v4l2_dev
);
122 tr
->video_dev
.v4l2_dev
= &tr
->v4l2_dev
;
124 tr
->sd_tuner
= v4l2_i2c_new_subdev_board(&tr
->v4l2_dev
,
125 i2c_get_adapter(pdata
->i2c_adapter
), pdata
->tuner
, NULL
);
126 tr
->sd_dsp
= v4l2_i2c_new_subdev_board(&tr
->v4l2_dev
,
127 i2c_get_adapter(pdata
->i2c_adapter
), pdata
->dsp
, NULL
);
128 if (tr
->sd_tuner
== NULL
|| tr
->sd_dsp
== NULL
) {
133 tr
->v4l2_dev
.ctrl_handler
= tr
->sd_dsp
->ctrl_handler
;
135 err
= video_register_device(&tr
->video_dev
, VFL_TYPE_RADIO
, -1);
137 dev_err(&pdev
->dev
, "Error reg video\n");
141 video_set_drvdata(&tr
->video_dev
, tr
);
143 platform_set_drvdata(pdev
, tr
);
147 v4l2_device_unregister(&tr
->v4l2_dev
);
149 dev_err(&pdev
->dev
, "Failed to register: %d\n", err
);
154 static void timbradio_remove(struct platform_device
*pdev
)
156 struct timbradio
*tr
= platform_get_drvdata(pdev
);
158 video_unregister_device(&tr
->video_dev
);
159 v4l2_device_unregister(&tr
->v4l2_dev
);
162 static struct platform_driver timbradio_platform_driver
= {
166 .probe
= timbradio_probe
,
167 .remove
= timbradio_remove
,
170 module_platform_driver(timbradio_platform_driver
);
172 MODULE_DESCRIPTION("Timberdale Radio driver");
173 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
174 MODULE_LICENSE("GPL v2");
175 MODULE_VERSION("0.0.2");
176 MODULE_ALIAS("platform:"DRIVER_NAME
);