diff options
Diffstat (limited to 'extras/recipes-kernel/linux/linux-omap/wl1271/0008-drivers-media-radio-wl128x-FM-Driver-V4L2-sources.patch')
-rw-r--r-- | extras/recipes-kernel/linux/linux-omap/wl1271/0008-drivers-media-radio-wl128x-FM-Driver-V4L2-sources.patch | 645 |
1 files changed, 645 insertions, 0 deletions
diff --git a/extras/recipes-kernel/linux/linux-omap/wl1271/0008-drivers-media-radio-wl128x-FM-Driver-V4L2-sources.patch b/extras/recipes-kernel/linux/linux-omap/wl1271/0008-drivers-media-radio-wl128x-FM-Driver-V4L2-sources.patch new file mode 100644 index 00000000..c3eae97f --- /dev/null +++ b/extras/recipes-kernel/linux/linux-omap/wl1271/0008-drivers-media-radio-wl128x-FM-Driver-V4L2-sources.patch | |||
@@ -0,0 +1,645 @@ | |||
1 | From d532e33a286ec2275b441c05675de52cd5b069d2 Mon Sep 17 00:00:00 2001 | ||
2 | From: Manjunatha Halli <manjunatha_halli@ti.com> | ||
3 | Date: Tue, 11 Jan 2011 11:31:22 +0000 | ||
4 | Subject: [PATCH 08/15] drivers:media:radio: wl128x: FM Driver V4L2 sources | ||
5 | |||
6 | This module interfaces V4L2 subsystem and FM common module. | ||
7 | It registers itself with V4L2 as Radio module. | ||
8 | |||
9 | Signed-off-by: Manjunatha Halli <manjunatha_halli@ti.com> | ||
10 | Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl> | ||
11 | --- | ||
12 | drivers/media/radio/wl128x/fmdrv_v4l2.c | 580 +++++++++++++++++++++++++++++++ | ||
13 | drivers/media/radio/wl128x/fmdrv_v4l2.h | 33 ++ | ||
14 | 2 files changed, 613 insertions(+), 0 deletions(-) | ||
15 | create mode 100644 drivers/media/radio/wl128x/fmdrv_v4l2.c | ||
16 | create mode 100644 drivers/media/radio/wl128x/fmdrv_v4l2.h | ||
17 | |||
18 | diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c | ||
19 | new file mode 100644 | ||
20 | index 0000000..d50e5ac | ||
21 | --- /dev/null | ||
22 | +++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c | ||
23 | @@ -0,0 +1,580 @@ | ||
24 | +/* | ||
25 | + * FM Driver for Connectivity chip of Texas Instruments. | ||
26 | + * This file provides interfaces to V4L2 subsystem. | ||
27 | + * | ||
28 | + * This module registers with V4L2 subsystem as Radio | ||
29 | + * data system interface (/dev/radio). During the registration, | ||
30 | + * it will expose two set of function pointers. | ||
31 | + * | ||
32 | + * 1) File operation related API (open, close, read, write, poll...etc). | ||
33 | + * 2) Set of V4L2 IOCTL complaint API. | ||
34 | + * | ||
35 | + * Copyright (C) 2011 Texas Instruments | ||
36 | + * Author: Raja Mani <raja_mani@ti.com> | ||
37 | + * Author: Manjunatha Halli <manjunatha_halli@ti.com> | ||
38 | + * | ||
39 | + * This program is free software; you can redistribute it and/or modify | ||
40 | + * it under the terms of the GNU General Public License version 2 as | ||
41 | + * published by the Free Software Foundation. | ||
42 | + * | ||
43 | + * This program is distributed in the hope that it will be useful, | ||
44 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
45 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
46 | + * GNU General Public License for more details. | ||
47 | + * | ||
48 | + * You should have received a copy of the GNU General Public License | ||
49 | + * along with this program; if not, write to the Free Software | ||
50 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
51 | + * | ||
52 | + */ | ||
53 | + | ||
54 | +#include "fmdrv.h" | ||
55 | +#include "fmdrv_v4l2.h" | ||
56 | +#include "fmdrv_common.h" | ||
57 | +#include "fmdrv_rx.h" | ||
58 | +#include "fmdrv_tx.h" | ||
59 | + | ||
60 | +static struct video_device *gradio_dev; | ||
61 | +static u8 radio_disconnected; | ||
62 | + | ||
63 | +/* -- V4L2 RADIO (/dev/radioX) device file operation interfaces --- */ | ||
64 | + | ||
65 | +/* Read RX RDS data */ | ||
66 | +static ssize_t fm_v4l2_fops_read(struct file *file, char __user * buf, | ||
67 | + size_t count, loff_t *ppos) | ||
68 | +{ | ||
69 | + u8 rds_mode; | ||
70 | + int ret; | ||
71 | + struct fmdev *fmdev; | ||
72 | + | ||
73 | + fmdev = video_drvdata(file); | ||
74 | + | ||
75 | + if (!radio_disconnected) { | ||
76 | + fmerr("FM device is already disconnected\n"); | ||
77 | + return -EIO; | ||
78 | + } | ||
79 | + | ||
80 | + /* Turn on RDS mode , if it is disabled */ | ||
81 | + ret = fm_rx_get_rds_mode(fmdev, &rds_mode); | ||
82 | + if (ret < 0) { | ||
83 | + fmerr("Unable to read current rds mode\n"); | ||
84 | + return ret; | ||
85 | + } | ||
86 | + | ||
87 | + if (rds_mode == FM_RDS_DISABLE) { | ||
88 | + ret = fmc_set_rds_mode(fmdev, FM_RDS_ENABLE); | ||
89 | + if (ret < 0) { | ||
90 | + fmerr("Failed to enable rds mode\n"); | ||
91 | + return ret; | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + /* Copy RDS data from internal buffer to user buffer */ | ||
96 | + return fmc_transfer_rds_from_internal_buff(fmdev, file, buf, count); | ||
97 | +} | ||
98 | + | ||
99 | +/* Write TX RDS data */ | ||
100 | +static ssize_t fm_v4l2_fops_write(struct file *file, const char __user * buf, | ||
101 | + size_t count, loff_t *ppos) | ||
102 | +{ | ||
103 | + struct tx_rds rds; | ||
104 | + int ret; | ||
105 | + struct fmdev *fmdev; | ||
106 | + | ||
107 | + ret = copy_from_user(&rds, buf, sizeof(rds)); | ||
108 | + fmdbg("(%d)type: %d, text %s, af %d\n", | ||
109 | + ret, rds.text_type, rds.text, rds.af_freq); | ||
110 | + | ||
111 | + fmdev = video_drvdata(file); | ||
112 | + fm_tx_set_radio_text(fmdev, rds.text, rds.text_type); | ||
113 | + fm_tx_set_af(fmdev, rds.af_freq); | ||
114 | + | ||
115 | + return 0; | ||
116 | +} | ||
117 | + | ||
118 | +static u32 fm_v4l2_fops_poll(struct file *file, struct poll_table_struct *pts) | ||
119 | +{ | ||
120 | + int ret; | ||
121 | + struct fmdev *fmdev; | ||
122 | + | ||
123 | + fmdev = video_drvdata(file); | ||
124 | + ret = fmc_is_rds_data_available(fmdev, file, pts); | ||
125 | + if (ret < 0) | ||
126 | + return POLLIN | POLLRDNORM; | ||
127 | + | ||
128 | + return 0; | ||
129 | +} | ||
130 | + | ||
131 | +/* | ||
132 | + * Handle open request for "/dev/radioX" device. | ||
133 | + * Start with FM RX mode as default. | ||
134 | + */ | ||
135 | +static int fm_v4l2_fops_open(struct file *file) | ||
136 | +{ | ||
137 | + int ret; | ||
138 | + struct fmdev *fmdev = NULL; | ||
139 | + | ||
140 | + /* Don't allow multiple open */ | ||
141 | + if (radio_disconnected) { | ||
142 | + fmerr("FM device is already opened\n"); | ||
143 | + return -EBUSY; | ||
144 | + } | ||
145 | + | ||
146 | + fmdev = video_drvdata(file); | ||
147 | + | ||
148 | + ret = fmc_prepare(fmdev); | ||
149 | + if (ret < 0) { | ||
150 | + fmerr("Unable to prepare FM CORE\n"); | ||
151 | + return ret; | ||
152 | + } | ||
153 | + | ||
154 | + fmdbg("Load FM RX firmware..\n"); | ||
155 | + | ||
156 | + ret = fmc_set_mode(fmdev, FM_MODE_RX); | ||
157 | + if (ret < 0) { | ||
158 | + fmerr("Unable to load FM RX firmware\n"); | ||
159 | + return ret; | ||
160 | + } | ||
161 | + radio_disconnected = 1; | ||
162 | + | ||
163 | + return ret; | ||
164 | +} | ||
165 | + | ||
166 | +static int fm_v4l2_fops_release(struct file *file) | ||
167 | +{ | ||
168 | + int ret; | ||
169 | + struct fmdev *fmdev; | ||
170 | + | ||
171 | + fmdev = video_drvdata(file); | ||
172 | + if (!radio_disconnected) { | ||
173 | + fmdbg("FM device is already closed\n"); | ||
174 | + return 0; | ||
175 | + } | ||
176 | + | ||
177 | + ret = fmc_set_mode(fmdev, FM_MODE_OFF); | ||
178 | + if (ret < 0) { | ||
179 | + fmerr("Unable to turn off the chip\n"); | ||
180 | + return ret; | ||
181 | + } | ||
182 | + | ||
183 | + ret = fmc_release(fmdev); | ||
184 | + if (ret < 0) { | ||
185 | + fmerr("FM CORE release failed\n"); | ||
186 | + return ret; | ||
187 | + } | ||
188 | + radio_disconnected = 0; | ||
189 | + | ||
190 | + return ret; | ||
191 | +} | ||
192 | + | ||
193 | +/* V4L2 RADIO (/dev/radioX) device IOCTL interfaces */ | ||
194 | +static int fm_v4l2_vidioc_querycap(struct file *file, void *priv, | ||
195 | + struct v4l2_capability *capability) | ||
196 | +{ | ||
197 | + strlcpy(capability->driver, FM_DRV_NAME, sizeof(capability->driver)); | ||
198 | + strlcpy(capability->card, FM_DRV_CARD_SHORT_NAME, | ||
199 | + sizeof(capability->card)); | ||
200 | + sprintf(capability->bus_info, "UART"); | ||
201 | + capability->version = FM_DRV_RADIO_VERSION; | ||
202 | + capability->capabilities = V4L2_CAP_HW_FREQ_SEEK | V4L2_CAP_TUNER | | ||
203 | + V4L2_CAP_RADIO | V4L2_CAP_MODULATOR | | ||
204 | + V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | | ||
205 | + V4L2_CAP_RDS_CAPTURE; | ||
206 | + | ||
207 | + return 0; | ||
208 | +} | ||
209 | + | ||
210 | +static int fm_g_volatile_ctrl(struct v4l2_ctrl *ctrl) | ||
211 | +{ | ||
212 | + struct fmdev *fmdev = container_of(ctrl->handler, | ||
213 | + struct fmdev, ctrl_handler); | ||
214 | + | ||
215 | + switch (ctrl->id) { | ||
216 | + case V4L2_CID_TUNE_ANTENNA_CAPACITOR: | ||
217 | + ctrl->val = fm_tx_get_tune_cap_val(fmdev); | ||
218 | + break; | ||
219 | + default: | ||
220 | + fmwarn("%s: Unknown IOCTL: %d\n", __func__, ctrl->id); | ||
221 | + break; | ||
222 | + } | ||
223 | + | ||
224 | + return 0; | ||
225 | +} | ||
226 | + | ||
227 | +static int fm_v4l2_s_ctrl(struct v4l2_ctrl *ctrl) | ||
228 | +{ | ||
229 | + struct fmdev *fmdev = container_of(ctrl->handler, | ||
230 | + struct fmdev, ctrl_handler); | ||
231 | + | ||
232 | + switch (ctrl->id) { | ||
233 | + case V4L2_CID_AUDIO_VOLUME: /* set volume */ | ||
234 | + return fm_rx_set_volume(fmdev, (u16)ctrl->val); | ||
235 | + | ||
236 | + case V4L2_CID_AUDIO_MUTE: /* set mute */ | ||
237 | + return fmc_set_mute_mode(fmdev, (u8)ctrl->val); | ||
238 | + | ||
239 | + case V4L2_CID_TUNE_POWER_LEVEL: | ||
240 | + /* set TX power level - ext control */ | ||
241 | + return fm_tx_set_pwr_lvl(fmdev, (u8)ctrl->val); | ||
242 | + | ||
243 | + case V4L2_CID_TUNE_PREEMPHASIS: | ||
244 | + return fm_tx_set_preemph_filter(fmdev, (u8) ctrl->val); | ||
245 | + | ||
246 | + default: | ||
247 | + return -EINVAL; | ||
248 | + } | ||
249 | +} | ||
250 | + | ||
251 | +static int fm_v4l2_vidioc_g_audio(struct file *file, void *priv, | ||
252 | + struct v4l2_audio *audio) | ||
253 | +{ | ||
254 | + memset(audio, 0, sizeof(*audio)); | ||
255 | + strcpy(audio->name, "Radio"); | ||
256 | + audio->capability = V4L2_AUDCAP_STEREO; | ||
257 | + | ||
258 | + return 0; | ||
259 | +} | ||
260 | + | ||
261 | +static int fm_v4l2_vidioc_s_audio(struct file *file, void *priv, | ||
262 | + struct v4l2_audio *audio) | ||
263 | +{ | ||
264 | + if (audio->index != 0) | ||
265 | + return -EINVAL; | ||
266 | + | ||
267 | + return 0; | ||
268 | +} | ||
269 | + | ||
270 | +/* Get tuner attributes. If current mode is NOT RX, return error */ | ||
271 | +static int fm_v4l2_vidioc_g_tuner(struct file *file, void *priv, | ||
272 | + struct v4l2_tuner *tuner) | ||
273 | +{ | ||
274 | + struct fmdev *fmdev = video_drvdata(file); | ||
275 | + u32 bottom_freq; | ||
276 | + u32 top_freq; | ||
277 | + u16 stereo_mono_mode; | ||
278 | + u16 rssilvl; | ||
279 | + int ret; | ||
280 | + | ||
281 | + if (tuner->index != 0) | ||
282 | + return -EINVAL; | ||
283 | + | ||
284 | + if (fmdev->curr_fmmode != FM_MODE_RX) | ||
285 | + return -EPERM; | ||
286 | + | ||
287 | + ret = fm_rx_get_band_freq_range(fmdev, &bottom_freq, &top_freq); | ||
288 | + if (ret != 0) | ||
289 | + return ret; | ||
290 | + | ||
291 | + ret = fm_rx_get_stereo_mono(fmdev, &stereo_mono_mode); | ||
292 | + if (ret != 0) | ||
293 | + return ret; | ||
294 | + | ||
295 | + ret = fm_rx_get_rssi_level(fmdev, &rssilvl); | ||
296 | + if (ret != 0) | ||
297 | + return ret; | ||
298 | + | ||
299 | + strcpy(tuner->name, "FM"); | ||
300 | + tuner->type = V4L2_TUNER_RADIO; | ||
301 | + /* Store rangelow and rangehigh freq in unit of 62.5 Hz */ | ||
302 | + tuner->rangelow = bottom_freq * 16; | ||
303 | + tuner->rangehigh = top_freq * 16; | ||
304 | + tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO | | ||
305 | + ((fmdev->rx.rds.flag == FM_RDS_ENABLE) ? V4L2_TUNER_SUB_RDS : 0); | ||
306 | + tuner->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS | | ||
307 | + V4L2_TUNER_CAP_LOW; | ||
308 | + tuner->audmode = (stereo_mono_mode ? | ||
309 | + V4L2_TUNER_MODE_MONO : V4L2_TUNER_MODE_STEREO); | ||
310 | + | ||
311 | + /* | ||
312 | + * Actual rssi value lies in between -128 to +127. | ||
313 | + * Convert this range from 0 to 255 by adding +128 | ||
314 | + */ | ||
315 | + rssilvl += 128; | ||
316 | + | ||
317 | + /* | ||
318 | + * Return signal strength value should be within 0 to 65535. | ||
319 | + * Find out correct signal radio by multiplying (65535/255) = 257 | ||
320 | + */ | ||
321 | + tuner->signal = rssilvl * 257; | ||
322 | + tuner->afc = 0; | ||
323 | + | ||
324 | + return ret; | ||
325 | +} | ||
326 | + | ||
327 | +/* | ||
328 | + * Set tuner attributes. If current mode is NOT RX, set to RX. | ||
329 | + * Currently, we set only audio mode (mono/stereo) and RDS state (on/off). | ||
330 | + * Should we set other tuner attributes, too? | ||
331 | + */ | ||
332 | +static int fm_v4l2_vidioc_s_tuner(struct file *file, void *priv, | ||
333 | + struct v4l2_tuner *tuner) | ||
334 | +{ | ||
335 | + struct fmdev *fmdev = video_drvdata(file); | ||
336 | + u16 aud_mode; | ||
337 | + u8 rds_mode; | ||
338 | + int ret; | ||
339 | + | ||
340 | + if (tuner->index != 0) | ||
341 | + return -EINVAL; | ||
342 | + | ||
343 | + aud_mode = (tuner->audmode == V4L2_TUNER_MODE_STEREO) ? | ||
344 | + FM_STEREO_MODE : FM_MONO_MODE; | ||
345 | + rds_mode = (tuner->rxsubchans & V4L2_TUNER_SUB_RDS) ? | ||
346 | + FM_RDS_ENABLE : FM_RDS_DISABLE; | ||
347 | + | ||
348 | + if (fmdev->curr_fmmode != FM_MODE_RX) { | ||
349 | + ret = fmc_set_mode(fmdev, FM_MODE_RX); | ||
350 | + if (ret < 0) { | ||
351 | + fmerr("Failed to set RX mode\n"); | ||
352 | + return ret; | ||
353 | + } | ||
354 | + } | ||
355 | + | ||
356 | + ret = fmc_set_stereo_mono(fmdev, aud_mode); | ||
357 | + if (ret < 0) { | ||
358 | + fmerr("Failed to set RX stereo/mono mode\n"); | ||
359 | + return ret; | ||
360 | + } | ||
361 | + | ||
362 | + ret = fmc_set_rds_mode(fmdev, rds_mode); | ||
363 | + if (ret < 0) | ||
364 | + fmerr("Failed to set RX RDS mode\n"); | ||
365 | + | ||
366 | + return ret; | ||
367 | +} | ||
368 | + | ||
369 | +/* Get tuner or modulator radio frequency */ | ||
370 | +static int fm_v4l2_vidioc_g_freq(struct file *file, void *priv, | ||
371 | + struct v4l2_frequency *freq) | ||
372 | +{ | ||
373 | + struct fmdev *fmdev = video_drvdata(file); | ||
374 | + int ret; | ||
375 | + | ||
376 | + ret = fmc_get_freq(fmdev, &freq->frequency); | ||
377 | + if (ret < 0) { | ||
378 | + fmerr("Failed to get frequency\n"); | ||
379 | + return ret; | ||
380 | + } | ||
381 | + | ||
382 | + /* Frequency unit of 62.5 Hz*/ | ||
383 | + freq->frequency = (u32) freq->frequency * 16; | ||
384 | + | ||
385 | + return 0; | ||
386 | +} | ||
387 | + | ||
388 | +/* Set tuner or modulator radio frequency */ | ||
389 | +static int fm_v4l2_vidioc_s_freq(struct file *file, void *priv, | ||
390 | + struct v4l2_frequency *freq) | ||
391 | +{ | ||
392 | + struct fmdev *fmdev = video_drvdata(file); | ||
393 | + | ||
394 | + /* | ||
395 | + * As V4L2_TUNER_CAP_LOW is set 1 user sends the frequency | ||
396 | + * in units of 62.5 Hz. | ||
397 | + */ | ||
398 | + freq->frequency = (u32)(freq->frequency / 16); | ||
399 | + | ||
400 | + return fmc_set_freq(fmdev, freq->frequency); | ||
401 | +} | ||
402 | + | ||
403 | +/* Set hardware frequency seek. If current mode is NOT RX, set it RX. */ | ||
404 | +static int fm_v4l2_vidioc_s_hw_freq_seek(struct file *file, void *priv, | ||
405 | + struct v4l2_hw_freq_seek *seek) | ||
406 | +{ | ||
407 | + struct fmdev *fmdev = video_drvdata(file); | ||
408 | + int ret; | ||
409 | + | ||
410 | + if (fmdev->curr_fmmode != FM_MODE_RX) { | ||
411 | + ret = fmc_set_mode(fmdev, FM_MODE_RX); | ||
412 | + if (ret != 0) { | ||
413 | + fmerr("Failed to set RX mode\n"); | ||
414 | + return ret; | ||
415 | + } | ||
416 | + } | ||
417 | + | ||
418 | + ret = fm_rx_seek(fmdev, seek->seek_upward, seek->wrap_around, | ||
419 | + seek->spacing); | ||
420 | + if (ret < 0) | ||
421 | + fmerr("RX seek failed - %d\n", ret); | ||
422 | + | ||
423 | + return ret; | ||
424 | +} | ||
425 | +/* Get modulator attributes. If mode is not TX, return no attributes. */ | ||
426 | +static int fm_v4l2_vidioc_g_modulator(struct file *file, void *priv, | ||
427 | + struct v4l2_modulator *mod) | ||
428 | +{ | ||
429 | + struct fmdev *fmdev = video_drvdata(file);; | ||
430 | + | ||
431 | + if (mod->index != 0) | ||
432 | + return -EINVAL; | ||
433 | + | ||
434 | + if (fmdev->curr_fmmode != FM_MODE_TX) | ||
435 | + return -EPERM; | ||
436 | + | ||
437 | + mod->txsubchans = ((fmdev->tx_data.aud_mode == FM_STEREO_MODE) ? | ||
438 | + V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO) | | ||
439 | + ((fmdev->tx_data.rds.flag == FM_RDS_ENABLE) ? | ||
440 | + V4L2_TUNER_SUB_RDS : 0); | ||
441 | + | ||
442 | + mod->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS | | ||
443 | + V4L2_TUNER_CAP_LOW; | ||
444 | + | ||
445 | + return 0; | ||
446 | +} | ||
447 | + | ||
448 | +/* Set modulator attributes. If mode is not TX, set to TX. */ | ||
449 | +static int fm_v4l2_vidioc_s_modulator(struct file *file, void *priv, | ||
450 | + struct v4l2_modulator *mod) | ||
451 | +{ | ||
452 | + struct fmdev *fmdev = video_drvdata(file); | ||
453 | + u8 rds_mode; | ||
454 | + u16 aud_mode; | ||
455 | + int ret; | ||
456 | + | ||
457 | + if (mod->index != 0) | ||
458 | + return -EINVAL; | ||
459 | + | ||
460 | + if (fmdev->curr_fmmode != FM_MODE_TX) { | ||
461 | + ret = fmc_set_mode(fmdev, FM_MODE_TX); | ||
462 | + if (ret != 0) { | ||
463 | + fmerr("Failed to set TX mode\n"); | ||
464 | + return ret; | ||
465 | + } | ||
466 | + } | ||
467 | + | ||
468 | + aud_mode = (mod->txsubchans & V4L2_TUNER_SUB_STEREO) ? | ||
469 | + FM_STEREO_MODE : FM_MONO_MODE; | ||
470 | + rds_mode = (mod->txsubchans & V4L2_TUNER_SUB_RDS) ? | ||
471 | + FM_RDS_ENABLE : FM_RDS_DISABLE; | ||
472 | + ret = fm_tx_set_stereo_mono(fmdev, aud_mode); | ||
473 | + if (ret < 0) { | ||
474 | + fmerr("Failed to set mono/stereo mode for TX\n"); | ||
475 | + return ret; | ||
476 | + } | ||
477 | + ret = fm_tx_set_rds_mode(fmdev, rds_mode); | ||
478 | + if (ret < 0) | ||
479 | + fmerr("Failed to set rds mode for TX\n"); | ||
480 | + | ||
481 | + return ret; | ||
482 | +} | ||
483 | + | ||
484 | +static const struct v4l2_file_operations fm_drv_fops = { | ||
485 | + .owner = THIS_MODULE, | ||
486 | + .read = fm_v4l2_fops_read, | ||
487 | + .write = fm_v4l2_fops_write, | ||
488 | + .poll = fm_v4l2_fops_poll, | ||
489 | + .unlocked_ioctl = video_ioctl2, | ||
490 | + .open = fm_v4l2_fops_open, | ||
491 | + .release = fm_v4l2_fops_release, | ||
492 | +}; | ||
493 | + | ||
494 | +static const struct v4l2_ctrl_ops fm_ctrl_ops = { | ||
495 | + .s_ctrl = fm_v4l2_s_ctrl, | ||
496 | + .g_volatile_ctrl = fm_g_volatile_ctrl, | ||
497 | +}; | ||
498 | +static const struct v4l2_ioctl_ops fm_drv_ioctl_ops = { | ||
499 | + .vidioc_querycap = fm_v4l2_vidioc_querycap, | ||
500 | + .vidioc_g_audio = fm_v4l2_vidioc_g_audio, | ||
501 | + .vidioc_s_audio = fm_v4l2_vidioc_s_audio, | ||
502 | + .vidioc_g_tuner = fm_v4l2_vidioc_g_tuner, | ||
503 | + .vidioc_s_tuner = fm_v4l2_vidioc_s_tuner, | ||
504 | + .vidioc_g_frequency = fm_v4l2_vidioc_g_freq, | ||
505 | + .vidioc_s_frequency = fm_v4l2_vidioc_s_freq, | ||
506 | + .vidioc_s_hw_freq_seek = fm_v4l2_vidioc_s_hw_freq_seek, | ||
507 | + .vidioc_g_modulator = fm_v4l2_vidioc_g_modulator, | ||
508 | + .vidioc_s_modulator = fm_v4l2_vidioc_s_modulator | ||
509 | +}; | ||
510 | + | ||
511 | +/* V4L2 RADIO device parent structure */ | ||
512 | +static struct video_device fm_viddev_template = { | ||
513 | + .fops = &fm_drv_fops, | ||
514 | + .ioctl_ops = &fm_drv_ioctl_ops, | ||
515 | + .name = FM_DRV_NAME, | ||
516 | + .release = video_device_release, | ||
517 | +}; | ||
518 | + | ||
519 | +int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr) | ||
520 | +{ | ||
521 | + struct v4l2_ctrl *ctrl; | ||
522 | + int ret; | ||
523 | + | ||
524 | + /* Init mutex for core locking */ | ||
525 | + mutex_init(&fmdev->mutex); | ||
526 | + | ||
527 | + /* Allocate new video device */ | ||
528 | + gradio_dev = video_device_alloc(); | ||
529 | + if (NULL == gradio_dev) { | ||
530 | + fmerr("Can't allocate video device\n"); | ||
531 | + return -ENOMEM; | ||
532 | + } | ||
533 | + | ||
534 | + /* Setup FM driver's V4L2 properties */ | ||
535 | + memcpy(gradio_dev, &fm_viddev_template, sizeof(fm_viddev_template)); | ||
536 | + | ||
537 | + video_set_drvdata(gradio_dev, fmdev); | ||
538 | + | ||
539 | + gradio_dev->lock = &fmdev->mutex; | ||
540 | + | ||
541 | + /* Register with V4L2 subsystem as RADIO device */ | ||
542 | + if (video_register_device(gradio_dev, VFL_TYPE_RADIO, radio_nr)) { | ||
543 | + video_device_release(gradio_dev); | ||
544 | + fmerr("Could not register video device\n"); | ||
545 | + return -ENOMEM; | ||
546 | + } | ||
547 | + | ||
548 | + fmdev->radio_dev = gradio_dev; | ||
549 | + | ||
550 | + /* Register to v4l2 ctrl handler framework */ | ||
551 | + fmdev->radio_dev->ctrl_handler = &fmdev->ctrl_handler; | ||
552 | + | ||
553 | + ret = v4l2_ctrl_handler_init(&fmdev->ctrl_handler, 5); | ||
554 | + if (ret < 0) { | ||
555 | + fmerr("(fmdev): Can't init ctrl handler\n"); | ||
556 | + v4l2_ctrl_handler_free(&fmdev->ctrl_handler); | ||
557 | + return -EBUSY; | ||
558 | + } | ||
559 | + | ||
560 | + /* | ||
561 | + * Following controls are handled by V4L2 control framework. | ||
562 | + * Added in ascending ID order. | ||
563 | + */ | ||
564 | + v4l2_ctrl_new_std(&fmdev->ctrl_handler, &fm_ctrl_ops, | ||
565 | + V4L2_CID_AUDIO_VOLUME, FM_RX_VOLUME_MIN, | ||
566 | + FM_RX_VOLUME_MAX, 1, FM_RX_VOLUME_MAX); | ||
567 | + | ||
568 | + v4l2_ctrl_new_std(&fmdev->ctrl_handler, &fm_ctrl_ops, | ||
569 | + V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1); | ||
570 | + | ||
571 | + v4l2_ctrl_new_std_menu(&fmdev->ctrl_handler, &fm_ctrl_ops, | ||
572 | + V4L2_CID_TUNE_PREEMPHASIS, V4L2_PREEMPHASIS_75_uS, | ||
573 | + 0, V4L2_PREEMPHASIS_75_uS); | ||
574 | + | ||
575 | + v4l2_ctrl_new_std(&fmdev->ctrl_handler, &fm_ctrl_ops, | ||
576 | + V4L2_CID_TUNE_POWER_LEVEL, FM_PWR_LVL_LOW, | ||
577 | + FM_PWR_LVL_HIGH, 1, FM_PWR_LVL_HIGH); | ||
578 | + | ||
579 | + ctrl = v4l2_ctrl_new_std(&fmdev->ctrl_handler, &fm_ctrl_ops, | ||
580 | + V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, | ||
581 | + 255, 1, 255); | ||
582 | + | ||
583 | + if (ctrl) | ||
584 | + ctrl->is_volatile = 1; | ||
585 | + | ||
586 | + return 0; | ||
587 | +} | ||
588 | + | ||
589 | +void *fm_v4l2_deinit_video_device(void) | ||
590 | +{ | ||
591 | + struct fmdev *fmdev; | ||
592 | + | ||
593 | + | ||
594 | + fmdev = video_get_drvdata(gradio_dev); | ||
595 | + | ||
596 | + /* Unregister to v4l2 ctrl handler framework*/ | ||
597 | + v4l2_ctrl_handler_free(&fmdev->ctrl_handler); | ||
598 | + | ||
599 | + /* Unregister RADIO device from V4L2 subsystem */ | ||
600 | + video_unregister_device(gradio_dev); | ||
601 | + | ||
602 | + return fmdev; | ||
603 | +} | ||
604 | diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.h b/drivers/media/radio/wl128x/fmdrv_v4l2.h | ||
605 | new file mode 100644 | ||
606 | index 0000000..0ba79d7 | ||
607 | --- /dev/null | ||
608 | +++ b/drivers/media/radio/wl128x/fmdrv_v4l2.h | ||
609 | @@ -0,0 +1,33 @@ | ||
610 | +/* | ||
611 | + * FM Driver for Connectivity chip of Texas Instruments. | ||
612 | + * | ||
613 | + * FM V4L2 module header. | ||
614 | + * | ||
615 | + * Copyright (C) 2011 Texas Instruments | ||
616 | + * | ||
617 | + * This program is free software; you can redistribute it and/or modify | ||
618 | + * it under the terms of the GNU General Public License version 2 as | ||
619 | + * published by the Free Software Foundation. | ||
620 | + * | ||
621 | + * This program is distributed in the hope that it will be useful, | ||
622 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
623 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
624 | + * GNU General Public License for more details. | ||
625 | + * | ||
626 | + * You should have received a copy of the GNU General Public License | ||
627 | + * along with this program; if not, write to the Free Software | ||
628 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
629 | + * | ||
630 | + */ | ||
631 | + | ||
632 | +#ifndef _FMDRV_V4L2_H | ||
633 | +#define _FMDRV_V4L2_H | ||
634 | + | ||
635 | +#include <media/v4l2-ioctl.h> | ||
636 | +#include <media/v4l2-common.h> | ||
637 | +#include <media/v4l2-ctrls.h> | ||
638 | + | ||
639 | +int fm_v4l2_init_video_device(struct fmdev *, int); | ||
640 | +void *fm_v4l2_deinit_video_device(void); | ||
641 | + | ||
642 | +#endif | ||
643 | -- | ||
644 | 1.6.6.1 | ||
645 | |||