Commit | Line | Data |
---|---|---|
d44d1f3b RR |
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 | ||
d44d1f3b RR |
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> | |
5a0e3ad6 | 24 | #include <linux/slab.h> |
d44d1f3b | 25 | #include <linux/i2c.h> |
7a707b89 | 26 | #include <linux/module.h> |
d44d1f3b RR |
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; | |
4f68775b | 37 | struct mutex lock; |
d44d1f3b RR |
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); | |
d020f839 HV |
47 | v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
48 | v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS; | |
d44d1f3b RR |
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, | |
2f73c7c5 | 60 | const struct v4l2_tuner *v) |
d44d1f3b RR |
61 | { |
62 | struct timbradio *tr = video_drvdata(file); | |
63 | return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v); | |
64 | } | |
65 | ||
d44d1f3b | 66 | static int timbradio_vidioc_s_frequency(struct file *file, void *priv, |
b530a447 | 67 | const struct v4l2_frequency *f) |
d44d1f3b RR |
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 | ||
d44d1f3b RR |
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, | |
d44d1f3b RR |
86 | }; |
87 | ||
88 | static const struct v4l2_file_operations timbradio_fops = { | |
89 | .owner = THIS_MODULE, | |
4f68775b | 90 | .unlocked_ioctl = video_ioctl2, |
d44d1f3b RR |
91 | }; |
92 | ||
4c62e976 | 93 | static int timbradio_probe(struct platform_device *pdev) |
d44d1f3b | 94 | { |
3271d382 | 95 | struct timb_radio_platform_data *pdata = pdev->dev.platform_data; |
d44d1f3b RR |
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 | ||
2f20c490 | 105 | tr = devm_kzalloc(&pdev->dev, sizeof(*tr), GFP_KERNEL); |
d44d1f3b RR |
106 | if (!tr) { |
107 | err = -ENOMEM; | |
108 | goto err; | |
109 | } | |
110 | ||
111 | tr->pdata = *pdata; | |
4f68775b | 112 | mutex_init(&tr->lock); |
d44d1f3b RR |
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; | |
4f68775b | 120 | tr->video_dev.lock = &tr->lock; |
d44d1f3b RR |
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) | |
2f20c490 | 125 | goto err; |
d44d1f3b RR |
126 | |
127 | tr->video_dev.v4l2_dev = &tr->v4l2_dev; | |
128 | ||
129 | err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1); | |
130 | if (err) { | |
131 | dev_err(&pdev->dev, "Error reg video\n"); | |
132 | goto err_video_req; | |
133 | } | |
134 | ||
135 | video_set_drvdata(&tr->video_dev, tr); | |
136 | ||
137 | platform_set_drvdata(pdev, tr); | |
138 | return 0; | |
139 | ||
140 | err_video_req: | |
141 | video_device_release_empty(&tr->video_dev); | |
142 | v4l2_device_unregister(&tr->v4l2_dev); | |
d44d1f3b RR |
143 | err: |
144 | dev_err(&pdev->dev, "Failed to register: %d\n", err); | |
145 | ||
146 | return err; | |
147 | } | |
148 | ||
4c62e976 | 149 | static int timbradio_remove(struct platform_device *pdev) |
d44d1f3b RR |
150 | { |
151 | struct timbradio *tr = platform_get_drvdata(pdev); | |
152 | ||
153 | video_unregister_device(&tr->video_dev); | |
154 | video_device_release_empty(&tr->video_dev); | |
155 | ||
156 | v4l2_device_unregister(&tr->v4l2_dev); | |
157 | ||
d44d1f3b RR |
158 | return 0; |
159 | } | |
160 | ||
161 | static struct platform_driver timbradio_platform_driver = { | |
162 | .driver = { | |
163 | .name = DRIVER_NAME, | |
164 | .owner = THIS_MODULE, | |
165 | }, | |
166 | .probe = timbradio_probe, | |
4c62e976 | 167 | .remove = timbradio_remove, |
d44d1f3b RR |
168 | }; |
169 | ||
1d6629b1 | 170 | module_platform_driver(timbradio_platform_driver); |
d44d1f3b RR |
171 | |
172 | MODULE_DESCRIPTION("Timberdale Radio driver"); | |
173 | MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); | |
174 | MODULE_LICENSE("GPL v2"); | |
29834c1a | 175 | MODULE_VERSION("0.0.2"); |
d44d1f3b | 176 | MODULE_ALIAS("platform:"DRIVER_NAME); |