]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/media/radio/radio-timb.c
[media] radio-timb: actually load the requested subdevs
[karo-tx-linux.git] / drivers / media / radio / radio-timb.c
1 /*
2  * radio-timb.c Timberdale FPGA Radio driver
3  * Copyright (c) 2009 Intel Corporation
4  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include <linux/io.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/v4l2-device.h>
22 #include <linux/platform_device.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/i2c.h>
26 #include <linux/module.h>
27 #include <media/timb_radio.h>
28
29 #define DRIVER_NAME "timb-radio"
30
31 struct timbradio {
32         struct timb_radio_platform_data pdata;
33         struct v4l2_subdev      *sd_tuner;
34         struct v4l2_subdev      *sd_dsp;
35         struct video_device     video_dev;
36         struct v4l2_device      v4l2_dev;
37         struct mutex            lock;
38 };
39
40
41 static int timbradio_vidioc_querycap(struct file *file, void  *priv,
42         struct v4l2_capability *v)
43 {
44         strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
45         strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
46         snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
47         v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
48         v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
49         return 0;
50 }
51
52 static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
53         struct v4l2_tuner *v)
54 {
55         struct timbradio *tr = video_drvdata(file);
56         return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
57 }
58
59 static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
60         const struct v4l2_tuner *v)
61 {
62         struct timbradio *tr = video_drvdata(file);
63         return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
64 }
65
66 static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
67         const struct v4l2_frequency *f)
68 {
69         struct timbradio *tr = video_drvdata(file);
70         return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
71 }
72
73 static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
74         struct v4l2_frequency *f)
75 {
76         struct timbradio *tr = video_drvdata(file);
77         return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
78 }
79
80 static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
81         .vidioc_querycap        = timbradio_vidioc_querycap,
82         .vidioc_g_tuner         = timbradio_vidioc_g_tuner,
83         .vidioc_s_tuner         = timbradio_vidioc_s_tuner,
84         .vidioc_g_frequency     = timbradio_vidioc_g_frequency,
85         .vidioc_s_frequency     = timbradio_vidioc_s_frequency,
86 };
87
88 static const struct v4l2_file_operations timbradio_fops = {
89         .owner          = THIS_MODULE,
90         .unlocked_ioctl = video_ioctl2,
91 };
92
93 static int timbradio_probe(struct platform_device *pdev)
94 {
95         struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
96         struct timbradio *tr;
97         int err;
98
99         if (!pdata) {
100                 dev_err(&pdev->dev, "Platform data missing\n");
101                 err = -EINVAL;
102                 goto err;
103         }
104
105         tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL);
106         if (!tr) {
107                 err = -ENOMEM;
108                 goto err;
109         }
110
111         tr->pdata = *pdata;
112         mutex_init(&tr->lock);
113
114         strlcpy(tr->video_dev.name, "Timberdale Radio",
115                 sizeof(tr->video_dev.name));
116         tr->video_dev.fops = &timbradio_fops;
117         tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
118         tr->video_dev.release = video_device_release_empty;
119         tr->video_dev.minor = -1;
120         tr->video_dev.lock = &tr->lock;
121
122         strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
123         err = v4l2_device_register(NULL, &tr->v4l2_dev);
124         if (err)
125                 goto err;
126
127         tr->video_dev.v4l2_dev = &tr->v4l2_dev;
128
129         tr->sd_tuner = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
130                 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL);
131         tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
132                 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL);
133         if (tr->sd_tuner == NULL || tr->sd_dsp == NULL)
134                 goto err_video_req;
135
136         tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler;
137
138         err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
139         if (err) {
140                 dev_err(&pdev->dev, "Error reg video\n");
141                 goto err_video_req;
142         }
143
144         video_set_drvdata(&tr->video_dev, tr);
145
146         platform_set_drvdata(pdev, tr);
147         return 0;
148
149 err_video_req:
150         v4l2_device_unregister(&tr->v4l2_dev);
151 err:
152         dev_err(&pdev->dev, "Failed to register: %d\n", err);
153
154         return err;
155 }
156
157 static int timbradio_remove(struct platform_device *pdev)
158 {
159         struct timbradio *tr = platform_get_drvdata(pdev);
160
161         video_unregister_device(&tr->video_dev);
162         v4l2_device_unregister(&tr->v4l2_dev);
163         return 0;
164 }
165
166 static struct platform_driver timbradio_platform_driver = {
167         .driver = {
168                 .name   = DRIVER_NAME,
169                 .owner  = THIS_MODULE,
170         },
171         .probe          = timbradio_probe,
172         .remove         = timbradio_remove,
173 };
174
175 module_platform_driver(timbradio_platform_driver);
176
177 MODULE_DESCRIPTION("Timberdale Radio driver");
178 MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
179 MODULE_LICENSE("GPL v2");
180 MODULE_VERSION("0.0.2");
181 MODULE_ALIAS("platform:"DRIVER_NAME);