aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarin Mitov <mitov@issp.bas.bg>2010-05-18 06:05:29 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-18 17:53:17 -0400
commita57941c2e7a79d5143a63c06c06be36f786d5241 (patch)
tree913d323540a388db6fd34453d4beca19978b7544
parentabfc768d9e374dc30b98206aff99d790e36d06dd (diff)
Staging: dt3155v4l: remove private memory allocator
This patch removes the private memory allocator and all conjugated functions. Now the driver uses videobuf-dma-contig module for allocations. Added reserving 4MB coherent memory for private per device allocations at probe time. Signed-off-by: Marin Mitov <mitov@issp.bas.bg> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/dt3155v4l/Kconfig2
-rw-r--r--drivers/staging/dt3155v4l/Makefile5
-rw-r--r--drivers/staging/dt3155v4l/dt3155-bufs.c256
-rw-r--r--drivers/staging/dt3155v4l/dt3155-bufs.h88
-rw-r--r--drivers/staging/dt3155v4l/dt3155v4l.c603
-rw-r--r--drivers/staging/dt3155v4l/dt3155v4l.h4
6 files changed, 107 insertions, 851 deletions
diff --git a/drivers/staging/dt3155v4l/Kconfig b/drivers/staging/dt3155v4l/Kconfig
index f49f4ac035b0..5cd5a575b64d 100644
--- a/drivers/staging/dt3155v4l/Kconfig
+++ b/drivers/staging/dt3155v4l/Kconfig
@@ -9,7 +9,7 @@ config VIDEO_DT3155
9 In doubt, say N. 9 In doubt, say N.
10 10
11 To compile this driver as a module, choose M here: the 11 To compile this driver as a module, choose M here: the
12 module will be called dt3155_v4l. 12 module will be called dt3155v4l.
13 13
14config DT3155_CCIR 14config DT3155_CCIR
15 bool "Selects CCIR/50Hz vertical refresh" 15 bool "Selects CCIR/50Hz vertical refresh"
diff --git a/drivers/staging/dt3155v4l/Makefile b/drivers/staging/dt3155v4l/Makefile
index 3a207ccd3143..ce7a3ec2faf3 100644
--- a/drivers/staging/dt3155v4l/Makefile
+++ b/drivers/staging/dt3155v4l/Makefile
@@ -1,4 +1 @@
1obj-$(CONFIG_VIDEO_DT3155) += dt3155_v4l.o obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l.o
2dt3155_v4l-objs := \
3 dt3155-bufs.o \
4 dt3155v4l.o
diff --git a/drivers/staging/dt3155v4l/dt3155-bufs.c b/drivers/staging/dt3155v4l/dt3155-bufs.c
deleted file mode 100644
index f93e431e786b..000000000000
--- a/drivers/staging/dt3155v4l/dt3155-bufs.c
+++ /dev/null
@@ -1,256 +0,0 @@
1/***************************************************************************
2 * Copyright (C) 2006-2010 by Marin Mitov *
3 * mitov@issp.bas.bg *
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 as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#include "dt3155-bufs.h"
22
23/**
24 * dt3155_init_chunks_buf - creates a chunk buffer and allocates memory for it
25 *
26 * returns: a pointer to the struct dt3155_buf or NULL if failed
27 *
28 * Creates a struct dt3155_buf, then allocates a chunk of memory of
29 * size DT3155_CHUNK_SIZE and sets all the pages in it as Reserved.
30 * This is done to be able to use remap_pfn_range() on these buffers
31 * (which do not work on normal memory if Reserved bit is not set)
32 */
33struct dt3155_buf *
34dt3155_init_chunks_buf(void)
35{ /* could sleep */
36 struct dt3155_buf *buf;
37 int i;
38
39 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
40 if (!buf)
41 return NULL;
42 buf->cpu = (void *)__get_free_pages(DT3155_CHUNK_FLAGS,
43 get_order(DT3155_CHUNK_SIZE));
44 if (!buf->cpu) {
45 kfree(buf);
46 return NULL;
47 }
48 for (i = 0; i < DT3155_CHUNK_SIZE; i += PAGE_SIZE)
49 SetPageReserved(virt_to_page(buf->cpu + i));
50 return buf; /* success */
51}
52
53/**
54 * dt3155_free_chunks_buf - destroys the specified buffer
55 *
56 * @buf: the buffer to be freed
57 *
58 * Clears Reserved bit of all pages in the chunk, frees the chunk memory
59 * and destroys struct dt3155_buf.
60 */
61void
62dt3155_free_chunks_buf(struct dt3155_buf *buf)
63{
64 int i;
65
66 for (i = 0; i < DT3155_CHUNK_SIZE; i += PAGE_SIZE)
67 ClearPageReserved(virt_to_page(buf->cpu + i));
68 free_pages((unsigned long)buf->cpu, get_order(DT3155_CHUNK_SIZE));
69 kfree(buf);
70}
71
72/**
73 * dt3155_init_fifo - creates and initializes a fifo
74 *
75 * returns: a pointer to the crated and initialized struct dt3155_fifo
76 * or NULL if failed
77 */
78struct dt3155_fifo *
79dt3155_init_fifo(void)
80{ /* could sleep */
81 struct dt3155_fifo *fifo = kzalloc(sizeof(*fifo), GFP_KERNEL);
82 if (fifo)
83 spin_lock_init(&fifo->lock);
84 return fifo;
85}
86
87/* dt3155_free_fifo(x) defined as macro in dt3155.h */
88
89/**
90 * dt3155_get_buf - gets a buffer from the fifo
91 *
92 * @fifo: the fifo to get a buffer from
93 *
94 * returns: a pointer to the buffer or NULL if failed
95 *
96 * dt3155_get_buf gets the fifo's spin_lock and returns the
97 * buffer pointed by the head. Could be used in any context.
98 */
99struct dt3155_buf *
100dt3155_get_buf(struct dt3155_fifo *fifo)
101{
102 unsigned long flags;
103 struct dt3155_buf *tmp_buf;
104
105 spin_lock_irqsave(&fifo->lock, flags);
106 tmp_buf = fifo->head;
107 if (fifo->head)
108 fifo->head = fifo->head->next;
109 if (!fifo->head)
110 fifo->tail = NULL;
111 spin_unlock_irqrestore(&fifo->lock, flags);
112 return tmp_buf;
113}
114
115/**
116 * dt3155_put_buf - puts a buffer into a fifo
117 *
118 * @buf: the buffer to put
119 * @fifo: the fifo to put the buffer in
120 *
121 * dt3155_put_buf gets the fifo's spin_lock and puts the buf
122 * at the tail of the fifo. Could be used in any context.
123 */
124void
125dt3155_put_buf(struct dt3155_buf *buf, struct dt3155_fifo *fifo)
126{
127 unsigned long flags;
128
129 spin_lock_irqsave(&fifo->lock, flags);
130 buf->next = NULL;
131 if (fifo->tail)
132 fifo->tail->next = buf;
133 fifo->tail = buf;
134 if (!fifo->head)
135 fifo->head = buf;
136 spin_unlock_irqrestore(&fifo->lock, flags);
137}
138
139/**
140 * dt3155_init_chunks_fifo - creates and fills a chunks_fifo
141 *
142 * returns: a pointer to the fifo or NULL if failed
143 *
144 * dt3155_init_chunks_fifo creates and fills the fifo with
145 * a number of chunks <= DT3155_CHUNK_NUM. The returned fifo
146 * contains at least one chunk.
147 */
148struct dt3155_fifo *
149dt3155_init_chunks_fifo(void)
150{ /* could sleep */
151 int i;
152
153 struct dt3155_fifo *chunks;
154 struct dt3155_buf *tmp_buf;
155
156 chunks = dt3155_init_fifo();
157 if (!chunks)
158 return NULL;
159 tmp_buf = dt3155_init_chunks_buf();
160 if (!tmp_buf) {
161 dt3155_free_fifo(chunks);
162 return NULL;
163 }
164 dt3155_put_buf(tmp_buf, chunks);
165 for (i = 1; i < DT3155_CHUNK_NUM; i++) {
166 tmp_buf = dt3155_init_chunks_buf();
167 if (!tmp_buf)
168 break;
169 dt3155_put_buf(tmp_buf, chunks);
170 }
171 return chunks;
172}
173
174/**
175 * dt3155_free_chunks_fifo - empties and destroys the chunks_fifo
176 *
177 * @chunks: the chunks_fifo to be freed
178 *
179 * dt3155_free_chunks_fifo deallocates all chunks in the fifo and
180 * destroys it.
181 */
182void
183dt3155_free_chunks_fifo(struct dt3155_fifo *chunks)
184{
185 int buf_count = 0;
186 struct dt3155_buf *buf;
187
188 while ((buf = dt3155_get_buf(chunks))) {
189 dt3155_free_chunks_buf(buf);
190 buf_count++;
191 }
192 dt3155_free_fifo(chunks);
193 printk(KERN_INFO "dt3155: %i chunks freed\n", buf_count);
194}
195
196/**
197 * dt3155_init_ibufs_fifo - creates and fills an image buffer fifo
198 *
199 * @chunks: chunks_fifo to take memory from
200 * @buf_size: the size of image buffers
201 *
202 * returns: a pointer to the fifo filled with image buffers
203 *
204 * dt3155_init_ibufs_fifo takes chunks from chunks_fifo, chops them
205 * into pieces of size buf_size and fills image fifo with them.
206 */
207struct dt3155_fifo *
208dt3155_init_ibufs_fifo(struct dt3155_fifo *chunks, int buf_size)
209{ /* could sleep */
210 int i, buf_count = 0;
211 struct dt3155_buf *tmp_ibuf, *chunks_buf, *last_chunk;
212 struct dt3155_fifo *tmp_fifo;
213
214 tmp_fifo = dt3155_init_fifo();
215 if (!tmp_fifo)
216 return NULL;
217 last_chunk = chunks->tail;
218 do {
219 chunks_buf = dt3155_get_buf(chunks);
220 dt3155_put_buf(chunks_buf, chunks);
221 for (i = 0; i < DT3155_CHUNK_SIZE / buf_size; i++) {
222 tmp_ibuf = kzalloc(sizeof(*tmp_ibuf), GFP_KERNEL);
223 if (tmp_ibuf) {
224 tmp_ibuf->cpu =
225 chunks_buf->cpu + DT3155_BUF_SIZE * i;
226 dt3155_put_buf(tmp_ibuf, tmp_fifo);
227 buf_count++;
228 } else {
229 if (buf_count) {
230 goto print_num_bufs;
231 } else {
232 dt3155_free_fifo(tmp_fifo);
233 return NULL;
234 }
235 }
236 }
237 } while (chunks_buf != last_chunk);
238print_num_bufs:
239 printk(KERN_INFO "dt3155: %i image buffers available\n", buf_count);
240 return tmp_fifo;
241}
242
243/**
244 * dt3155_free_ibufs_fifo - empties and destroys an image fifo
245 *
246 * @fifo: the fifo to free
247 */
248void
249dt3155_free_ibufs_fifo(struct dt3155_fifo *fifo)
250{
251 struct dt3155_buf *tmp_ibuf;
252
253 while ((tmp_ibuf = dt3155_get_buf(fifo)))
254 kfree(tmp_ibuf);
255 kfree(fifo);
256}
diff --git a/drivers/staging/dt3155v4l/dt3155-bufs.h b/drivers/staging/dt3155v4l/dt3155-bufs.h
deleted file mode 100644
index db6d387231b2..000000000000
--- a/drivers/staging/dt3155v4l/dt3155-bufs.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/***************************************************************************
2 * Copyright (C) 2006-2010 by Marin Mitov *
3 * mitov@issp.bas.bg *
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 as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#ifndef _DT3155_BUFS_H_
22#define _DT3155_BUFS_H_
23
24#include <linux/pci.h>
25
26/* 4 chunks of 4MB, 9 buffers each = 36 buffers (> VIDEO_MAX_FRAME) */
27#define DT3155_CHUNK_NUM 4
28
29/* DT3155_CHUNK_SIZE should be 4M (2^22) or less, but more than image size */
30#define DT3155_CHUNK_SIZE (1U << 22)
31#define DT3155_CHUNK_FLAGS (GFP_KERNEL | GFP_DMA32 | __GFP_COLD | __GFP_NOWARN)
32
33/* DT3155_BUF_SIZE = 108 * PAGE_SIZE, so each buf is PAGE_SIZE alligned */
34#define DT3155_BUF_SIZE (768 * 576)
35
36/**
37 * struct dt3155_buf - image buffer structure
38 *
39 * @cpu: virtual kernel address of the buffer
40 * @dma: dma (bus) address of the buffer
41 * @next: pointer to the next buffer in the fifo
42 * @tv: time value when the image has been acquired
43 */
44struct dt3155_buf {
45 void *cpu;
46 dma_addr_t dma;
47 struct dt3155_buf *next;
48 struct timeval tv;
49};
50
51/**
52 * struct dt3155_fifo - fifo structure
53 *
54 * @head: pointer to the head of the fifo
55 * @tail: pionter to the tail of the fifo
56 * @lock: spin_lock to protect the fifo
57 */
58struct dt3155_fifo {
59 struct dt3155_buf *head;
60 struct dt3155_buf *tail;
61 spinlock_t lock;
62};
63
64struct dt3155_buf * __must_check
65dt3155_init_chunks_buf(void);
66void
67dt3155_free_chunks_buf(struct dt3155_buf *buf);
68
69struct dt3155_fifo * __must_check
70dt3155_init_fifo(void);
71#define dt3155_free_fifo(x) kfree(x)
72
73struct dt3155_buf * __must_check
74dt3155_get_buf(struct dt3155_fifo *fifo);
75void
76dt3155_put_buf(struct dt3155_buf *buf, struct dt3155_fifo *fifo);
77
78struct dt3155_fifo * __must_check
79dt3155_init_chunks_fifo(void);
80void
81dt3155_free_chunks_fifo(struct dt3155_fifo *chunks);
82
83struct dt3155_fifo * __must_check
84dt3155_init_ibufs_fifo(struct dt3155_fifo *chunks, int buf_size);
85void
86dt3155_free_ibufs_fifo(struct dt3155_fifo *fifo);
87
88#endif /* _DT3155_BUFS_H_ */
diff --git a/drivers/staging/dt3155v4l/dt3155v4l.c b/drivers/staging/dt3155v4l/dt3155v4l.c
index 308fb45965b3..6dc3af622848 100644
--- a/drivers/staging/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/dt3155v4l/dt3155v4l.c
@@ -18,22 +18,26 @@
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/ 19 ***************************************************************************/
20 20
21#include <media/v4l2-dev.h>
22#include <media/videobuf-core.h>
23#include <media/v4l2-ioctl.h>
24#include <linux/pci.h>
25#include <linux/version.h> 21#include <linux/version.h>
26#include <linux/stringify.h> 22#include <linux/stringify.h>
27#include <linux/delay.h> 23#include <linux/delay.h>
28#include <media/videobuf-dma-contig.h>
29#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <media/v4l2-dev.h>
26#include <media/v4l2-ioctl.h>
27#include <media/videobuf-dma-contig.h>
30 28
31#include "dt3155v4l.h" 29#include "dt3155v4l.h"
32#include "dt3155-bufs.h"
33 30
34#define DT3155_VENDOR_ID 0x8086 31#define DT3155_VENDOR_ID 0x8086
35#define DT3155_DEVICE_ID 0x1223 32#define DT3155_DEVICE_ID 0x1223
36 33
34/* DT3155_CHUNK_SIZE is 4M (2^22) 8 full size buffers */
35#define DT3155_CHUNK_SIZE (1U << 22)
36
37#define DT3155_COH_FLAGS (GFP_KERNEL | GFP_DMA32 | __GFP_COLD | __GFP_NOWARN)
38
39#define DT3155_BUF_SIZE (768 * 576)
40
37/* global initializers (for all boards) */ 41/* global initializers (for all boards) */
38#ifdef CONFIG_DT3155_CCIR 42#ifdef CONFIG_DT3155_CCIR
39static const u8 csr2_init = VT_50HZ; 43static const u8 csr2_init = VT_50HZ;
@@ -190,441 +194,6 @@ static int wait_i2c_reg(void __iomem *addr)
190 return 0; 194 return 0;
191} 195}
192 196
193/*
194 * global pointers to a list of 4MB chunks reserved at driver
195 * load, broken down to contiguous buffers of 768 * 576 bytes
196 * each to form a pool of buffers for allocations
197 * FIXME: add spinlock to protect moves between alloc/free lists
198 */
199static struct dt3155_fifo *dt3155_chunks; /* list of 4MB chuncks */
200static struct dt3155_fifo *dt3155_free_bufs; /* list of free buffers */
201static struct dt3155_fifo *dt3155_alloc_bufs; /* list of allocated buffers */
202
203/* same as in <drivers/media/video/videobuf-dma-contig.c> */
204struct videobuf_dma_contig_memory {
205 u32 magic;
206 void *vaddr;
207 dma_addr_t dma_handle;
208 unsigned long size;
209 int is_userptr;
210};
211
212#define MAGIC_DC_MEM 0x0733ac61
213#define MAGIC_CHECK(is, should) \
214 if (unlikely((is) != (should))) { \
215 pr_err("magic mismatch: %x expected %x\n", (is), (should)); \
216 BUG(); \
217 }
218
219/* helper functions to allocate/free buffers from the pool */
220static void *
221dt3155_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle,
222 gfp_t flag)
223{
224 struct dt3155_buf *buf;
225
226 if (size > DT3155_BUF_SIZE)
227 return NULL;
228 size = DT3155_BUF_SIZE; /* same for CCIR & RS-170 */
229 buf = dt3155_get_buf(dt3155_free_bufs);
230 if (!buf)
231 return NULL;
232 buf->dma = dma_map_single(dev, buf->cpu, size, DMA_FROM_DEVICE);
233 if (dma_mapping_error(dev, buf->dma)) {
234 dt3155_put_buf(buf, dt3155_free_bufs);
235 return NULL;
236 }
237 dt3155_put_buf(buf, dt3155_alloc_bufs);
238 *dma_handle = buf->dma;
239 return buf->cpu;
240}
241
242static void
243dt3155_free_buffer(struct device *dev, size_t size, void *cpu_addr,
244 dma_addr_t dma_handle)
245{
246 struct dt3155_buf *buf, *last;
247 int found = 0;
248
249 if (!cpu_addr) /* to free NULL is OK */
250 return;
251 last = dt3155_get_buf(dt3155_alloc_bufs);
252 if (!last) {
253 printk(KERN_ERR "dt3155: %s(): no alloc buffers\n", __func__);
254 return;
255 }
256 dt3155_put_buf(last, dt3155_alloc_bufs);
257 do {
258 buf = dt3155_get_buf(dt3155_alloc_bufs);
259 if (buf->cpu == cpu_addr && buf->dma == dma_handle) {
260 found = 1;
261 break;
262 }
263 dt3155_put_buf(buf, dt3155_alloc_bufs);
264 } while (buf != last);
265 if (!found) {
266 printk(KERN_ERR "dt3155: %s(): buffer not found\n", __func__);
267 return;
268 }
269 size = DT3155_BUF_SIZE; /* same for CCIR & RS-170 */
270 dma_unmap_single(dev, dma_handle, size, DMA_FROM_DEVICE);
271 dt3155_put_buf(buf, dt3155_free_bufs);
272}
273
274/* same as videobuf_dma_contig_user_get() */
275static int
276dt3155_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
277 struct videobuf_buffer *vb)
278{
279 struct mm_struct *mm = current->mm;
280 struct vm_area_struct *vma;
281 unsigned long prev_pfn, this_pfn;
282 unsigned long pages_done, user_address;
283 unsigned int offset;
284 int ret;
285
286 offset = vb->baddr & ~PAGE_MASK;
287 mem->size = PAGE_ALIGN(vb->size + offset);
288 mem->is_userptr = 0;
289 ret = -EINVAL;
290
291 down_read(&mm->mmap_sem);
292
293 vma = find_vma(mm, vb->baddr);
294 if (!vma)
295 goto out_up;
296
297 if ((vb->baddr + mem->size) > vma->vm_end)
298 goto out_up;
299
300 pages_done = 0;
301 prev_pfn = 0; /* kill warning */
302 user_address = vb->baddr;
303
304 while (pages_done < (mem->size >> PAGE_SHIFT)) {
305 ret = follow_pfn(vma, user_address, &this_pfn);
306 if (ret)
307 break;
308
309 if (pages_done == 0)
310 mem->dma_handle = (this_pfn << PAGE_SHIFT) + offset;
311 else if (this_pfn != (prev_pfn + 1))
312 ret = -EFAULT;
313
314 if (ret)
315 break;
316
317 prev_pfn = this_pfn;
318 user_address += PAGE_SIZE;
319 pages_done++;
320 }
321
322 if (!ret)
323 mem->is_userptr = 1;
324
325 out_up:
326 up_read(&current->mm->mmap_sem);
327
328 return ret;
329}
330
331/* same as videobuf_dma_contig_user_put() */
332static void
333dt3155_dma_contig_user_put(struct videobuf_dma_contig_memory *mem)
334{
335 mem->is_userptr = 0;
336 mem->dma_handle = 0;
337 mem->size = 0;
338}
339
340/* same as videobuf_iolock() but uses allocations from the pool */
341static int
342dt3155_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
343 struct v4l2_framebuffer *fbuf)
344{
345 struct videobuf_dma_contig_memory *mem = vb->priv;
346
347 BUG_ON(!mem);
348 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
349
350 switch (vb->memory) {
351 case V4L2_MEMORY_MMAP:
352 dev_dbg(q->dev, "%s memory method MMAP\n", __func__);
353
354 /* All handling should be done by __videobuf_mmap_mapper() */
355 if (!mem->vaddr) {
356 dev_err(q->dev, "memory is not alloced/mmapped.\n");
357 return -EINVAL;
358 }
359 break;
360 case V4L2_MEMORY_USERPTR:
361 dev_dbg(q->dev, "%s memory method USERPTR\n", __func__);
362
363 /* handle pointer from user space */
364 if (vb->baddr)
365 return dt3155_dma_contig_user_get(mem, vb);
366
367 /* allocate memory for the read() method */
368 mem->size = PAGE_ALIGN(vb->size);
369 mem->vaddr = dt3155_alloc_buffer(q->dev, mem->size,
370 &mem->dma_handle, GFP_KERNEL);
371 if (!mem->vaddr) {
372 dev_err(q->dev, "dma_alloc_coherent %ld failed\n",
373 mem->size);
374 return -ENOMEM;
375 }
376
377 dev_dbg(q->dev, "dma_alloc_coherent data is at %p (%ld)\n",
378 mem->vaddr, mem->size);
379 break;
380 case V4L2_MEMORY_OVERLAY:
381 default:
382 dev_dbg(q->dev, "%s memory method OVERLAY/unknown\n",
383 __func__);
384 return -EINVAL;
385 }
386
387 return 0;
388}
389
390/* same as videobuf_dma_contig_free() but uses the pool */
391void
392dt3155_dma_contig_free(struct videobuf_queue *q, struct videobuf_buffer *buf)
393{
394 struct videobuf_dma_contig_memory *mem = buf->priv;
395
396 /* mmapped memory can't be freed here, otherwise mmapped region
397 would be released, while still needed. In this case, the memory
398 release should happen inside videobuf_vm_close().
399 So, it should free memory only if the memory were allocated for
400 read() operation.
401 */
402 if (buf->memory != V4L2_MEMORY_USERPTR)
403 return;
404
405 if (!mem)
406 return;
407
408 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
409
410 /* handle user space pointer case */
411 if (buf->baddr) {
412 dt3155_dma_contig_user_put(mem);
413 return;
414 }
415
416 /* read() method */
417 dt3155_free_buffer(q->dev, mem->size, mem->vaddr, mem->dma_handle);
418 mem->vaddr = NULL;
419}
420
421/* same as videobuf_vm_open() */
422static void
423dt3155_vm_open(struct vm_area_struct *vma)
424{
425 struct videobuf_mapping *map = vma->vm_private_data;
426
427 dev_dbg(map->q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n",
428 map, map->count, vma->vm_start, vma->vm_end);
429
430 map->count++;
431}
432
433/* same as videobuf_vm_close(), but free to the pool */
434static void
435dt3155_vm_close(struct vm_area_struct *vma)
436{
437 struct videobuf_mapping *map = vma->vm_private_data;
438 struct videobuf_queue *q = map->q;
439 int i;
440
441 dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
442 map, map->count, vma->vm_start, vma->vm_end);
443
444 map->count--;
445 if (0 == map->count) {
446 struct videobuf_dma_contig_memory *mem;
447
448 dev_dbg(q->dev, "munmap %p q=%p\n", map, q);
449 mutex_lock(&q->vb_lock);
450
451 /* We need first to cancel streams, before unmapping */
452 if (q->streaming)
453 videobuf_queue_cancel(q);
454
455 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
456 if (NULL == q->bufs[i])
457 continue;
458
459 if (q->bufs[i]->map != map)
460 continue;
461
462 mem = q->bufs[i]->priv;
463 if (mem) {
464 /* This callback is called only if kernel has
465 allocated memory and this memory is mmapped.
466 In this case, memory should be freed,
467 in order to do memory unmap.
468 */
469
470 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
471
472 /* vfree is not atomic - can't be
473 called with IRQ's disabled
474 */
475 dev_dbg(q->dev, "buf[%d] freeing %p\n",
476 i, mem->vaddr);
477
478 dt3155_free_buffer(q->dev, mem->size,
479 mem->vaddr, mem->dma_handle);
480 mem->vaddr = NULL;
481 }
482
483 q->bufs[i]->map = NULL;
484 q->bufs[i]->baddr = 0;
485 }
486
487 kfree(map);
488
489 mutex_unlock(&q->vb_lock);
490 }
491}
492
493static const struct vm_operations_struct dt3155_vm_ops = {
494 .open = dt3155_vm_open,
495 .close = dt3155_vm_close,
496};
497
498/* same as videobuf_mmap_mapper(), but allocates from the pool */
499static int
500dt3155_mmap_mapper(struct videobuf_queue *q, struct videobuf_buffer *buf,
501 struct vm_area_struct *vma)
502{
503 struct videobuf_dma_contig_memory *mem;
504 struct videobuf_mapping *map;
505 int retval;
506 unsigned long size;
507
508 dev_dbg(q->dev, "%s\n", __func__);
509
510 /* create mapping + update buffer list */
511 map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
512 if (!map)
513 return -ENOMEM;
514
515 buf->map = map;
516 map->start = vma->vm_start;
517 map->end = vma->vm_end;
518 map->q = q;
519
520 buf->baddr = vma->vm_start;
521
522 mem = buf->priv;
523 BUG_ON(!mem);
524 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
525
526 mem->size = PAGE_ALIGN(buf->bsize);
527 mem->vaddr = dt3155_alloc_buffer(q->dev, mem->size,
528 &mem->dma_handle, GFP_KERNEL);
529 if (!mem->vaddr) {
530 dev_err(q->dev, "dma_alloc_coherent size %ld failed\n",
531 mem->size);
532 goto error;
533 }
534 dev_dbg(q->dev, "dma_alloc_coherent data is at addr %p (size %ld)\n",
535 mem->vaddr, mem->size);
536
537 /* Try to remap memory */
538
539 size = vma->vm_end - vma->vm_start;
540 size = (size < mem->size) ? size : mem->size;
541
542 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
543 retval = remap_pfn_range(vma, vma->vm_start,
544 mem->dma_handle >> PAGE_SHIFT,
545 size, vma->vm_page_prot);
546 if (retval) {
547 dev_err(q->dev, "mmap: remap failed with error %d. ", retval);
548 dt3155_free_buffer(q->dev, mem->size,
549 mem->vaddr, mem->dma_handle);
550 goto error;
551 }
552
553 vma->vm_ops = &dt3155_vm_ops;
554 vma->vm_flags |= VM_DONTEXPAND;
555 vma->vm_private_data = map;
556
557 dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
558 map, q, vma->vm_start, vma->vm_end,
559 (long int)buf->bsize,
560 vma->vm_pgoff, buf->i);
561
562 dt3155_vm_open(vma);
563
564 return 0;
565
566error:
567 kfree(map);
568 return -ENOMEM;
569}
570
571static int
572dt3155_sync_for_cpu(struct videobuf_queue *q, struct videobuf_buffer *vb)
573{
574 struct dt3155_priv *pd = q->priv_data;
575 struct videobuf_dma_contig_memory *mem = vb->priv;
576
577 BUG_ON(!mem);
578 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
579
580 pci_dma_sync_single_for_cpu(pd->pdev, mem->dma_handle,
581 mem->size, PCI_DMA_FROMDEVICE);
582 return 0;
583}
584
585static int
586dt3155_sync_for_device(struct videobuf_queue *q, struct videobuf_buffer *vb)
587{
588 struct dt3155_priv *pd = q->priv_data;
589 struct videobuf_dma_contig_memory *mem = vb->priv;
590
591 BUG_ON(!mem);
592 MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
593
594 pci_dma_sync_single_for_device(pd->pdev, mem->dma_handle,
595 mem->size, PCI_DMA_FROMDEVICE);
596 return 0;
597}
598
599/*
600 * same as videobuf_queue_dma_contig_init(), but after
601 * initialisation overwrites videobuf_iolock() and
602 * videobuf_mmap_mapper() with our customized versions
603 * as well as adds sync() method
604 */
605static void
606dt3155_queue_dma_contig_init(struct videobuf_queue *q,
607 struct videobuf_queue_ops *ops,
608 struct device *dev,
609 spinlock_t *irqlock,
610 enum v4l2_buf_type type,
611 enum v4l2_field field,
612 unsigned int msize,
613 void *priv)
614{
615 struct dt3155_priv *pd = priv;
616
617 videobuf_queue_dma_contig_init(q, ops, dev, irqlock,
618 type, field, msize, priv);
619 /* replace with local copy */
620 pd->qt_ops = *q->int_ops;
621 q->int_ops = &pd->qt_ops;
622 /* and overwrite with our methods */
623 q->int_ops->iolock = dt3155_iolock;
624 q->int_ops->mmap_mapper = dt3155_mmap_mapper;
625 q->int_ops->sync = dt3155_sync_for_cpu;
626}
627
628static int 197static int
629dt3155_start_acq(struct dt3155_priv *pd) 198dt3155_start_acq(struct dt3155_priv *pd)
630{ 199{
@@ -699,7 +268,7 @@ dt3155_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
699 if (ret) { 268 if (ret) {
700 vb->state = VIDEOBUF_ERROR; 269 vb->state = VIDEOBUF_ERROR;
701 printk(KERN_ERR "ERROR: videobuf_iolock() failed\n"); 270 printk(KERN_ERR "ERROR: videobuf_iolock() failed\n");
702 videobuf_dma_contig_free(q, vb); 271 videobuf_dma_contig_free(q, vb); /* FIXME: needed? */
703 } else 272 } else
704 vb->state = VIDEOBUF_PREPARED; 273 vb->state = VIDEOBUF_PREPARED;
705 return ret; 274 return ret;
@@ -713,7 +282,6 @@ dt3155_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
713 282
714 if (vb->state != VIDEOBUF_NEEDS_INIT) { 283 if (vb->state != VIDEOBUF_NEEDS_INIT) {
715 vb->state = VIDEOBUF_QUEUED; 284 vb->state = VIDEOBUF_QUEUED;
716 dt3155_sync_for_device(q, vb);
717 list_add_tail(&vb->queue, &pd->dmaq); 285 list_add_tail(&vb->queue, &pd->dmaq);
718 wake_up_interruptible_sync(&pd->do_dma); 286 wake_up_interruptible_sync(&pd->do_dma);
719 } else 287 } else
@@ -726,7 +294,7 @@ dt3155_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
726{ 294{
727 if (vb->state == VIDEOBUF_ACTIVE) 295 if (vb->state == VIDEOBUF_ACTIVE)
728 videobuf_waiton(vb, 0, 0); /* FIXME: cannot be interrupted */ 296 videobuf_waiton(vb, 0, 0); /* FIXME: cannot be interrupted */
729 dt3155_dma_contig_free(q, vb); 297 videobuf_dma_contig_free(q, vb);
730 vb->state = VIDEOBUF_NEEDS_INIT; 298 vb->state = VIDEOBUF_NEEDS_INIT;
731} 299}
732 300
@@ -869,7 +437,7 @@ dt3155_open(struct file *filp)
869 ret = -ENOMEM; 437 ret = -ENOMEM;
870 goto err_alloc_queue; 438 goto err_alloc_queue;
871 } 439 }
872 dt3155_queue_dma_contig_init(pd->vidq, &vbq_ops, 440 videobuf_queue_dma_contig_init(pd->vidq, &vbq_ops,
873 &pd->pdev->dev, &pd->lock, 441 &pd->pdev->dev, &pd->lock,
874 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 442 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
875 sizeof(struct videobuf_buffer), pd); 443 sizeof(struct videobuf_buffer), pd);
@@ -1317,11 +885,13 @@ static const struct v4l2_ioctl_ops dt3155_ioctl_ops = {
1317static int __devinit 885static int __devinit
1318dt3155_init_board(struct pci_dev *dev) 886dt3155_init_board(struct pci_dev *dev)
1319{ 887{
888 struct dt3155_priv *pd = pci_get_drvdata(dev);
889 void *buf_cpu;
890 dma_addr_t buf_dma;
1320 int i; 891 int i;
1321 u8 tmp; 892 u8 tmp;
1322 struct dt3155_buf *buf; 893
1323 struct dt3155_priv *pd = pci_get_drvdata(dev); 894 pci_set_master(dev); /* dt3155 needs it */
1324 pci_set_master(dev); /* dt3155 needs it */
1325 895
1326 /* resetting the adapter */ 896 /* resetting the adapter */
1327 iowrite32(FLD_CRPT_ODD | FLD_CRPT_EVEN | FLD_DN_ODD | FLD_DN_EVEN, 897 iowrite32(FLD_CRPT_ODD | FLD_CRPT_EVEN | FLD_DN_ODD | FLD_DN_EVEN,
@@ -1381,22 +951,16 @@ dt3155_init_board(struct pci_dev *dev)
1381 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); 951 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
1382 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3); 952 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3);
1383 953
1384 /* allocate and pci_map memory, and initialize the DMA machine */ 954 /* allocate memory, and initialize the DMA machine */
1385 buf = dt3155_get_buf(dt3155_free_bufs); 955 buf_cpu = dma_alloc_coherent(&dev->dev, DT3155_BUF_SIZE, &buf_dma,
1386 if (!buf) { 956 GFP_KERNEL);
1387 printk(KERN_ERR "dt3155: dt3155_get_buf " 957 if (!buf_cpu) {
958 printk(KERN_ERR "dt3155: dma_alloc_coherent "
1388 "(in dt3155_init_board) failed\n"); 959 "(in dt3155_init_board) failed\n");
1389 return -ENOMEM; 960 return -ENOMEM;
1390 } 961 }
1391 buf->dma = pci_map_single(dev, buf->cpu, 962 iowrite32(buf_dma, pd->regs + EVEN_DMA_START);
1392 DT3155_BUF_SIZE, PCI_DMA_FROMDEVICE); 963 iowrite32(buf_dma, pd->regs + ODD_DMA_START);
1393 if (pci_dma_mapping_error(dev, buf->dma)) {
1394 printk(KERN_ERR "dt3155: pci_map_single failed\n");
1395 dt3155_put_buf(buf, dt3155_free_bufs);
1396 return -ENOMEM;
1397 }
1398 iowrite32(buf->dma, pd->regs + EVEN_DMA_START);
1399 iowrite32(buf->dma, pd->regs + ODD_DMA_START);
1400 iowrite32(0, pd->regs + EVEN_DMA_STRIDE); 964 iowrite32(0, pd->regs + EVEN_DMA_STRIDE);
1401 iowrite32(0, pd->regs + ODD_DMA_STRIDE); 965 iowrite32(0, pd->regs + ODD_DMA_STRIDE);
1402 966
@@ -1413,9 +977,8 @@ dt3155_init_board(struct pci_dev *dev)
1413 write_i2c_reg(pd->regs, CSR2, pd->csr2); 977 write_i2c_reg(pd->regs, CSR2, pd->csr2);
1414 iowrite32(FIFO_EN | SRST | FLD_DN_EVEN | FLD_DN_ODD, pd->regs + CSR1); 978 iowrite32(FIFO_EN | SRST | FLD_DN_EVEN | FLD_DN_ODD, pd->regs + CSR1);
1415 979
1416 /* pci_unmap and deallocate memory */ 980 /* deallocate memory */
1417 pci_unmap_single(dev, buf->dma, DT3155_BUF_SIZE, PCI_DMA_FROMDEVICE); 981 dma_free_coherent(&dev->dev, DT3155_BUF_SIZE, buf_cpu, buf_dma);
1418 dt3155_put_buf(buf, dt3155_free_bufs);
1419 if (tmp & BUSY_EVEN) { 982 if (tmp & BUSY_EVEN) {
1420 printk(KERN_ERR "dt3155: BUSY_EVEN not cleared\n"); 983 printk(KERN_ERR "dt3155: BUSY_EVEN not cleared\n");
1421 return -EIO; 984 return -EIO;
@@ -1433,17 +996,82 @@ static struct video_device dt3155_vdev = {
1433 .current_norm = DT3155_CURRENT_NORM, 996 .current_norm = DT3155_CURRENT_NORM,
1434}; 997};
1435 998
999/* same as in drivers/base/dma-coherent.c */
1000struct dma_coherent_mem {
1001 void *virt_base;
1002 u32 device_base;
1003 int size;
1004 int flags;
1005 unsigned long *bitmap;
1006};
1007
1008static int __devinit
1009dt3155_alloc_coherent(struct device *dev, size_t size, int flags)
1010{
1011 int pages = size >> PAGE_SHIFT;
1012 int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
1013
1014 if ((flags & DMA_MEMORY_MAP) == 0)
1015 goto out;
1016 if (!size)
1017 goto out;
1018 if (dev->dma_mem)
1019 goto out;
1020
1021 dev->dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
1022 if (!dev->dma_mem)
1023 goto out;
1024 dev->dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
1025 if (!dev->dma_mem->bitmap)
1026 goto err_bitmap;
1027
1028 dev->dma_mem->virt_base = dma_alloc_coherent(dev, size,
1029 &dev->dma_mem->device_base, DT3155_COH_FLAGS);
1030 if (!dev->dma_mem->virt_base)
1031 goto err_coherent;
1032 dev->dma_mem->size = pages;
1033 dev->dma_mem->flags = flags;
1034 return DMA_MEMORY_MAP;
1035
1036err_coherent:
1037 kfree(dev->dma_mem->bitmap);
1038err_bitmap:
1039 kfree(dev->dma_mem);
1040out:
1041 return 0;
1042}
1043
1044static void __devexit
1045dt3155_free_coherent(struct device *dev)
1046{
1047 struct dma_coherent_mem *mem = dev->dma_mem;
1048
1049 if (!mem)
1050 return;
1051 dev->dma_mem = NULL;
1052 dma_free_coherent(dev, mem->size << PAGE_SHIFT,
1053 mem->virt_base, mem->device_base);
1054 kfree(mem->bitmap);
1055 kfree(mem);
1056}
1057
1436static int __devinit 1058static int __devinit
1437dt3155_probe(struct pci_dev *dev, const struct pci_device_id *id) 1059dt3155_probe(struct pci_dev *dev, const struct pci_device_id *id)
1438{ 1060{
1439 int err = -ENODEV; 1061 int err;
1440 struct dt3155_priv *pd; 1062 struct dt3155_priv *pd;
1441 1063
1442 printk(KERN_INFO "dt3155: probe()\n"); 1064 printk(KERN_INFO "dt3155: probe()\n");
1443 if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) { 1065 err = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
1066 if (err) {
1444 printk(KERN_ERR "dt3155: cannot set dma_mask\n"); 1067 printk(KERN_ERR "dt3155: cannot set dma_mask\n");
1445 return -ENODEV; 1068 return -ENODEV;
1446 } 1069 }
1070 err = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
1071 if (err) {
1072 printk(KERN_ERR "dt3155: cannot set dma_coherent_mask\n");
1073 return -ENODEV;
1074 }
1447 pd = kzalloc(sizeof(*pd), GFP_KERNEL); 1075 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
1448 if (!pd) { 1076 if (!pd) {
1449 printk(KERN_ERR "dt3155: cannot allocate dt3155_priv\n"); 1077 printk(KERN_ERR "dt3155: cannot allocate dt3155_priv\n");
@@ -1451,12 +1079,12 @@ dt3155_probe(struct pci_dev *dev, const struct pci_device_id *id)
1451 } 1079 }
1452 pd->vdev = video_device_alloc(); 1080 pd->vdev = video_device_alloc();
1453 if (!pd->vdev) { 1081 if (!pd->vdev) {
1454 printk(KERN_ERR "dt3155: cannot allocate vdp structure\n"); 1082 printk(KERN_ERR "dt3155: cannot allocate vdev structure\n");
1455 goto err_video_device_alloc; 1083 goto err_video_device_alloc;
1456 } 1084 }
1457 *pd->vdev = dt3155_vdev; 1085 *pd->vdev = dt3155_vdev;
1458 pci_set_drvdata(dev, pd); /* for use in dt3155_remove() */ 1086 pci_set_drvdata(dev, pd); /* for use in dt3155_remove() */
1459 video_set_drvdata(pd->vdev, pd); /* for use in video_fops */ 1087 video_set_drvdata(pd->vdev, pd); /* for use in video_fops */
1460 pd->users = 0; 1088 pd->users = 0;
1461 pd->acq_fp = NULL; 1089 pd->acq_fp = NULL;
1462 pd->pdev = dev; 1090 pd->pdev = dev;
@@ -1489,6 +1117,10 @@ dt3155_probe(struct pci_dev *dev, const struct pci_device_id *id)
1489 printk(KERN_ERR "dt3155: Cannot register video device\n"); 1117 printk(KERN_ERR "dt3155: Cannot register video device\n");
1490 goto err_init_board; 1118 goto err_init_board;
1491 } 1119 }
1120 err = dt3155_alloc_coherent(&dev->dev, DT3155_CHUNK_SIZE,
1121 DMA_MEMORY_MAP);
1122 if (err)
1123 printk(KERN_INFO "dt3155: preallocated 8 buffers\n");
1492 printk(KERN_INFO "dt3155: /dev/video%i is ready\n", pd->vdev->minor); 1124 printk(KERN_INFO "dt3155: /dev/video%i is ready\n", pd->vdev->minor);
1493 return 0; /* success */ 1125 return 0; /* success */
1494 1126
@@ -1511,6 +1143,7 @@ dt3155_remove(struct pci_dev *dev)
1511 struct dt3155_priv *pd = pci_get_drvdata(dev); 1143 struct dt3155_priv *pd = pci_get_drvdata(dev);
1512 1144
1513 printk(KERN_INFO "dt3155: remove()\n"); 1145 printk(KERN_INFO "dt3155: remove()\n");
1146 dt3155_free_coherent(&dev->dev);
1514 video_unregister_device(pd->vdev); 1147 video_unregister_device(pd->vdev);
1515 pci_iounmap(dev, pd->regs); 1148 pci_iounmap(dev, pd->regs);
1516 pci_release_region(pd->pdev, 0); 1149 pci_release_region(pd->pdev, 0);
@@ -1542,48 +1175,18 @@ dt3155_init_module(void)
1542 1175
1543 printk(KERN_INFO "dt3155: ==================\n"); 1176 printk(KERN_INFO "dt3155: ==================\n");
1544 printk(KERN_INFO "dt3155: init()\n"); 1177 printk(KERN_INFO "dt3155: init()\n");
1545 dt3155_chunks = dt3155_init_chunks_fifo();
1546 if (!dt3155_chunks) {
1547 err = -ENOMEM;
1548 printk(KERN_ERR "dt3155: cannot init dt3155_chunks_fifo\n");
1549 goto err_init_chunks_fifo;
1550 }
1551 dt3155_free_bufs = dt3155_init_ibufs_fifo(dt3155_chunks,
1552 DT3155_BUF_SIZE);
1553 if (!dt3155_free_bufs) {
1554 err = -ENOMEM;
1555 printk(KERN_ERR "dt3155: cannot dt3155_init_ibufs_fifo\n");
1556 goto err_init_ibufs_fifo;
1557 }
1558 dt3155_alloc_bufs = dt3155_init_fifo();
1559 if (!dt3155_alloc_bufs) {
1560 err = -ENOMEM;
1561 printk(KERN_ERR "dt3155: cannot dt3155_init_fifo\n");
1562 goto err_init_fifo;
1563 }
1564 err = pci_register_driver(&pci_driver); 1178 err = pci_register_driver(&pci_driver);
1565 if (err) { 1179 if (err) {
1566 printk(KERN_ERR "dt3155: cannot register pci_driver\n"); 1180 printk(KERN_ERR "dt3155: cannot register pci_driver\n");
1567 goto err_register_driver; 1181 return err;
1568 } 1182 }
1569 return 0; /* succes */ 1183 return 0; /* succes */
1570err_register_driver:
1571 dt3155_free_fifo(dt3155_alloc_bufs);
1572err_init_fifo:
1573 dt3155_free_ibufs_fifo(dt3155_free_bufs);
1574err_init_ibufs_fifo:
1575 dt3155_free_chunks_fifo(dt3155_chunks);
1576err_init_chunks_fifo:
1577 return err;
1578} 1184}
1579 1185
1580static void __exit 1186static void __exit
1581dt3155_exit_module(void) 1187dt3155_exit_module(void)
1582{ 1188{
1583 pci_unregister_driver(&pci_driver); 1189 pci_unregister_driver(&pci_driver);
1584 dt3155_free_fifo(dt3155_alloc_bufs);
1585 dt3155_free_ibufs_fifo(dt3155_free_bufs);
1586 dt3155_free_chunks_fifo(dt3155_chunks);
1587 printk(KERN_INFO "dt3155: exit()\n"); 1190 printk(KERN_INFO "dt3155: exit()\n");
1588 printk(KERN_INFO "dt3155: ==================\n"); 1191 printk(KERN_INFO "dt3155: ==================\n");
1589} 1192}
diff --git a/drivers/staging/dt3155v4l/dt3155v4l.h b/drivers/staging/dt3155v4l/dt3155v4l.h
index e65a81e198b9..aa68a6f38aaa 100644
--- a/drivers/staging/dt3155v4l/dt3155v4l.h
+++ b/drivers/staging/dt3155v4l/dt3155v4l.h
@@ -29,8 +29,8 @@
29 29
30#define DT3155_NAME "dt3155" 30#define DT3155_NAME "dt3155"
31#define DT3155_VER_MAJ 1 31#define DT3155_VER_MAJ 1
32#define DT3155_VER_MIN 0 32#define DT3155_VER_MIN 1
33#define DT3155_VER_EXT 3 33#define DT3155_VER_EXT 0
34#define DT3155_VERSION __stringify(DT3155_VER_MAJ) "." \ 34#define DT3155_VERSION __stringify(DT3155_VER_MAJ) "." \
35 __stringify(DT3155_VER_MIN) "." \ 35 __stringify(DT3155_VER_MIN) "." \
36 __stringify(DT3155_VER_EXT) 36 __stringify(DT3155_VER_EXT)