aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/pci/ivtv
diff options
context:
space:
mode:
authorAndy Walls <awalls@md.metrocast.net>2012-09-02 18:13:14 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-09-18 12:26:50 -0400
commit269c11fbac4f7b4ed58e77f3049b64b55a342234 (patch)
tree53e01d0a8f9cd1cd488f2d3e2838a79edf1ccfe6 /drivers/media/pci/ivtv
parent6d60805fd2e8103fafa02fcf6448446229ebd511 (diff)
[media] ivtv, ivtv-alsa: Add initial ivtv-alsa interface driver for ivtv
This is a cut-and-paste port of the cx18-alsa driver to create an ivtv-alsa interface module for the ivtv driver. It is not actually hooked-up to the PCM stream DMA buffers from the ivtv driver yet. That will be done in a coming change, since that portion is so very different from the cx18 driver. This code has all or more of the bugs and shortcomings of the cx18-alsa interface driver: inconsistent use of itvsc->slock, ivtv-alsa-mixer.c is dead code, assumes 48 ksps regardless of the actual setting of the audio capture, problems with proper struct ivtv and struct ivtv_stream housekeeping, struct ivtv_open_id.v4l2_fh abuse, and $DIETY knows what else. Signed-off-by: Andy Walls <awalls@md.metrocast.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/pci/ivtv')
-rw-r--r--drivers/media/pci/ivtv/Kconfig11
-rw-r--r--drivers/media/pci/ivtv/Makefile2
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-main.c303
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-mixer.c175
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-mixer.h23
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-pcm.c357
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-pcm.h27
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa.h75
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c37
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.h10
-rw-r--r--drivers/media/pci/ivtv/ivtv-fileops.c4
-rw-r--r--drivers/media/pci/ivtv/ivtv-fileops.h4
-rw-r--r--drivers/media/pci/ivtv/ivtv-streams.c2
13 files changed, 1027 insertions, 3 deletions
diff --git a/drivers/media/pci/ivtv/Kconfig b/drivers/media/pci/ivtv/Kconfig
index 89f65914cc8e..3906b883e2bc 100644
--- a/drivers/media/pci/ivtv/Kconfig
+++ b/drivers/media/pci/ivtv/Kconfig
@@ -28,6 +28,17 @@ config VIDEO_IVTV
28 To compile this driver as a module, choose M here: the 28 To compile this driver as a module, choose M here: the
29 module will be called ivtv. 29 module will be called ivtv.
30 30
31config VIDEO_IVTV_ALSA
32 tristate "Conexant cx23415/cx23416 PCM audio capture support"
33 depends on VIDEO_IVTV && SND && EXPERIMENTAL
34 select SND_PCM
35 ---help---
36 This is an ALSA interface driver for direct PCM audio capture from
37 Conexant cx23415/cx23416 based PCI TV cards using the ivtv driver.
38
39 To compile this driver as a module, choose M here: the
40 module will be called ivtv-alsa.
41
31config VIDEO_FB_IVTV 42config VIDEO_FB_IVTV
32 tristate "Conexant cx23415 framebuffer support" 43 tristate "Conexant cx23415 framebuffer support"
33 depends on VIDEO_IVTV && FB 44 depends on VIDEO_IVTV && FB
diff --git a/drivers/media/pci/ivtv/Makefile b/drivers/media/pci/ivtv/Makefile
index 1408c9f1de93..0eaa88298b7e 100644
--- a/drivers/media/pci/ivtv/Makefile
+++ b/drivers/media/pci/ivtv/Makefile
@@ -3,8 +3,10 @@ ivtv-objs := ivtv-routing.o ivtv-cards.o ivtv-controls.o \
3 ivtv-gpio.o ivtv-i2c.o ivtv-ioctl.o ivtv-irq.o \ 3 ivtv-gpio.o ivtv-i2c.o ivtv-ioctl.o ivtv-irq.o \
4 ivtv-mailbox.o ivtv-queue.o ivtv-streams.o ivtv-udma.o \ 4 ivtv-mailbox.o ivtv-queue.o ivtv-streams.o ivtv-udma.o \
5 ivtv-vbi.o ivtv-yuv.o 5 ivtv-vbi.o ivtv-yuv.o
6ivtv-alsa-objs := ivtv-alsa-main.o ivtv-alsa-pcm.o
6 7
7obj-$(CONFIG_VIDEO_IVTV) += ivtv.o 8obj-$(CONFIG_VIDEO_IVTV) += ivtv.o
9obj-$(CONFIG_VIDEO_IVTV_ALSA) += ivtv-alsa.o
8obj-$(CONFIG_VIDEO_FB_IVTV) += ivtvfb.o 10obj-$(CONFIG_VIDEO_FB_IVTV) += ivtvfb.o
9 11
10ccflags-y += -I$(srctree)/drivers/media/i2c 12ccflags-y += -I$(srctree)/drivers/media/i2c
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-main.c b/drivers/media/pci/ivtv/ivtv-alsa-main.c
new file mode 100644
index 000000000000..8deab1629b3b
--- /dev/null
+++ b/drivers/media/pci/ivtv/ivtv-alsa-main.c
@@ -0,0 +1,303 @@
1/*
2 * ALSA interface to ivtv PCM capture streams
3 *
4 * Copyright (C) 2009,2012 Andy Walls <awalls@md.metrocast.net>
5 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
6 *
7 * Portions of this work were sponsored by ONELAN Limited for the cx18 driver
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 * 02111-1307 USA
23 */
24
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/device.h>
30#include <linux/spinlock.h>
31
32#include <media/v4l2-device.h>
33
34#include <sound/core.h>
35#include <sound/initval.h>
36
37#include "ivtv-driver.h"
38#include "ivtv-version.h"
39#include "ivtv-alsa.h"
40#include "ivtv-alsa-mixer.h"
41#include "ivtv-alsa-pcm.h"
42
43int ivtv_alsa_debug;
44
45#define IVTV_DEBUG_ALSA_INFO(fmt, arg...) \
46 do { \
47 if (ivtv_alsa_debug & 2) \
48 pr_info("%s: " fmt, "ivtv-alsa", ## arg); \
49 } while (0)
50
51module_param_named(debug, ivtv_alsa_debug, int, 0644);
52MODULE_PARM_DESC(debug,
53 "Debug level (bitmask). Default: 0\n"
54 "\t\t\t 1/0x0001: warning\n"
55 "\t\t\t 2/0x0002: info\n");
56
57MODULE_AUTHOR("Andy Walls");
58MODULE_DESCRIPTION("CX23415/CX23416 ALSA Interface");
59MODULE_SUPPORTED_DEVICE("CX23415/CX23416 MPEG2 encoder");
60MODULE_LICENSE("GPL");
61
62MODULE_VERSION(IVTV_VERSION);
63
64static inline
65struct snd_ivtv_card *to_snd_ivtv_card(struct v4l2_device *v4l2_dev)
66{
67 return to_ivtv(v4l2_dev)->alsa;
68}
69
70static inline
71struct snd_ivtv_card *p_to_snd_ivtv_card(struct v4l2_device **v4l2_dev)
72{
73 return container_of(v4l2_dev, struct snd_ivtv_card, v4l2_dev);
74}
75
76static void snd_ivtv_card_free(struct snd_ivtv_card *itvsc)
77{
78 if (itvsc == NULL)
79 return;
80
81 if (itvsc->v4l2_dev != NULL)
82 to_ivtv(itvsc->v4l2_dev)->alsa = NULL;
83
84 /* FIXME - take any other stopping actions needed */
85
86 kfree(itvsc);
87}
88
89static void snd_ivtv_card_private_free(struct snd_card *sc)
90{
91 if (sc == NULL)
92 return;
93 snd_ivtv_card_free(sc->private_data);
94 sc->private_data = NULL;
95 sc->private_free = NULL;
96}
97
98static int snd_ivtv_card_create(struct v4l2_device *v4l2_dev,
99 struct snd_card *sc,
100 struct snd_ivtv_card **itvsc)
101{
102 *itvsc = kzalloc(sizeof(struct snd_ivtv_card), GFP_KERNEL);
103 if (*itvsc == NULL)
104 return -ENOMEM;
105
106 (*itvsc)->v4l2_dev = v4l2_dev;
107 (*itvsc)->sc = sc;
108
109 sc->private_data = *itvsc;
110 sc->private_free = snd_ivtv_card_private_free;
111
112 return 0;
113}
114
115static int snd_ivtv_card_set_names(struct snd_ivtv_card *itvsc)
116{
117 struct ivtv *itv = to_ivtv(itvsc->v4l2_dev);
118 struct snd_card *sc = itvsc->sc;
119
120 /* sc->driver is used by alsa-lib's configurator: simple, unique */
121 strlcpy(sc->driver, "CX2341[56]", sizeof(sc->driver));
122
123 /* sc->shortname is a symlink in /proc/asound: IVTV-M -> cardN */
124 snprintf(sc->shortname, sizeof(sc->shortname), "IVTV-%d",
125 itv->instance);
126
127 /* sc->longname is read from /proc/asound/cards */
128 snprintf(sc->longname, sizeof(sc->longname),
129 "CX2341[56] #%d %s TV/FM Radio/Line-In Capture",
130 itv->instance, itv->card_name);
131
132 return 0;
133}
134
135static int snd_ivtv_init(struct v4l2_device *v4l2_dev)
136{
137 struct ivtv *itv = to_ivtv(v4l2_dev);
138 struct snd_card *sc = NULL;
139 struct snd_ivtv_card *itvsc;
140 int ret;
141
142 /* Numbrs steps from "Writing an ALSA Driver" by Takashi Iwai */
143
144 /* (1) Check and increment the device index */
145 /* This is a no-op for us. We'll use the itv->instance */
146
147 /* (2) Create a card instance */
148 ret = snd_card_create(SNDRV_DEFAULT_IDX1, /* use first available id */
149 SNDRV_DEFAULT_STR1, /* xid from end of shortname*/
150 THIS_MODULE, 0, &sc);
151 if (ret) {
152 IVTV_ALSA_ERR("%s: snd_card_create() failed with err %d\n",
153 __func__, ret);
154 goto err_exit;
155 }
156
157 /* (3) Create a main component */
158 ret = snd_ivtv_card_create(v4l2_dev, sc, &itvsc);
159 if (ret) {
160 IVTV_ALSA_ERR("%s: snd_ivtv_card_create() failed with err %d\n",
161 __func__, ret);
162 goto err_exit_free;
163 }
164
165 /* (4) Set the driver ID and name strings */
166 snd_ivtv_card_set_names(itvsc);
167
168 /* (5) Create other components: mixer, PCM, & proc files */
169#if 0
170 ret = snd_ivtv_mixer_create(itvsc);
171 if (ret) {
172 IVTV_ALSA_WARN("%s: snd_ivtv_mixer_create() failed with err %d:"
173 " proceeding anyway\n", __func__, ret);
174 }
175#endif
176
177 ret = snd_ivtv_pcm_create(itvsc);
178 if (ret) {
179 IVTV_ALSA_ERR("%s: snd_ivtv_pcm_create() failed with err %d\n",
180 __func__, ret);
181 goto err_exit_free;
182 }
183 /* FIXME - proc files */
184
185 /* (7) Set the driver data and return 0 */
186 /* We do this out of normal order for PCI drivers to avoid races */
187 itv->alsa = itvsc;
188
189 /* (6) Register the card instance */
190 ret = snd_card_register(sc);
191 if (ret) {
192 itv->alsa = NULL;
193 IVTV_ALSA_ERR("%s: snd_card_register() failed with err %d\n",
194 __func__, ret);
195 goto err_exit_free;
196 }
197
198 return 0;
199
200err_exit_free:
201 if (sc != NULL)
202 snd_card_free(sc);
203 kfree(itvsc);
204err_exit:
205 return ret;
206}
207
208int ivtv_alsa_load(struct ivtv *itv)
209{
210 struct v4l2_device *v4l2_dev = &itv->v4l2_dev;
211 struct ivtv_stream *s;
212
213 if (v4l2_dev == NULL) {
214 pr_err("ivtv-alsa: %s: struct v4l2_device * is NULL\n",
215 __func__);
216 return 0;
217 }
218
219 itv = to_ivtv(v4l2_dev);
220 if (itv == NULL) {
221 pr_err("ivtv-alsa itv is NULL\n");
222 return 0;
223 }
224
225 s = &itv->streams[IVTV_ENC_STREAM_TYPE_PCM];
226 if (s->vdev == NULL) {
227 IVTV_DEBUG_ALSA_INFO("%s: PCM stream for card is disabled - "
228 "skipping\n", __func__);
229 return 0;
230 }
231
232 if (itv->alsa != NULL) {
233 IVTV_ALSA_ERR("%s: struct snd_ivtv_card * already exists\n",
234 __func__);
235 return 0;
236 }
237
238 if (snd_ivtv_init(v4l2_dev)) {
239 IVTV_ALSA_ERR("%s: failed to create struct snd_ivtv_card\n",
240 __func__);
241 } else {
242 IVTV_DEBUG_ALSA_INFO("%s: created ivtv ALSA interface instance "
243 "\n", __func__);
244 }
245 return 0;
246}
247
248static int __init ivtv_alsa_init(void)
249{
250 pr_info("ivtv-alsa: module loading...\n");
251 ivtv_ext_init = &ivtv_alsa_load;
252 return 0;
253}
254
255static void __exit snd_ivtv_exit(struct snd_ivtv_card *itvsc)
256{
257 struct ivtv *itv = to_ivtv(itvsc->v4l2_dev);
258
259 /* FIXME - pointer checks & shutdown itvsc */
260
261 snd_card_free(itvsc->sc);
262 itv->alsa = NULL;
263}
264
265static int __exit ivtv_alsa_exit_callback(struct device *dev, void *data)
266{
267 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
268 struct snd_ivtv_card *itvsc;
269
270 if (v4l2_dev == NULL) {
271 pr_err("ivtv-alsa: %s: struct v4l2_device * is NULL\n",
272 __func__);
273 return 0;
274 }
275
276 itvsc = to_snd_ivtv_card(v4l2_dev);
277 if (itvsc == NULL) {
278 IVTV_ALSA_WARN("%s: struct snd_ivtv_card * is NULL\n",
279 __func__);
280 return 0;
281 }
282
283 snd_ivtv_exit(itvsc);
284 return 0;
285}
286
287static void __exit ivtv_alsa_exit(void)
288{
289 struct device_driver *drv;
290 int ret;
291
292 pr_info("ivtv-alsa: module unloading...\n");
293
294 drv = driver_find("ivtv", &pci_bus_type);
295 ret = driver_for_each_device(drv, NULL, NULL, ivtv_alsa_exit_callback);
296 (void)ret; /* suppress compiler warning */
297
298 ivtv_ext_init = NULL;
299 pr_info("ivtv-alsa: module unload complete\n");
300}
301
302module_init(ivtv_alsa_init);
303module_exit(ivtv_alsa_exit);
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-mixer.c b/drivers/media/pci/ivtv/ivtv-alsa-mixer.c
new file mode 100644
index 000000000000..33ec05b09af3
--- /dev/null
+++ b/drivers/media/pci/ivtv/ivtv-alsa-mixer.c
@@ -0,0 +1,175 @@
1/*
2 * ALSA mixer controls for the
3 * ALSA interface to ivtv PCM capture streams
4 *
5 * Copyright (C) 2009,2012 Andy Walls <awalls@md.metrocast.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/device.h>
26#include <linux/spinlock.h>
27#include <linux/videodev2.h>
28
29#include <media/v4l2-device.h>
30
31#include <sound/core.h>
32#include <sound/control.h>
33#include <sound/tlv.h>
34
35#include "ivtv-alsa.h"
36#include "ivtv-driver.h"
37
38/*
39 * Note the cx25840-core volume scale is funny, due to the alignment of the
40 * scale with another chip's range:
41 *
42 * v4l2_control value /512 indicated dB actual dB reg 0x8d4
43 * 0x0000 - 0x01ff 0 -119 -96 228
44 * 0x0200 - 0x02ff 1 -118 -96 228
45 * ...
46 * 0x2c00 - 0x2dff 22 -97 -96 228
47 * 0x2e00 - 0x2fff 23 -96 -96 228
48 * 0x3000 - 0x31ff 24 -95 -95 226
49 * ...
50 * 0xee00 - 0xefff 119 0 0 36
51 * ...
52 * 0xfe00 - 0xffff 127 +8 +8 20
53 */
54static inline int dB_to_cx25840_vol(int dB)
55{
56 if (dB < -96)
57 dB = -96;
58 else if (dB > 8)
59 dB = 8;
60 return (dB + 119) << 9;
61}
62
63static inline int cx25840_vol_to_dB(int v)
64{
65 if (v < (23 << 9))
66 v = (23 << 9);
67 else if (v > (127 << 9))
68 v = (127 << 9);
69 return (v >> 9) - 119;
70}
71
72static int snd_ivtv_mixer_tv_vol_info(struct snd_kcontrol *kcontrol,
73 struct snd_ctl_elem_info *uinfo)
74{
75 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
76 uinfo->count = 1;
77 /* We're already translating values, just keep this control in dB */
78 uinfo->value.integer.min = -96;
79 uinfo->value.integer.max = 8;
80 uinfo->value.integer.step = 1;
81 return 0;
82}
83
84static int snd_ivtv_mixer_tv_vol_get(struct snd_kcontrol *kctl,
85 struct snd_ctl_elem_value *uctl)
86{
87 struct snd_ivtv_card *itvsc = snd_kcontrol_chip(kctl);
88 struct ivtv *itv = to_ivtv(itvsc->v4l2_dev);
89 struct v4l2_control vctrl;
90 int ret;
91
92 vctrl.id = V4L2_CID_AUDIO_VOLUME;
93 vctrl.value = dB_to_cx25840_vol(uctl->value.integer.value[0]);
94
95 snd_ivtv_lock(itvsc);
96 ret = v4l2_subdev_call(itv->sd_audio, core, g_ctrl, &vctrl);
97 snd_ivtv_unlock(itvsc);
98
99 if (!ret)
100 uctl->value.integer.value[0] = cx25840_vol_to_dB(vctrl.value);
101 return ret;
102}
103
104static int snd_ivtv_mixer_tv_vol_put(struct snd_kcontrol *kctl,
105 struct snd_ctl_elem_value *uctl)
106{
107 struct snd_ivtv_card *itvsc = snd_kcontrol_chip(kctl);
108 struct ivtv *itv = to_ivtv(itvsc->v4l2_dev);
109 struct v4l2_control vctrl;
110 int ret;
111
112 vctrl.id = V4L2_CID_AUDIO_VOLUME;
113 vctrl.value = dB_to_cx25840_vol(uctl->value.integer.value[0]);
114
115 snd_ivtv_lock(itvsc);
116
117 /* Fetch current state */
118 ret = v4l2_subdev_call(itv->sd_audio, core, g_ctrl, &vctrl);
119
120 if (ret ||
121 (cx25840_vol_to_dB(vctrl.value) != uctl->value.integer.value[0])) {
122
123 /* Set, if needed */
124 vctrl.value = dB_to_cx25840_vol(uctl->value.integer.value[0]);
125 ret = v4l2_subdev_call(itv->sd_audio, core, s_ctrl, &vctrl);
126 if (!ret)
127 ret = 1; /* Indicate control was changed w/o error */
128 }
129 snd_ivtv_unlock(itvsc);
130
131 return ret;
132}
133
134
135/* This is a bit of overkill, the slider is already in dB internally */
136static DECLARE_TLV_DB_SCALE(snd_ivtv_mixer_tv_vol_db_scale, -9600, 100, 0);
137
138static struct snd_kcontrol_new snd_ivtv_mixer_tv_vol __initdata = {
139 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
140 .name = "Analog TV Capture Volume",
141 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
142 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
143 .info = snd_ivtv_mixer_tv_volume_info,
144 .get = snd_ivtv_mixer_tv_volume_get,
145 .put = snd_ivtv_mixer_tv_volume_put,
146 .tlv.p = snd_ivtv_mixer_tv_vol_db_scale
147};
148
149/* FIXME - add mute switch and balance, bass, treble sliders:
150 V4L2_CID_AUDIO_MUTE
151
152 V4L2_CID_AUDIO_BALANCE
153
154 V4L2_CID_AUDIO_BASS
155 V4L2_CID_AUDIO_TREBLE
156*/
157
158/* FIXME - add stereo, lang1, lang2, mono menu */
159/* FIXME - add I2S volume */
160
161int __init snd_ivtv_mixer_create(struct snd_ivtv_card *itvsc)
162{
163 struct v4l2_device *v4l2_dev = itvsc->v4l2_dev;
164 struct snd_card *sc = itvsc->sc;
165 int ret;
166
167 strlcpy(sc->mixername, "CX2341[56] Mixer", sizeof(sc->mixername));
168
169 ret = snd_ctl_add(sc, snd_ctl_new1(snd_ivtv_mixer_tv_vol, itvsc));
170 if (ret) {
171 IVTV_ALSA_WARN("%s: failed to add %s control, err %d\n",
172 __func__, snd_ivtv_mixer_tv_vol.name, ret);
173 }
174 return ret;
175}
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-mixer.h b/drivers/media/pci/ivtv/ivtv-alsa-mixer.h
new file mode 100644
index 000000000000..cdde36704d53
--- /dev/null
+++ b/drivers/media/pci/ivtv/ivtv-alsa-mixer.h
@@ -0,0 +1,23 @@
1/*
2 * ALSA mixer controls for the
3 * ALSA interface to ivtv PCM capture streams
4 *
5 * Copyright (C) 2009,2012 Andy Walls <awalls@md.metrocast.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23int __init snd_ivtv_mixer_create(struct snd_ivtv_card *itvsc);
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-pcm.c b/drivers/media/pci/ivtv/ivtv-alsa-pcm.c
new file mode 100644
index 000000000000..82c708e1df91
--- /dev/null
+++ b/drivers/media/pci/ivtv/ivtv-alsa-pcm.c
@@ -0,0 +1,357 @@
1/*
2 * ALSA PCM device for the
3 * ALSA interface to ivtv PCM capture streams
4 *
5 * Copyright (C) 2009,2012 Andy Walls <awalls@md.metrocast.net>
6 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
7 *
8 * Portions of this work were sponsored by ONELAN Limited for the cx18 driver
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307 USA
24 */
25
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/vmalloc.h>
29#include <linux/printk.h>
30
31#include <media/v4l2-device.h>
32
33#include <sound/core.h>
34#include <sound/pcm.h>
35
36#include "ivtv-driver.h"
37#include "ivtv-queue.h"
38#include "ivtv-streams.h"
39#include "ivtv-fileops.h"
40#include "ivtv-alsa.h"
41
42static unsigned int pcm_debug;
43module_param(pcm_debug, int, 0644);
44MODULE_PARM_DESC(pcm_debug, "enable debug messages for pcm");
45
46#define dprintk(fmt, arg...) \
47 do { \
48 if (pcm_debug) \
49 pr_info("ivtv-alsa-pcm %s: " fmt, __func__, ##arg); \
50 } while (0)
51
52static struct snd_pcm_hardware snd_ivtv_hw_capture = {
53 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
54 SNDRV_PCM_INFO_MMAP |
55 SNDRV_PCM_INFO_INTERLEAVED |
56 SNDRV_PCM_INFO_MMAP_VALID,
57
58 .formats = SNDRV_PCM_FMTBIT_S16_LE,
59
60 .rates = SNDRV_PCM_RATE_48000,
61
62 .rate_min = 48000,
63 .rate_max = 48000,
64 .channels_min = 2,
65 .channels_max = 2,
66 .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
67 .period_bytes_min = 64, /* 12544/2, */
68 .period_bytes_max = 12544,
69 .periods_min = 2,
70 .periods_max = 98, /* 12544, */
71};
72
73void ivtv_alsa_announce_pcm_data(struct snd_ivtv_card *itvsc, u8 *pcm_data,
74 size_t num_bytes)
75{
76 struct snd_pcm_substream *substream;
77 struct snd_pcm_runtime *runtime;
78 unsigned int oldptr;
79 unsigned int stride;
80 int period_elapsed = 0;
81 int length;
82
83 dprintk("ivtv alsa announce ptr=%p data=%p num_bytes=%zd\n", itvsc,
84 pcm_data, num_bytes);
85
86 substream = itvsc->capture_pcm_substream;
87 if (substream == NULL) {
88 dprintk("substream was NULL\n");
89 return;
90 }
91
92 runtime = substream->runtime;
93 if (runtime == NULL) {
94 dprintk("runtime was NULL\n");
95 return;
96 }
97
98 stride = runtime->frame_bits >> 3;
99 if (stride == 0) {
100 dprintk("stride is zero\n");
101 return;
102 }
103
104 length = num_bytes / stride;
105 if (length == 0) {
106 dprintk("%s: length was zero\n", __func__);
107 return;
108 }
109
110 if (runtime->dma_area == NULL) {
111 dprintk("dma area was NULL - ignoring\n");
112 return;
113 }
114
115 oldptr = itvsc->hwptr_done_capture;
116 if (oldptr + length >= runtime->buffer_size) {
117 unsigned int cnt =
118 runtime->buffer_size - oldptr;
119 memcpy(runtime->dma_area + oldptr * stride, pcm_data,
120 cnt * stride);
121 memcpy(runtime->dma_area, pcm_data + cnt * stride,
122 length * stride - cnt * stride);
123 } else {
124 memcpy(runtime->dma_area + oldptr * stride, pcm_data,
125 length * stride);
126 }
127 snd_pcm_stream_lock(substream);
128
129 itvsc->hwptr_done_capture += length;
130 if (itvsc->hwptr_done_capture >=
131 runtime->buffer_size)
132 itvsc->hwptr_done_capture -=
133 runtime->buffer_size;
134
135 itvsc->capture_transfer_done += length;
136 if (itvsc->capture_transfer_done >=
137 runtime->period_size) {
138 itvsc->capture_transfer_done -=
139 runtime->period_size;
140 period_elapsed = 1;
141 }
142
143 snd_pcm_stream_unlock(substream);
144
145 if (period_elapsed)
146 snd_pcm_period_elapsed(substream);
147}
148
149static int snd_ivtv_pcm_capture_open(struct snd_pcm_substream *substream)
150{
151 struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
152 struct snd_pcm_runtime *runtime = substream->runtime;
153 struct v4l2_device *v4l2_dev = itvsc->v4l2_dev;
154 struct ivtv *itv = to_ivtv(v4l2_dev);
155 struct ivtv_stream *s;
156 struct ivtv_open_id item;
157 int ret;
158
159 /* Instruct the CX2341[56] to start sending packets */
160 snd_ivtv_lock(itvsc);
161 s = &itv->streams[IVTV_ENC_STREAM_TYPE_PCM];
162
163 v4l2_fh_init(&item.fh, s->vdev);
164 item.itv = itv;
165 item.type = s->type;
166
167 /* See if the stream is available */
168 if (ivtv_claim_stream(&item, item.type)) {
169 /* No, it's already in use */
170 snd_ivtv_unlock(itvsc);
171 return -EBUSY;
172 }
173
174 if (test_bit(IVTV_F_S_STREAMOFF, &s->s_flags) ||
175 test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
176 /* We're already streaming. No additional action required */
177 snd_ivtv_unlock(itvsc);
178 return 0;
179 }
180
181
182 runtime->hw = snd_ivtv_hw_capture;
183 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
184 itvsc->capture_pcm_substream = substream;
185 runtime->private_data = itv;
186
187 itv->pcm_announce_callback = ivtv_alsa_announce_pcm_data;
188
189 /* Not currently streaming, so start it up */
190 set_bit(IVTV_F_S_STREAMING, &s->s_flags);
191 ret = ivtv_start_v4l2_encode_stream(s);
192 snd_ivtv_unlock(itvsc);
193
194 return ret;
195}
196
197static int snd_ivtv_pcm_capture_close(struct snd_pcm_substream *substream)
198{
199 struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
200 struct v4l2_device *v4l2_dev = itvsc->v4l2_dev;
201 struct ivtv *itv = to_ivtv(v4l2_dev);
202 struct ivtv_stream *s;
203
204 /* Instruct the ivtv to stop sending packets */
205 snd_ivtv_lock(itvsc);
206 s = &itv->streams[IVTV_ENC_STREAM_TYPE_PCM];
207 ivtv_stop_v4l2_encode_stream(s, 0);
208 clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
209
210 ivtv_release_stream(s);
211
212 itv->pcm_announce_callback = NULL;
213 snd_ivtv_unlock(itvsc);
214
215 return 0;
216}
217
218static int snd_ivtv_pcm_ioctl(struct snd_pcm_substream *substream,
219 unsigned int cmd, void *arg)
220{
221 struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
222 int ret;
223
224 snd_ivtv_lock(itvsc);
225 ret = snd_pcm_lib_ioctl(substream, cmd, arg);
226 snd_ivtv_unlock(itvsc);
227 return ret;
228}
229
230
231static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
232 size_t size)
233{
234 struct snd_pcm_runtime *runtime = subs->runtime;
235
236 dprintk("Allocating vbuffer\n");
237 if (runtime->dma_area) {
238 if (runtime->dma_bytes > size)
239 return 0;
240
241 vfree(runtime->dma_area);
242 }
243 runtime->dma_area = vmalloc(size);
244 if (!runtime->dma_area)
245 return -ENOMEM;
246
247 runtime->dma_bytes = size;
248
249 return 0;
250}
251
252static int snd_ivtv_pcm_hw_params(struct snd_pcm_substream *substream,
253 struct snd_pcm_hw_params *params)
254{
255 dprintk("%s called\n", __func__);
256
257 return snd_pcm_alloc_vmalloc_buffer(substream,
258 params_buffer_bytes(params));
259}
260
261static int snd_ivtv_pcm_hw_free(struct snd_pcm_substream *substream)
262{
263 struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
264 unsigned long flags;
265
266 spin_lock_irqsave(&itvsc->slock, flags);
267 if (substream->runtime->dma_area) {
268 dprintk("freeing pcm capture region\n");
269 vfree(substream->runtime->dma_area);
270 substream->runtime->dma_area = NULL;
271 }
272 spin_unlock_irqrestore(&itvsc->slock, flags);
273
274 return 0;
275}
276
277static int snd_ivtv_pcm_prepare(struct snd_pcm_substream *substream)
278{
279 struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
280
281 itvsc->hwptr_done_capture = 0;
282 itvsc->capture_transfer_done = 0;
283
284 return 0;
285}
286
287static int snd_ivtv_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
288{
289 return 0;
290}
291
292static
293snd_pcm_uframes_t snd_ivtv_pcm_pointer(struct snd_pcm_substream *substream)
294{
295 unsigned long flags;
296 snd_pcm_uframes_t hwptr_done;
297 struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
298
299 spin_lock_irqsave(&itvsc->slock, flags);
300 hwptr_done = itvsc->hwptr_done_capture;
301 spin_unlock_irqrestore(&itvsc->slock, flags);
302
303 return hwptr_done;
304}
305
306static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
307 unsigned long offset)
308{
309 void *pageptr = subs->runtime->dma_area + offset;
310
311 return vmalloc_to_page(pageptr);
312}
313
314static struct snd_pcm_ops snd_ivtv_pcm_capture_ops = {
315 .open = snd_ivtv_pcm_capture_open,
316 .close = snd_ivtv_pcm_capture_close,
317 .ioctl = snd_ivtv_pcm_ioctl,
318 .hw_params = snd_ivtv_pcm_hw_params,
319 .hw_free = snd_ivtv_pcm_hw_free,
320 .prepare = snd_ivtv_pcm_prepare,
321 .trigger = snd_ivtv_pcm_trigger,
322 .pointer = snd_ivtv_pcm_pointer,
323 .page = snd_pcm_get_vmalloc_page,
324};
325
326int snd_ivtv_pcm_create(struct snd_ivtv_card *itvsc)
327{
328 struct snd_pcm *sp;
329 struct snd_card *sc = itvsc->sc;
330 struct v4l2_device *v4l2_dev = itvsc->v4l2_dev;
331 struct ivtv *itv = to_ivtv(v4l2_dev);
332 int ret;
333
334 ret = snd_pcm_new(sc, "CX2341[56] PCM",
335 0, /* PCM device 0, the only one for this card */
336 0, /* 0 playback substreams */
337 1, /* 1 capture substream */
338 &sp);
339 if (ret) {
340 IVTV_ALSA_ERR("%s: snd_ivtv_pcm_create() failed with err %d\n",
341 __func__, ret);
342 goto err_exit;
343 }
344
345 spin_lock_init(&itvsc->slock);
346
347 snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_CAPTURE,
348 &snd_ivtv_pcm_capture_ops);
349 sp->info_flags = 0;
350 sp->private_data = itvsc;
351 strlcpy(sp->name, itv->card_name, sizeof(sp->name));
352
353 return 0;
354
355err_exit:
356 return ret;
357}
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-pcm.h b/drivers/media/pci/ivtv/ivtv-alsa-pcm.h
new file mode 100644
index 000000000000..5ab18319ea4d
--- /dev/null
+++ b/drivers/media/pci/ivtv/ivtv-alsa-pcm.h
@@ -0,0 +1,27 @@
1/*
2 * ALSA PCM device for the
3 * ALSA interface to ivtv PCM capture streams
4 *
5 * Copyright (C) 2009,2012 Andy Walls <awalls@md.metrocast.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23int __init snd_ivtv_pcm_create(struct snd_ivtv_card *itvsc);
24
25/* Used by ivtv driver to announce the PCM data to the module */
26void ivtv_alsa_announce_pcm_data(struct snd_ivtv_card *card, u8 *pcm_data,
27 size_t num_bytes);
diff --git a/drivers/media/pci/ivtv/ivtv-alsa.h b/drivers/media/pci/ivtv/ivtv-alsa.h
new file mode 100644
index 000000000000..4a0d8f2c254d
--- /dev/null
+++ b/drivers/media/pci/ivtv/ivtv-alsa.h
@@ -0,0 +1,75 @@
1/*
2 * ALSA interface to ivtv PCM capture streams
3 *
4 * Copyright (C) 2009,2012 Andy Walls <awalls@md.metrocast.net>
5 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23struct snd_card;
24
25struct snd_ivtv_card {
26 struct v4l2_device *v4l2_dev;
27 struct snd_card *sc;
28 unsigned int capture_transfer_done;
29 unsigned int hwptr_done_capture;
30 struct snd_pcm_substream *capture_pcm_substream;
31 spinlock_t slock;
32};
33
34extern int ivtv_alsa_debug;
35
36/*
37 * File operations that manipulate the encoder or video or audio subdevices
38 * need to be serialized. Use the same lock we use for v4l2 file ops.
39 */
40static inline void snd_ivtv_lock(struct snd_ivtv_card *itvsc)
41{
42 struct ivtv *itv = to_ivtv(itvsc->v4l2_dev);
43 mutex_lock(&itv->serialize_lock);
44}
45
46static inline void snd_ivtv_unlock(struct snd_ivtv_card *itvsc)
47{
48 struct ivtv *itv = to_ivtv(itvsc->v4l2_dev);
49 mutex_unlock(&itv->serialize_lock);
50}
51
52#define IVTV_ALSA_DBGFLG_WARN (1 << 0)
53#define IVTV_ALSA_DBGFLG_INFO (1 << 1)
54
55#define IVTV_ALSA_DEBUG(x, type, fmt, args...) \
56 do { \
57 if ((x) & ivtv_alsa_debug) \
58 pr_info("%s-alsa: " type ": " fmt, \
59 v4l2_dev->name , ## args); \
60 } while (0)
61
62#define IVTV_ALSA_DEBUG_WARN(fmt, args...) \
63 IVTV_ALSA_DEBUG(IVTV_ALSA_DBGFLG_WARN, "warning", fmt , ## args)
64
65#define IVTV_ALSA_DEBUG_INFO(fmt, args...) \
66 IVTV_ALSA_DEBUG(IVTV_ALSA_DBGFLG_INFO, "info", fmt , ## args)
67
68#define IVTV_ALSA_ERR(fmt, args...) \
69 pr_err("%s-alsa: " fmt, v4l2_dev->name , ## args)
70
71#define IVTV_ALSA_WARN(fmt, args...) \
72 pr_warn("%s-alsa: " fmt, v4l2_dev->name , ## args)
73
74#define IVTV_ALSA_INFO(fmt, args...) \
75 pr_info("%s-alsa: " fmt, v4l2_dev->name , ## args)
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index 5462ce2f60ea..eed95a396665 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -68,6 +68,10 @@
68 setting this to 1 you ensure that radio0 is now also radio1. */ 68 setting this to 1 you ensure that radio0 is now also radio1. */
69int ivtv_first_minor; 69int ivtv_first_minor;
70 70
71/* Callback for registering extensions */
72int (*ivtv_ext_init)(struct ivtv *);
73EXPORT_SYMBOL(ivtv_ext_init);
74
71/* add your revision and whatnot here */ 75/* add your revision and whatnot here */
72static struct pci_device_id ivtv_pci_tbl[] __devinitdata = { 76static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
73 {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV15, 77 {PCI_VENDOR_ID_ICOMP, PCI_DEVICE_ID_IVTV15,
@@ -279,6 +283,34 @@ MODULE_LICENSE("GPL");
279 283
280MODULE_VERSION(IVTV_VERSION); 284MODULE_VERSION(IVTV_VERSION);
281 285
286#if defined(CONFIG_MODULES) && defined(MODULE)
287static void request_module_async(struct work_struct *work)
288{
289 struct ivtv *dev = container_of(work, struct ivtv, request_module_wk);
290
291 /* Make sure ivtv-alsa module is loaded */
292 request_module("ivtv-alsa");
293
294 /* Initialize ivtv-alsa for this instance of the cx18 device */
295 if (ivtv_ext_init != NULL)
296 ivtv_ext_init(dev);
297}
298
299static void request_modules(struct ivtv *dev)
300{
301 INIT_WORK(&dev->request_module_wk, request_module_async);
302 schedule_work(&dev->request_module_wk);
303}
304
305static void flush_request_modules(struct ivtv *dev)
306{
307 flush_work_sync(&dev->request_module_wk);
308}
309#else
310#define request_modules(dev)
311#define flush_request_modules(dev)
312#endif /* CONFIG_MODULES */
313
282void ivtv_clear_irq_mask(struct ivtv *itv, u32 mask) 314void ivtv_clear_irq_mask(struct ivtv *itv, u32 mask)
283{ 315{
284 itv->irqmask &= ~mask; 316 itv->irqmask &= ~mask;
@@ -1253,6 +1285,9 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1253 goto free_streams; 1285 goto free_streams;
1254 } 1286 }
1255 IVTV_INFO("Initialized card: %s\n", itv->card_name); 1287 IVTV_INFO("Initialized card: %s\n", itv->card_name);
1288
1289 /* Load ivtv submodules (ivtv-alsa) */
1290 request_modules(itv);
1256 return 0; 1291 return 0;
1257 1292
1258free_streams: 1293free_streams:
@@ -1380,6 +1415,8 @@ static void ivtv_remove(struct pci_dev *pdev)
1380 1415
1381 IVTV_DEBUG_INFO("Removing card\n"); 1416 IVTV_DEBUG_INFO("Removing card\n");
1382 1417
1418 flush_request_modules(itv);
1419
1383 if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) { 1420 if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) {
1384 /* Stop all captures */ 1421 /* Stop all captures */
1385 IVTV_DEBUG_INFO("Stopping all streams\n"); 1422 IVTV_DEBUG_INFO("Stopping all streams\n");
diff --git a/drivers/media/pci/ivtv/ivtv-driver.h b/drivers/media/pci/ivtv/ivtv-driver.h
index a7e00f8938f8..1918e7326795 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.h
+++ b/drivers/media/pci/ivtv/ivtv-driver.h
@@ -669,6 +669,13 @@ struct ivtv {
669 atomic_t capturing; /* count number of active capture streams */ 669 atomic_t capturing; /* count number of active capture streams */
670 atomic_t decoding; /* count number of active decoding streams */ 670 atomic_t decoding; /* count number of active decoding streams */
671 671
672 /* ALSA interface for PCM capture stream */
673 struct snd_ivtv_card *alsa;
674 void (*pcm_announce_callback)(struct snd_ivtv_card *card, u8 *pcm_data,
675 size_t num_bytes);
676
677 /* Used for ivtv-alsa module loading */
678 struct work_struct request_module_wk;
672 679
673 /* Interrupts & DMA */ 680 /* Interrupts & DMA */
674 u32 irqmask; /* active interrupts */ 681 u32 irqmask; /* active interrupts */
@@ -752,6 +759,9 @@ static inline struct ivtv *to_ivtv(struct v4l2_device *v4l2_dev)
752 return container_of(v4l2_dev, struct ivtv, v4l2_dev); 759 return container_of(v4l2_dev, struct ivtv, v4l2_dev);
753} 760}
754 761
762/* ivtv extensions to be loaded */
763extern int (*ivtv_ext_init)(struct ivtv *);
764
755/* Globals */ 765/* Globals */
756extern int ivtv_first_minor; 766extern int ivtv_first_minor;
757 767
diff --git a/drivers/media/pci/ivtv/ivtv-fileops.c b/drivers/media/pci/ivtv/ivtv-fileops.c
index 88bce907cdef..7f2eb5f62fd1 100644
--- a/drivers/media/pci/ivtv/ivtv-fileops.c
+++ b/drivers/media/pci/ivtv/ivtv-fileops.c
@@ -41,7 +41,7 @@
41 associated VBI streams are also automatically claimed. 41 associated VBI streams are also automatically claimed.
42 Possible error returns: -EBUSY if someone else has claimed 42 Possible error returns: -EBUSY if someone else has claimed
43 the stream or 0 on success. */ 43 the stream or 0 on success. */
44static int ivtv_claim_stream(struct ivtv_open_id *id, int type) 44int ivtv_claim_stream(struct ivtv_open_id *id, int type)
45{ 45{
46 struct ivtv *itv = id->itv; 46 struct ivtv *itv = id->itv;
47 struct ivtv_stream *s = &itv->streams[type]; 47 struct ivtv_stream *s = &itv->streams[type];
@@ -96,6 +96,7 @@ static int ivtv_claim_stream(struct ivtv_open_id *id, int type)
96 set_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags); 96 set_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags);
97 return 0; 97 return 0;
98} 98}
99EXPORT_SYMBOL(ivtv_claim_stream);
99 100
100/* This function releases a previously claimed stream. It will take into 101/* This function releases a previously claimed stream. It will take into
101 account associated VBI streams. */ 102 account associated VBI streams. */
@@ -146,6 +147,7 @@ void ivtv_release_stream(struct ivtv_stream *s)
146 clear_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags); 147 clear_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags);
147 ivtv_flush_queues(s_vbi); 148 ivtv_flush_queues(s_vbi);
148} 149}
150EXPORT_SYMBOL(ivtv_release_stream);
149 151
150static void ivtv_dualwatch(struct ivtv *itv) 152static void ivtv_dualwatch(struct ivtv *itv)
151{ 153{
diff --git a/drivers/media/pci/ivtv/ivtv-fileops.h b/drivers/media/pci/ivtv/ivtv-fileops.h
index 049a2923965d..5e08800772ca 100644
--- a/drivers/media/pci/ivtv/ivtv-fileops.h
+++ b/drivers/media/pci/ivtv/ivtv-fileops.h
@@ -37,8 +37,8 @@ void ivtv_mute(struct ivtv *itv);
37void ivtv_unmute(struct ivtv *itv); 37void ivtv_unmute(struct ivtv *itv);
38 38
39/* Utilities */ 39/* Utilities */
40 40/* Shared with ivtv-alsa module */
41/* Release a previously claimed stream. */ 41int ivtv_claim_stream(struct ivtv_open_id *id, int type);
42void ivtv_release_stream(struct ivtv_stream *s); 42void ivtv_release_stream(struct ivtv_stream *s);
43 43
44#endif 44#endif
diff --git a/drivers/media/pci/ivtv/ivtv-streams.c b/drivers/media/pci/ivtv/ivtv-streams.c
index f08ec17cc3dc..ea6135203f58 100644
--- a/drivers/media/pci/ivtv/ivtv-streams.c
+++ b/drivers/media/pci/ivtv/ivtv-streams.c
@@ -629,6 +629,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
629 atomic_inc(&itv->capturing); 629 atomic_inc(&itv->capturing);
630 return 0; 630 return 0;
631} 631}
632EXPORT_SYMBOL(ivtv_start_v4l2_encode_stream);
632 633
633static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s) 634static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
634{ 635{
@@ -885,6 +886,7 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
885 886
886 return 0; 887 return 0;
887} 888}
889EXPORT_SYMBOL(ivtv_stop_v4l2_encode_stream);
888 890
889int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts) 891int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
890{ 892{