M7350/kernel/drivers/media/radio/si4713/radio-platform-si4713.c

246 lines
7.4 KiB
C
Raw Normal View History

2024-09-09 08:52:07 +00:00
/*
* drivers/media/radio/radio-si4713.c
*
* Platform Driver for Silicon Labs Si4713 FM Radio Transmitter:
*
* Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
* Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/videodev2.h>
#include <linux/slab.h>
#include <media/v4l2-device.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
2024-09-09 08:57:42 +00:00
#include <media/v4l2-fh.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
2024-09-09 08:52:07 +00:00
#include <media/radio-si4713.h>
/* module parameters */
static int radio_nr = -1; /* radio device minor (-1 ==> auto assign) */
module_param(radio_nr, int, 0);
MODULE_PARM_DESC(radio_nr,
"Minor number for radio device (-1 ==> auto assign)");
2024-09-09 08:57:42 +00:00
MODULE_LICENSE("GPL v2");
2024-09-09 08:52:07 +00:00
MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
MODULE_DESCRIPTION("Platform driver for Si4713 FM Radio Transmitter");
MODULE_VERSION("0.0.1");
2024-09-09 08:57:42 +00:00
MODULE_ALIAS("platform:radio-si4713");
2024-09-09 08:52:07 +00:00
/* Driver state struct */
struct radio_si4713_device {
struct v4l2_device v4l2_dev;
2024-09-09 08:57:42 +00:00
struct video_device radio_dev;
struct mutex lock;
2024-09-09 08:52:07 +00:00
};
/* radio_si4713_fops - file operations interface */
static const struct v4l2_file_operations radio_si4713_fops = {
.owner = THIS_MODULE,
2024-09-09 08:57:42 +00:00
.open = v4l2_fh_open,
.release = v4l2_fh_release,
.poll = v4l2_ctrl_poll,
2024-09-09 08:52:07 +00:00
/* Note: locking is done at the subdev level in the i2c driver. */
.unlocked_ioctl = video_ioctl2,
};
/* Video4Linux Interface */
/* radio_si4713_querycap - query device capabilities */
static int radio_si4713_querycap(struct file *file, void *priv,
struct v4l2_capability *capability)
{
strlcpy(capability->driver, "radio-si4713", sizeof(capability->driver));
strlcpy(capability->card, "Silicon Labs Si4713 Modulator",
2024-09-09 08:57:42 +00:00
sizeof(capability->card));
strlcpy(capability->bus_info, "platform:radio-si4713",
sizeof(capability->bus_info));
capability->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
2024-09-09 08:52:07 +00:00
return 0;
}
/*
* v4l2 ioctl call backs.
* we are just a wrapper for v4l2_sub_devs.
*/
static inline struct v4l2_device *get_v4l2_dev(struct file *file)
{
return &((struct radio_si4713_device *)video_drvdata(file))->v4l2_dev;
}
static int radio_si4713_g_modulator(struct file *file, void *p,
2024-09-09 08:57:42 +00:00
struct v4l2_modulator *vm)
2024-09-09 08:52:07 +00:00
{
return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
2024-09-09 08:57:42 +00:00
g_modulator, vm);
2024-09-09 08:52:07 +00:00
}
static int radio_si4713_s_modulator(struct file *file, void *p,
2024-09-09 08:57:42 +00:00
const struct v4l2_modulator *vm)
2024-09-09 08:52:07 +00:00
{
return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
2024-09-09 08:57:42 +00:00
s_modulator, vm);
2024-09-09 08:52:07 +00:00
}
static int radio_si4713_g_frequency(struct file *file, void *p,
2024-09-09 08:57:42 +00:00
struct v4l2_frequency *vf)
2024-09-09 08:52:07 +00:00
{
return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
2024-09-09 08:57:42 +00:00
g_frequency, vf);
2024-09-09 08:52:07 +00:00
}
static int radio_si4713_s_frequency(struct file *file, void *p,
2024-09-09 08:57:42 +00:00
const struct v4l2_frequency *vf)
2024-09-09 08:52:07 +00:00
{
return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
2024-09-09 08:57:42 +00:00
s_frequency, vf);
2024-09-09 08:52:07 +00:00
}
static long radio_si4713_default(struct file *file, void *p,
2024-09-09 08:57:42 +00:00
bool valid_prio, unsigned int cmd, void *arg)
2024-09-09 08:52:07 +00:00
{
return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
2024-09-09 08:57:42 +00:00
ioctl, cmd, arg);
2024-09-09 08:52:07 +00:00
}
static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
.vidioc_querycap = radio_si4713_querycap,
.vidioc_g_modulator = radio_si4713_g_modulator,
.vidioc_s_modulator = radio_si4713_s_modulator,
.vidioc_g_frequency = radio_si4713_g_frequency,
.vidioc_s_frequency = radio_si4713_s_frequency,
2024-09-09 08:57:42 +00:00
.vidioc_log_status = v4l2_ctrl_log_status,
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2024-09-09 08:52:07 +00:00
.vidioc_default = radio_si4713_default,
};
/* radio_si4713_vdev_template - video device interface */
static struct video_device radio_si4713_vdev_template = {
.fops = &radio_si4713_fops,
.name = "radio-si4713",
2024-09-09 08:57:42 +00:00
.release = video_device_release_empty,
2024-09-09 08:52:07 +00:00
.ioctl_ops = &radio_si4713_ioctl_ops,
2024-09-09 08:57:42 +00:00
.vfl_dir = VFL_DIR_TX,
2024-09-09 08:52:07 +00:00
};
/* Platform driver interface */
/* radio_si4713_pdriver_probe - probe for the device */
static int radio_si4713_pdriver_probe(struct platform_device *pdev)
{
struct radio_si4713_platform_data *pdata = pdev->dev.platform_data;
struct radio_si4713_device *rsdev;
struct i2c_adapter *adapter;
struct v4l2_subdev *sd;
int rval = 0;
if (!pdata) {
dev_err(&pdev->dev, "Cannot proceed without platform data.\n");
rval = -EINVAL;
goto exit;
}
2024-09-09 08:57:42 +00:00
rsdev = devm_kzalloc(&pdev->dev, sizeof(*rsdev), GFP_KERNEL);
2024-09-09 08:52:07 +00:00
if (!rsdev) {
dev_err(&pdev->dev, "Failed to alloc video device.\n");
rval = -ENOMEM;
goto exit;
}
2024-09-09 08:57:42 +00:00
mutex_init(&rsdev->lock);
2024-09-09 08:52:07 +00:00
rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev);
if (rval) {
dev_err(&pdev->dev, "Failed to register v4l2 device.\n");
2024-09-09 08:57:42 +00:00
goto exit;
2024-09-09 08:52:07 +00:00
}
adapter = i2c_get_adapter(pdata->i2c_bus);
if (!adapter) {
dev_err(&pdev->dev, "Cannot get i2c adapter %d\n",
2024-09-09 08:57:42 +00:00
pdata->i2c_bus);
2024-09-09 08:52:07 +00:00
rval = -ENODEV;
goto unregister_v4l2_dev;
}
sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter,
2024-09-09 08:57:42 +00:00
pdata->subdev_board_info, NULL);
2024-09-09 08:52:07 +00:00
if (!sd) {
dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n");
rval = -ENODEV;
goto put_adapter;
}
2024-09-09 08:57:42 +00:00
rsdev->radio_dev = radio_si4713_vdev_template;
rsdev->radio_dev.v4l2_dev = &rsdev->v4l2_dev;
rsdev->radio_dev.ctrl_handler = sd->ctrl_handler;
/* Serialize all access to the si4713 */
rsdev->radio_dev.lock = &rsdev->lock;
video_set_drvdata(&rsdev->radio_dev, rsdev);
if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
2024-09-09 08:52:07 +00:00
dev_err(&pdev->dev, "Could not register video device.\n");
rval = -EIO;
2024-09-09 08:57:42 +00:00
goto put_adapter;
2024-09-09 08:52:07 +00:00
}
dev_info(&pdev->dev, "New device successfully probed\n");
goto exit;
put_adapter:
i2c_put_adapter(adapter);
unregister_v4l2_dev:
v4l2_device_unregister(&rsdev->v4l2_dev);
exit:
return rval;
}
/* radio_si4713_pdriver_remove - remove the device */
2024-09-09 08:57:42 +00:00
static int radio_si4713_pdriver_remove(struct platform_device *pdev)
2024-09-09 08:52:07 +00:00
{
struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next,
struct v4l2_subdev, list);
struct i2c_client *client = v4l2_get_subdevdata(sd);
2024-09-09 08:57:42 +00:00
struct radio_si4713_device *rsdev;
2024-09-09 08:52:07 +00:00
2024-09-09 08:57:42 +00:00
rsdev = container_of(v4l2_dev, struct radio_si4713_device, v4l2_dev);
video_unregister_device(&rsdev->radio_dev);
2024-09-09 08:52:07 +00:00
i2c_put_adapter(client->adapter);
v4l2_device_unregister(&rsdev->v4l2_dev);
return 0;
}
static struct platform_driver radio_si4713_pdriver = {
.driver = {
.name = "radio-si4713",
2024-09-09 08:57:42 +00:00
.owner = THIS_MODULE,
2024-09-09 08:52:07 +00:00
},
.probe = radio_si4713_pdriver_probe,
2024-09-09 08:57:42 +00:00
.remove = radio_si4713_pdriver_remove,
2024-09-09 08:52:07 +00:00
};
module_platform_driver(radio_si4713_pdriver);