1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/media/radio/radio-si4713.c
5 * Platform Driver for Silicon Labs Si4713 FM Radio Transmitter:
7 * Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
8 * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/i2c.h>
16 #include <linux/videodev2.h>
17 #include <linux/slab.h>
18 #include <media/v4l2-device.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/v4l2-fh.h>
22 #include <media/v4l2-ctrls.h>
23 #include <media/v4l2-event.h>
26 /* module parameters */
27 static int radio_nr
= -1; /* radio device minor (-1 ==> auto assign) */
28 module_param(radio_nr
, int, 0);
29 MODULE_PARM_DESC(radio_nr
,
30 "Minor number for radio device (-1 ==> auto assign)");
32 MODULE_LICENSE("GPL v2");
33 MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
34 MODULE_DESCRIPTION("Platform driver for Si4713 FM Radio Transmitter");
35 MODULE_VERSION("0.0.1");
36 MODULE_ALIAS("platform:radio-si4713");
38 /* Driver state struct */
39 struct radio_si4713_device
{
40 struct v4l2_device v4l2_dev
;
41 struct video_device radio_dev
;
45 /* radio_si4713_fops - file operations interface */
46 static const struct v4l2_file_operations radio_si4713_fops
= {
49 .release
= v4l2_fh_release
,
50 .poll
= v4l2_ctrl_poll
,
51 /* Note: locking is done at the subdev level in the i2c driver. */
52 .unlocked_ioctl
= video_ioctl2
,
55 /* Video4Linux Interface */
57 /* radio_si4713_querycap - query device capabilities */
58 static int radio_si4713_querycap(struct file
*file
, void *priv
,
59 struct v4l2_capability
*capability
)
61 strscpy(capability
->driver
, "radio-si4713", sizeof(capability
->driver
));
62 strscpy(capability
->card
, "Silicon Labs Si4713 Modulator",
63 sizeof(capability
->card
));
64 strscpy(capability
->bus_info
, "platform:radio-si4713",
65 sizeof(capability
->bus_info
));
66 capability
->device_caps
= V4L2_CAP_MODULATOR
| V4L2_CAP_RDS_OUTPUT
;
67 capability
->capabilities
= capability
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
73 * v4l2 ioctl call backs.
74 * we are just a wrapper for v4l2_sub_devs.
76 static inline struct v4l2_device
*get_v4l2_dev(struct file
*file
)
78 return &((struct radio_si4713_device
*)video_drvdata(file
))->v4l2_dev
;
81 static int radio_si4713_g_modulator(struct file
*file
, void *p
,
82 struct v4l2_modulator
*vm
)
84 return v4l2_device_call_until_err(get_v4l2_dev(file
), 0, tuner
,
88 static int radio_si4713_s_modulator(struct file
*file
, void *p
,
89 const struct v4l2_modulator
*vm
)
91 return v4l2_device_call_until_err(get_v4l2_dev(file
), 0, tuner
,
95 static int radio_si4713_g_frequency(struct file
*file
, void *p
,
96 struct v4l2_frequency
*vf
)
98 return v4l2_device_call_until_err(get_v4l2_dev(file
), 0, tuner
,
102 static int radio_si4713_s_frequency(struct file
*file
, void *p
,
103 const struct v4l2_frequency
*vf
)
105 return v4l2_device_call_until_err(get_v4l2_dev(file
), 0, tuner
,
109 static long radio_si4713_default(struct file
*file
, void *p
,
110 bool valid_prio
, unsigned int cmd
, void *arg
)
112 return v4l2_device_call_until_err(get_v4l2_dev(file
), 0, core
,
116 static struct v4l2_ioctl_ops radio_si4713_ioctl_ops
= {
117 .vidioc_querycap
= radio_si4713_querycap
,
118 .vidioc_g_modulator
= radio_si4713_g_modulator
,
119 .vidioc_s_modulator
= radio_si4713_s_modulator
,
120 .vidioc_g_frequency
= radio_si4713_g_frequency
,
121 .vidioc_s_frequency
= radio_si4713_s_frequency
,
122 .vidioc_log_status
= v4l2_ctrl_log_status
,
123 .vidioc_subscribe_event
= v4l2_ctrl_subscribe_event
,
124 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
125 .vidioc_default
= radio_si4713_default
,
128 /* radio_si4713_vdev_template - video device interface */
129 static const struct video_device radio_si4713_vdev_template
= {
130 .fops
= &radio_si4713_fops
,
131 .name
= "radio-si4713",
132 .release
= video_device_release_empty
,
133 .ioctl_ops
= &radio_si4713_ioctl_ops
,
134 .vfl_dir
= VFL_DIR_TX
,
137 /* Platform driver interface */
138 /* radio_si4713_pdriver_probe - probe for the device */
139 static int radio_si4713_pdriver_probe(struct platform_device
*pdev
)
141 struct radio_si4713_platform_data
*pdata
= pdev
->dev
.platform_data
;
142 struct radio_si4713_device
*rsdev
;
143 struct v4l2_subdev
*sd
;
147 dev_err(&pdev
->dev
, "Cannot proceed without platform data.\n");
152 rsdev
= devm_kzalloc(&pdev
->dev
, sizeof(*rsdev
), GFP_KERNEL
);
154 dev_err(&pdev
->dev
, "Failed to alloc video device.\n");
158 mutex_init(&rsdev
->lock
);
160 rval
= v4l2_device_register(&pdev
->dev
, &rsdev
->v4l2_dev
);
162 dev_err(&pdev
->dev
, "Failed to register v4l2 device.\n");
166 sd
= i2c_get_clientdata(pdata
->subdev
);
167 rval
= v4l2_device_register_subdev(&rsdev
->v4l2_dev
, sd
);
169 dev_err(&pdev
->dev
, "Cannot get v4l2 subdevice\n");
170 goto unregister_v4l2_dev
;
173 rsdev
->radio_dev
= radio_si4713_vdev_template
;
174 rsdev
->radio_dev
.v4l2_dev
= &rsdev
->v4l2_dev
;
175 rsdev
->radio_dev
.ctrl_handler
= sd
->ctrl_handler
;
176 /* Serialize all access to the si4713 */
177 rsdev
->radio_dev
.lock
= &rsdev
->lock
;
178 video_set_drvdata(&rsdev
->radio_dev
, rsdev
);
179 if (video_register_device(&rsdev
->radio_dev
, VFL_TYPE_RADIO
, radio_nr
)) {
180 dev_err(&pdev
->dev
, "Could not register video device.\n");
182 goto unregister_v4l2_dev
;
184 dev_info(&pdev
->dev
, "New device successfully probed\n");
189 v4l2_device_unregister(&rsdev
->v4l2_dev
);
194 /* radio_si4713_pdriver_remove - remove the device */
195 static int radio_si4713_pdriver_remove(struct platform_device
*pdev
)
197 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
198 struct radio_si4713_device
*rsdev
;
200 rsdev
= container_of(v4l2_dev
, struct radio_si4713_device
, v4l2_dev
);
201 video_unregister_device(&rsdev
->radio_dev
);
202 v4l2_device_unregister(&rsdev
->v4l2_dev
);
207 static struct platform_driver radio_si4713_pdriver
= {
209 .name
= "radio-si4713",
211 .probe
= radio_si4713_pdriver_probe
,
212 .remove
= radio_si4713_pdriver_remove
,
215 module_platform_driver(radio_si4713_pdriver
);