diff options
Diffstat (limited to 'drivers/media/video/omap24xxcam.c')
-rw-r--r-- | drivers/media/video/omap24xxcam.c | 1908 |
1 files changed, 1908 insertions, 0 deletions
diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c new file mode 100644 index 000000000000..85c3c7c92af1 --- /dev/null +++ b/drivers/media/video/omap24xxcam.c | |||
@@ -0,0 +1,1908 @@ | |||
1 | /* | ||
2 | * drivers/media/video/omap24xxcam.c | ||
3 | * | ||
4 | * OMAP 2 camera block driver. | ||
5 | * | ||
6 | * Copyright (C) 2004 MontaVista Software, Inc. | ||
7 | * Copyright (C) 2004 Texas Instruments. | ||
8 | * Copyright (C) 2007-2008 Nokia Corporation. | ||
9 | * | ||
10 | * Contact: Sakari Ailus <sakari.ailus@nokia.com> | ||
11 | * | ||
12 | * Based on code from Andy Lowe <source@mvista.com> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * version 2 as published by the Free Software Foundation. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, but | ||
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
26 | * 02110-1301 USA | ||
27 | */ | ||
28 | |||
29 | #include <linux/delay.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | #include <linux/videodev2.h> | ||
33 | #include <linux/pci.h> /* needed for videobufs */ | ||
34 | #include <linux/version.h> | ||
35 | #include <linux/platform_device.h> | ||
36 | #include <linux/clk.h> | ||
37 | #include <linux/io.h> | ||
38 | |||
39 | #include <media/v4l2-common.h> | ||
40 | #include <media/v4l2-ioctl.h> | ||
41 | |||
42 | #include "omap24xxcam.h" | ||
43 | |||
44 | #define OMAP24XXCAM_VERSION KERNEL_VERSION(0, 0, 0) | ||
45 | |||
46 | #define RESET_TIMEOUT_NS 10000 | ||
47 | |||
48 | static void omap24xxcam_reset(struct omap24xxcam_device *cam); | ||
49 | static int omap24xxcam_sensor_if_enable(struct omap24xxcam_device *cam); | ||
50 | static void omap24xxcam_device_unregister(struct v4l2_int_device *s); | ||
51 | static int omap24xxcam_remove(struct platform_device *pdev); | ||
52 | |||
53 | /* module parameters */ | ||
54 | static int video_nr = -1; /* video device minor (-1 ==> auto assign) */ | ||
55 | /* | ||
56 | * Maximum amount of memory to use for capture buffers. | ||
57 | * Default is 4800KB, enough to double-buffer SXGA. | ||
58 | */ | ||
59 | static int capture_mem = 1280 * 960 * 2 * 2; | ||
60 | |||
61 | static struct v4l2_int_device omap24xxcam; | ||
62 | |||
63 | /* | ||
64 | * | ||
65 | * Clocks. | ||
66 | * | ||
67 | */ | ||
68 | |||
69 | static void omap24xxcam_clock_put(struct omap24xxcam_device *cam) | ||
70 | { | ||
71 | if (cam->ick != NULL && !IS_ERR(cam->ick)) | ||
72 | clk_put(cam->ick); | ||
73 | if (cam->fck != NULL && !IS_ERR(cam->fck)) | ||
74 | clk_put(cam->fck); | ||
75 | |||
76 | cam->ick = cam->fck = NULL; | ||
77 | } | ||
78 | |||
79 | static int omap24xxcam_clock_get(struct omap24xxcam_device *cam) | ||
80 | { | ||
81 | int rval = 0; | ||
82 | |||
83 | cam->fck = clk_get(cam->dev, "cam_fck"); | ||
84 | if (IS_ERR(cam->fck)) { | ||
85 | dev_err(cam->dev, "can't get cam_fck"); | ||
86 | rval = PTR_ERR(cam->fck); | ||
87 | omap24xxcam_clock_put(cam); | ||
88 | return rval; | ||
89 | } | ||
90 | |||
91 | cam->ick = clk_get(cam->dev, "cam_ick"); | ||
92 | if (IS_ERR(cam->ick)) { | ||
93 | dev_err(cam->dev, "can't get cam_ick"); | ||
94 | rval = PTR_ERR(cam->ick); | ||
95 | omap24xxcam_clock_put(cam); | ||
96 | } | ||
97 | |||
98 | return rval; | ||
99 | } | ||
100 | |||
101 | static void omap24xxcam_clock_on(struct omap24xxcam_device *cam) | ||
102 | { | ||
103 | clk_enable(cam->fck); | ||
104 | clk_enable(cam->ick); | ||
105 | } | ||
106 | |||
107 | static void omap24xxcam_clock_off(struct omap24xxcam_device *cam) | ||
108 | { | ||
109 | clk_disable(cam->fck); | ||
110 | clk_disable(cam->ick); | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * | ||
115 | * Camera core | ||
116 | * | ||
117 | */ | ||
118 | |||
119 | /* | ||
120 | * Set xclk. | ||
121 | * | ||
122 | * To disable xclk, use value zero. | ||
123 | */ | ||
124 | static void omap24xxcam_core_xclk_set(const struct omap24xxcam_device *cam, | ||
125 | u32 xclk) | ||
126 | { | ||
127 | if (xclk) { | ||
128 | u32 divisor = CAM_MCLK / xclk; | ||
129 | |||
130 | if (divisor == 1) | ||
131 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, | ||
132 | CC_CTRL_XCLK, | ||
133 | CC_CTRL_XCLK_DIV_BYPASS); | ||
134 | else | ||
135 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, | ||
136 | CC_CTRL_XCLK, divisor); | ||
137 | } else | ||
138 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, | ||
139 | CC_CTRL_XCLK, CC_CTRL_XCLK_DIV_STABLE_LOW); | ||
140 | } | ||
141 | |||
142 | static void omap24xxcam_core_hwinit(const struct omap24xxcam_device *cam) | ||
143 | { | ||
144 | /* | ||
145 | * Setting the camera core AUTOIDLE bit causes problems with frame | ||
146 | * synchronization, so we will clear the AUTOIDLE bit instead. | ||
147 | */ | ||
148 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_SYSCONFIG, | ||
149 | CC_SYSCONFIG_AUTOIDLE); | ||
150 | |||
151 | /* program the camera interface DMA packet size */ | ||
152 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_CTRL_DMA, | ||
153 | CC_CTRL_DMA_EN | (DMA_THRESHOLD / 4 - 1)); | ||
154 | |||
155 | /* enable camera core error interrupts */ | ||
156 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_IRQENABLE, | ||
157 | CC_IRQENABLE_FW_ERR_IRQ | ||
158 | | CC_IRQENABLE_FSC_ERR_IRQ | ||
159 | | CC_IRQENABLE_SSC_ERR_IRQ | ||
160 | | CC_IRQENABLE_FIFO_OF_IRQ); | ||
161 | } | ||
162 | |||
163 | /* | ||
164 | * Enable the camera core. | ||
165 | * | ||
166 | * Data transfer to the camera DMA starts from next starting frame. | ||
167 | */ | ||
168 | static void omap24xxcam_core_enable(const struct omap24xxcam_device *cam) | ||
169 | { | ||
170 | |||
171 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_CTRL, | ||
172 | cam->cc_ctrl); | ||
173 | } | ||
174 | |||
175 | /* | ||
176 | * Disable camera core. | ||
177 | * | ||
178 | * The data transfer will be stopped immediately (CC_CTRL_CC_RST). The | ||
179 | * core internal state machines will be reset. Use | ||
180 | * CC_CTRL_CC_FRAME_TRIG instead if you want to transfer the current | ||
181 | * frame completely. | ||
182 | */ | ||
183 | static void omap24xxcam_core_disable(const struct omap24xxcam_device *cam) | ||
184 | { | ||
185 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_CTRL, | ||
186 | CC_CTRL_CC_RST); | ||
187 | } | ||
188 | |||
189 | /* Interrupt service routine for camera core interrupts. */ | ||
190 | static void omap24xxcam_core_isr(struct omap24xxcam_device *cam) | ||
191 | { | ||
192 | u32 cc_irqstatus; | ||
193 | const u32 cc_irqstatus_err = | ||
194 | CC_IRQSTATUS_FW_ERR_IRQ | ||
195 | | CC_IRQSTATUS_FSC_ERR_IRQ | ||
196 | | CC_IRQSTATUS_SSC_ERR_IRQ | ||
197 | | CC_IRQSTATUS_FIFO_UF_IRQ | ||
198 | | CC_IRQSTATUS_FIFO_OF_IRQ; | ||
199 | |||
200 | cc_irqstatus = omap24xxcam_reg_in(cam->mmio_base + CC_REG_OFFSET, | ||
201 | CC_IRQSTATUS); | ||
202 | omap24xxcam_reg_out(cam->mmio_base + CC_REG_OFFSET, CC_IRQSTATUS, | ||
203 | cc_irqstatus); | ||
204 | |||
205 | if (cc_irqstatus & cc_irqstatus_err | ||
206 | && !atomic_read(&cam->in_reset)) { | ||
207 | dev_dbg(cam->dev, "resetting camera, cc_irqstatus 0x%x\n", | ||
208 | cc_irqstatus); | ||
209 | omap24xxcam_reset(cam); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | /* | ||
214 | * | ||
215 | * videobuf_buffer handling. | ||
216 | * | ||
217 | * Memory for mmapped videobuf_buffers is not allocated | ||
218 | * conventionally, but by several kmalloc allocations and then | ||
219 | * creating the scatterlist on our own. User-space buffers are handled | ||
220 | * normally. | ||
221 | * | ||
222 | */ | ||
223 | |||
224 | /* | ||
225 | * Free the memory-mapped buffer memory allocated for a | ||
226 | * videobuf_buffer and the associated scatterlist. | ||
227 | */ | ||
228 | static void omap24xxcam_vbq_free_mmap_buffer(struct videobuf_buffer *vb) | ||
229 | { | ||
230 | struct videobuf_dmabuf *dma = videobuf_to_dma(vb); | ||
231 | size_t alloc_size; | ||
232 | struct page *page; | ||
233 | int i; | ||
234 | |||
235 | if (dma->sglist == NULL) | ||
236 | return; | ||
237 | |||
238 | i = dma->sglen; | ||
239 | while (i) { | ||
240 | i--; | ||
241 | alloc_size = sg_dma_len(&dma->sglist[i]); | ||
242 | page = sg_page(&dma->sglist[i]); | ||
243 | do { | ||
244 | ClearPageReserved(page++); | ||
245 | } while (alloc_size -= PAGE_SIZE); | ||
246 | __free_pages(sg_page(&dma->sglist[i]), | ||
247 | get_order(sg_dma_len(&dma->sglist[i]))); | ||
248 | } | ||
249 | |||
250 | kfree(dma->sglist); | ||
251 | dma->sglist = NULL; | ||
252 | } | ||
253 | |||
254 | /* Release all memory related to the videobuf_queue. */ | ||
255 | static void omap24xxcam_vbq_free_mmap_buffers(struct videobuf_queue *vbq) | ||
256 | { | ||
257 | int i; | ||
258 | |||
259 | mutex_lock(&vbq->vb_lock); | ||
260 | |||
261 | for (i = 0; i < VIDEO_MAX_FRAME; i++) { | ||
262 | if (NULL == vbq->bufs[i]) | ||
263 | continue; | ||
264 | if (V4L2_MEMORY_MMAP != vbq->bufs[i]->memory) | ||
265 | continue; | ||
266 | vbq->ops->buf_release(vbq, vbq->bufs[i]); | ||
267 | omap24xxcam_vbq_free_mmap_buffer(vbq->bufs[i]); | ||
268 | kfree(vbq->bufs[i]); | ||
269 | vbq->bufs[i] = NULL; | ||
270 | } | ||
271 | |||
272 | mutex_unlock(&vbq->vb_lock); | ||
273 | |||
274 | videobuf_mmap_free(vbq); | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * Allocate physically as contiguous as possible buffer for video | ||
279 | * frame and allocate and build DMA scatter-gather list for it. | ||
280 | */ | ||
281 | static int omap24xxcam_vbq_alloc_mmap_buffer(struct videobuf_buffer *vb) | ||
282 | { | ||
283 | unsigned int order; | ||
284 | size_t alloc_size, size = vb->bsize; /* vb->bsize is page aligned */ | ||
285 | struct page *page; | ||
286 | int max_pages, err = 0, i = 0; | ||
287 | struct videobuf_dmabuf *dma = videobuf_to_dma(vb); | ||
288 | |||
289 | /* | ||
290 | * allocate maximum size scatter-gather list. Note this is | ||
291 | * overhead. We may not use as many entries as we allocate | ||
292 | */ | ||
293 | max_pages = vb->bsize >> PAGE_SHIFT; | ||
294 | dma->sglist = kcalloc(max_pages, sizeof(*dma->sglist), GFP_KERNEL); | ||
295 | if (dma->sglist == NULL) { | ||
296 | err = -ENOMEM; | ||
297 | goto out; | ||
298 | } | ||
299 | |||
300 | while (size) { | ||
301 | order = get_order(size); | ||
302 | /* | ||
303 | * do not over-allocate even if we would get larger | ||
304 | * contiguous chunk that way | ||
305 | */ | ||
306 | if ((PAGE_SIZE << order) > size) | ||
307 | order--; | ||
308 | |||
309 | /* try to allocate as many contiguous pages as possible */ | ||
310 | page = alloc_pages(GFP_KERNEL | GFP_DMA, order); | ||
311 | /* if allocation fails, try to allocate smaller amount */ | ||
312 | while (page == NULL) { | ||
313 | order--; | ||
314 | page = alloc_pages(GFP_KERNEL | GFP_DMA, order); | ||
315 | if (page == NULL && !order) { | ||
316 | err = -ENOMEM; | ||
317 | goto out; | ||
318 | } | ||
319 | } | ||
320 | size -= (PAGE_SIZE << order); | ||
321 | |||
322 | /* append allocated chunk of pages into scatter-gather list */ | ||
323 | sg_set_page(&dma->sglist[i], page, PAGE_SIZE << order, 0); | ||
324 | dma->sglen++; | ||
325 | i++; | ||
326 | |||
327 | alloc_size = (PAGE_SIZE << order); | ||
328 | |||
329 | /* clear pages before giving them to user space */ | ||
330 | memset(page_address(page), 0, alloc_size); | ||
331 | |||
332 | /* mark allocated pages reserved */ | ||
333 | do { | ||
334 | SetPageReserved(page++); | ||
335 | } while (alloc_size -= PAGE_SIZE); | ||
336 | } | ||
337 | /* | ||
338 | * REVISIT: not fully correct to assign nr_pages == sglen but | ||
339 | * video-buf is passing nr_pages for e.g. unmap_sg calls | ||
340 | */ | ||
341 | dma->nr_pages = dma->sglen; | ||
342 | dma->direction = PCI_DMA_FROMDEVICE; | ||
343 | |||
344 | return 0; | ||
345 | |||
346 | out: | ||
347 | omap24xxcam_vbq_free_mmap_buffer(vb); | ||
348 | return err; | ||
349 | } | ||
350 | |||
351 | static int omap24xxcam_vbq_alloc_mmap_buffers(struct videobuf_queue *vbq, | ||
352 | unsigned int count) | ||
353 | { | ||
354 | int i, err = 0; | ||
355 | struct omap24xxcam_fh *fh = | ||
356 | container_of(vbq, struct omap24xxcam_fh, vbq); | ||
357 | |||
358 | mutex_lock(&vbq->vb_lock); | ||
359 | |||
360 | for (i = 0; i < count; i++) { | ||
361 | err = omap24xxcam_vbq_alloc_mmap_buffer(vbq->bufs[i]); | ||
362 | if (err) | ||
363 | goto out; | ||
364 | dev_dbg(fh->cam->dev, "sglen is %d for buffer %d\n", | ||
365 | videobuf_to_dma(vbq->bufs[i])->sglen, i); | ||
366 | } | ||
367 | |||
368 | mutex_unlock(&vbq->vb_lock); | ||
369 | |||
370 | return 0; | ||
371 | out: | ||
372 | while (i) { | ||
373 | i--; | ||
374 | omap24xxcam_vbq_free_mmap_buffer(vbq->bufs[i]); | ||
375 | } | ||
376 | |||
377 | mutex_unlock(&vbq->vb_lock); | ||
378 | |||
379 | return err; | ||
380 | } | ||
381 | |||
382 | /* | ||
383 | * This routine is called from interrupt context when a scatter-gather DMA | ||
384 | * transfer of a videobuf_buffer completes. | ||
385 | */ | ||
386 | static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma, | ||
387 | u32 csr, void *arg) | ||
388 | { | ||
389 | struct omap24xxcam_device *cam = | ||
390 | container_of(sgdma, struct omap24xxcam_device, sgdma); | ||
391 | struct omap24xxcam_fh *fh = cam->streaming->private_data; | ||
392 | struct videobuf_buffer *vb = (struct videobuf_buffer *)arg; | ||
393 | const u32 csr_error = CAMDMA_CSR_MISALIGNED_ERR | ||
394 | | CAMDMA_CSR_SUPERVISOR_ERR | CAMDMA_CSR_SECURE_ERR | ||
395 | | CAMDMA_CSR_TRANS_ERR | CAMDMA_CSR_DROP; | ||
396 | unsigned long flags; | ||
397 | |||
398 | spin_lock_irqsave(&cam->core_enable_disable_lock, flags); | ||
399 | if (--cam->sgdma_in_queue == 0) | ||
400 | omap24xxcam_core_disable(cam); | ||
401 | spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags); | ||
402 | |||
403 | do_gettimeofday(&vb->ts); | ||
404 | vb->field_count = atomic_add_return(2, &fh->field_count); | ||
405 | if (csr & csr_error) { | ||
406 | vb->state = VIDEOBUF_ERROR; | ||
407 | if (!atomic_read(&fh->cam->in_reset)) { | ||
408 | dev_dbg(cam->dev, "resetting camera, csr 0x%x\n", csr); | ||
409 | omap24xxcam_reset(cam); | ||
410 | } | ||
411 | } else | ||
412 | vb->state = VIDEOBUF_DONE; | ||
413 | wake_up(&vb->done); | ||
414 | } | ||
415 | |||
416 | static void omap24xxcam_vbq_release(struct videobuf_queue *vbq, | ||
417 | struct videobuf_buffer *vb) | ||
418 | { | ||
419 | struct videobuf_dmabuf *dma = videobuf_to_dma(vb); | ||
420 | |||
421 | /* wait for buffer, especially to get out of the sgdma queue */ | ||
422 | videobuf_waiton(vb, 0, 0); | ||
423 | if (vb->memory == V4L2_MEMORY_MMAP) { | ||
424 | dma_unmap_sg(vbq->dev, dma->sglist, dma->sglen, | ||
425 | dma->direction); | ||
426 | dma->direction = DMA_NONE; | ||
427 | } else { | ||
428 | videobuf_dma_unmap(vbq, videobuf_to_dma(vb)); | ||
429 | videobuf_dma_free(videobuf_to_dma(vb)); | ||
430 | } | ||
431 | |||
432 | vb->state = VIDEOBUF_NEEDS_INIT; | ||
433 | } | ||
434 | |||
435 | /* | ||
436 | * Limit the number of available kernel image capture buffers based on the | ||
437 | * number requested, the currently selected image size, and the maximum | ||
438 | * amount of memory permitted for kernel capture buffers. | ||
439 | */ | ||
440 | static int omap24xxcam_vbq_setup(struct videobuf_queue *vbq, unsigned int *cnt, | ||
441 | unsigned int *size) | ||
442 | { | ||
443 | struct omap24xxcam_fh *fh = vbq->priv_data; | ||
444 | |||
445 | if (*cnt <= 0) | ||
446 | *cnt = VIDEO_MAX_FRAME; /* supply a default number of buffers */ | ||
447 | |||
448 | if (*cnt > VIDEO_MAX_FRAME) | ||
449 | *cnt = VIDEO_MAX_FRAME; | ||
450 | |||
451 | *size = fh->pix.sizeimage; | ||
452 | |||
453 | /* accessing fh->cam->capture_mem is ok, it's constant */ | ||
454 | while (*size * *cnt > fh->cam->capture_mem) | ||
455 | (*cnt)--; | ||
456 | |||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | static int omap24xxcam_dma_iolock(struct videobuf_queue *vbq, | ||
461 | struct videobuf_dmabuf *dma) | ||
462 | { | ||
463 | int err = 0; | ||
464 | |||
465 | dma->direction = PCI_DMA_FROMDEVICE; | ||
466 | if (!dma_map_sg(vbq->dev, dma->sglist, dma->sglen, dma->direction)) { | ||
467 | kfree(dma->sglist); | ||
468 | dma->sglist = NULL; | ||
469 | dma->sglen = 0; | ||
470 | err = -EIO; | ||
471 | } | ||
472 | |||
473 | return err; | ||
474 | } | ||
475 | |||
476 | static int omap24xxcam_vbq_prepare(struct videobuf_queue *vbq, | ||
477 | struct videobuf_buffer *vb, | ||
478 | enum v4l2_field field) | ||
479 | { | ||
480 | struct omap24xxcam_fh *fh = vbq->priv_data; | ||
481 | int err = 0; | ||
482 | |||
483 | /* | ||
484 | * Accessing pix here is okay since it's constant while | ||
485 | * streaming is on (and we only get called then). | ||
486 | */ | ||
487 | if (vb->baddr) { | ||
488 | /* This is a userspace buffer. */ | ||
489 | if (fh->pix.sizeimage > vb->bsize) { | ||
490 | /* The buffer isn't big enough. */ | ||
491 | err = -EINVAL; | ||
492 | } else | ||
493 | vb->size = fh->pix.sizeimage; | ||
494 | } else { | ||
495 | if (vb->state != VIDEOBUF_NEEDS_INIT) { | ||
496 | /* | ||
497 | * We have a kernel bounce buffer that has | ||
498 | * already been allocated. | ||
499 | */ | ||
500 | if (fh->pix.sizeimage > vb->size) { | ||
501 | /* | ||
502 | * The image size has been changed to | ||
503 | * a larger size since this buffer was | ||
504 | * allocated, so we need to free and | ||
505 | * reallocate it. | ||
506 | */ | ||
507 | omap24xxcam_vbq_release(vbq, vb); | ||
508 | vb->size = fh->pix.sizeimage; | ||
509 | } | ||
510 | } else { | ||
511 | /* We need to allocate a new kernel bounce buffer. */ | ||
512 | vb->size = fh->pix.sizeimage; | ||
513 | } | ||
514 | } | ||
515 | |||
516 | if (err) | ||
517 | return err; | ||
518 | |||
519 | vb->width = fh->pix.width; | ||
520 | vb->height = fh->pix.height; | ||
521 | vb->field = field; | ||
522 | |||
523 | if (vb->state == VIDEOBUF_NEEDS_INIT) { | ||
524 | if (vb->memory == V4L2_MEMORY_MMAP) | ||
525 | /* | ||
526 | * we have built the scatter-gather list by ourself so | ||
527 | * do the scatter-gather mapping as well | ||
528 | */ | ||
529 | err = omap24xxcam_dma_iolock(vbq, videobuf_to_dma(vb)); | ||
530 | else | ||
531 | err = videobuf_iolock(vbq, vb, NULL); | ||
532 | } | ||
533 | |||
534 | if (!err) | ||
535 | vb->state = VIDEOBUF_PREPARED; | ||
536 | else | ||
537 | omap24xxcam_vbq_release(vbq, vb); | ||
538 | |||
539 | return err; | ||
540 | } | ||
541 | |||
542 | static void omap24xxcam_vbq_queue(struct videobuf_queue *vbq, | ||
543 | struct videobuf_buffer *vb) | ||
544 | { | ||
545 | struct omap24xxcam_fh *fh = vbq->priv_data; | ||
546 | struct omap24xxcam_device *cam = fh->cam; | ||
547 | enum videobuf_state state = vb->state; | ||
548 | unsigned long flags; | ||
549 | int err; | ||
550 | |||
551 | /* | ||
552 | * FIXME: We're marking the buffer active since we have no | ||
553 | * pretty way of marking it active exactly when the | ||
554 | * scatter-gather transfer starts. | ||
555 | */ | ||
556 | vb->state = VIDEOBUF_ACTIVE; | ||
557 | |||
558 | err = omap24xxcam_sgdma_queue(&fh->cam->sgdma, | ||
559 | videobuf_to_dma(vb)->sglist, | ||
560 | videobuf_to_dma(vb)->sglen, vb->size, | ||
561 | omap24xxcam_vbq_complete, vb); | ||
562 | |||
563 | if (!err) { | ||
564 | spin_lock_irqsave(&cam->core_enable_disable_lock, flags); | ||
565 | if (++cam->sgdma_in_queue == 1 | ||
566 | && !atomic_read(&cam->in_reset)) | ||
567 | omap24xxcam_core_enable(cam); | ||
568 | spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags); | ||
569 | } else { | ||
570 | /* | ||
571 | * Oops. We're not supposed to get any errors here. | ||
572 | * The only way we could get an error is if we ran out | ||
573 | * of scatter-gather DMA slots, but we are supposed to | ||
574 | * have at least as many scatter-gather DMA slots as | ||
575 | * video buffers so that can't happen. | ||
576 | */ | ||
577 | dev_err(cam->dev, "failed to queue a video buffer for dma!\n"); | ||
578 | dev_err(cam->dev, "likely a bug in the driver!\n"); | ||
579 | vb->state = state; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | static struct videobuf_queue_ops omap24xxcam_vbq_ops = { | ||
584 | .buf_setup = omap24xxcam_vbq_setup, | ||
585 | .buf_prepare = omap24xxcam_vbq_prepare, | ||
586 | .buf_queue = omap24xxcam_vbq_queue, | ||
587 | .buf_release = omap24xxcam_vbq_release, | ||
588 | }; | ||
589 | |||
590 | /* | ||
591 | * | ||
592 | * OMAP main camera system | ||
593 | * | ||
594 | */ | ||
595 | |||
596 | /* | ||
597 | * Reset camera block to power-on state. | ||
598 | */ | ||
599 | static void omap24xxcam_poweron_reset(struct omap24xxcam_device *cam) | ||
600 | { | ||
601 | int max_loop = RESET_TIMEOUT_NS; | ||
602 | |||
603 | /* Reset whole camera subsystem */ | ||
604 | omap24xxcam_reg_out(cam->mmio_base, | ||
605 | CAM_SYSCONFIG, | ||
606 | CAM_SYSCONFIG_SOFTRESET); | ||
607 | |||
608 | /* Wait till it's finished */ | ||
609 | while (!(omap24xxcam_reg_in(cam->mmio_base, CAM_SYSSTATUS) | ||
610 | & CAM_SYSSTATUS_RESETDONE) | ||
611 | && --max_loop) { | ||
612 | ndelay(1); | ||
613 | } | ||
614 | |||
615 | if (!(omap24xxcam_reg_in(cam->mmio_base, CAM_SYSSTATUS) | ||
616 | & CAM_SYSSTATUS_RESETDONE)) | ||
617 | dev_err(cam->dev, "camera soft reset timeout\n"); | ||
618 | } | ||
619 | |||
620 | /* | ||
621 | * (Re)initialise the camera block. | ||
622 | */ | ||
623 | static void omap24xxcam_hwinit(struct omap24xxcam_device *cam) | ||
624 | { | ||
625 | omap24xxcam_poweron_reset(cam); | ||
626 | |||
627 | /* set the camera subsystem autoidle bit */ | ||
628 | omap24xxcam_reg_out(cam->mmio_base, CAM_SYSCONFIG, | ||
629 | CAM_SYSCONFIG_AUTOIDLE); | ||
630 | |||
631 | /* set the camera MMU autoidle bit */ | ||
632 | omap24xxcam_reg_out(cam->mmio_base, | ||
633 | CAMMMU_REG_OFFSET + CAMMMU_SYSCONFIG, | ||
634 | CAMMMU_SYSCONFIG_AUTOIDLE); | ||
635 | |||
636 | omap24xxcam_core_hwinit(cam); | ||
637 | |||
638 | omap24xxcam_dma_hwinit(&cam->sgdma.dma); | ||
639 | } | ||
640 | |||
641 | /* | ||
642 | * Callback for dma transfer stalling. | ||
643 | */ | ||
644 | static void omap24xxcam_stalled_dma_reset(unsigned long data) | ||
645 | { | ||
646 | struct omap24xxcam_device *cam = (struct omap24xxcam_device *)data; | ||
647 | |||
648 | if (!atomic_read(&cam->in_reset)) { | ||
649 | dev_dbg(cam->dev, "dma stalled, resetting camera\n"); | ||
650 | omap24xxcam_reset(cam); | ||
651 | } | ||
652 | } | ||
653 | |||
654 | /* | ||
655 | * Stop capture. Mark we're doing a reset, stop DMA transfers and | ||
656 | * core. (No new scatter-gather transfers will be queued whilst | ||
657 | * in_reset is non-zero.) | ||
658 | * | ||
659 | * If omap24xxcam_capture_stop is called from several places at | ||
660 | * once, only the first call will have an effect. Similarly, the last | ||
661 | * call omap24xxcam_streaming_cont will have effect. | ||
662 | * | ||
663 | * Serialisation is ensured by using cam->core_enable_disable_lock. | ||
664 | */ | ||
665 | static void omap24xxcam_capture_stop(struct omap24xxcam_device *cam) | ||
666 | { | ||
667 | unsigned long flags; | ||
668 | |||
669 | spin_lock_irqsave(&cam->core_enable_disable_lock, flags); | ||
670 | |||
671 | if (atomic_inc_return(&cam->in_reset) != 1) { | ||
672 | spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags); | ||
673 | return; | ||
674 | } | ||
675 | |||
676 | omap24xxcam_core_disable(cam); | ||
677 | |||
678 | spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags); | ||
679 | |||
680 | omap24xxcam_sgdma_sync(&cam->sgdma); | ||
681 | } | ||
682 | |||
683 | /* | ||
684 | * Reset and continue streaming. | ||
685 | * | ||
686 | * Note: Resetting the camera FIFO via the CC_RST bit in the CC_CTRL | ||
687 | * register is supposed to be sufficient to recover from a camera | ||
688 | * interface error, but it doesn't seem to be enough. If we only do | ||
689 | * that then subsequent image captures are out of sync by either one | ||
690 | * or two times DMA_THRESHOLD bytes. Resetting and re-initializing the | ||
691 | * entire camera subsystem prevents the problem with frame | ||
692 | * synchronization. | ||
693 | */ | ||
694 | static void omap24xxcam_capture_cont(struct omap24xxcam_device *cam) | ||
695 | { | ||
696 | unsigned long flags; | ||
697 | |||
698 | spin_lock_irqsave(&cam->core_enable_disable_lock, flags); | ||
699 | |||
700 | if (atomic_read(&cam->in_reset) != 1) | ||
701 | goto out; | ||
702 | |||
703 | omap24xxcam_hwinit(cam); | ||
704 | |||
705 | omap24xxcam_sensor_if_enable(cam); | ||
706 | |||
707 | omap24xxcam_sgdma_process(&cam->sgdma); | ||
708 | |||
709 | if (cam->sgdma_in_queue) | ||
710 | omap24xxcam_core_enable(cam); | ||
711 | |||
712 | out: | ||
713 | atomic_dec(&cam->in_reset); | ||
714 | spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags); | ||
715 | } | ||
716 | |||
717 | static ssize_t | ||
718 | omap24xxcam_streaming_show(struct device *dev, struct device_attribute *attr, | ||
719 | char *buf) | ||
720 | { | ||
721 | struct omap24xxcam_device *cam = dev_get_drvdata(dev); | ||
722 | |||
723 | return sprintf(buf, "%s\n", cam->streaming ? "active" : "inactive"); | ||
724 | } | ||
725 | static DEVICE_ATTR(streaming, S_IRUGO, omap24xxcam_streaming_show, NULL); | ||
726 | |||
727 | /* | ||
728 | * Stop capture and restart it. I.e. reset the camera during use. | ||
729 | */ | ||
730 | static void omap24xxcam_reset(struct omap24xxcam_device *cam) | ||
731 | { | ||
732 | omap24xxcam_capture_stop(cam); | ||
733 | omap24xxcam_capture_cont(cam); | ||
734 | } | ||
735 | |||
736 | /* | ||
737 | * The main interrupt handler. | ||
738 | */ | ||
739 | static irqreturn_t omap24xxcam_isr(int irq, void *arg) | ||
740 | { | ||
741 | struct omap24xxcam_device *cam = (struct omap24xxcam_device *)arg; | ||
742 | u32 irqstatus; | ||
743 | unsigned int irqhandled = 0; | ||
744 | |||
745 | irqstatus = omap24xxcam_reg_in(cam->mmio_base, CAM_IRQSTATUS); | ||
746 | |||
747 | if (irqstatus & | ||
748 | (CAM_IRQSTATUS_DMA_IRQ2 | CAM_IRQSTATUS_DMA_IRQ1 | ||
749 | | CAM_IRQSTATUS_DMA_IRQ0)) { | ||
750 | omap24xxcam_dma_isr(&cam->sgdma.dma); | ||
751 | irqhandled = 1; | ||
752 | } | ||
753 | if (irqstatus & CAM_IRQSTATUS_CC_IRQ) { | ||
754 | omap24xxcam_core_isr(cam); | ||
755 | irqhandled = 1; | ||
756 | } | ||
757 | if (irqstatus & CAM_IRQSTATUS_MMU_IRQ) | ||
758 | dev_err(cam->dev, "unhandled camera MMU interrupt!\n"); | ||
759 | |||
760 | return IRQ_RETVAL(irqhandled); | ||
761 | } | ||
762 | |||
763 | /* | ||
764 | * | ||
765 | * Sensor handling. | ||
766 | * | ||
767 | */ | ||
768 | |||
769 | /* | ||
770 | * Enable the external sensor interface. Try to negotiate interface | ||
771 | * parameters with the sensor and start using the new ones. The calls | ||
772 | * to sensor_if_enable and sensor_if_disable need not to be balanced. | ||
773 | */ | ||
774 | static int omap24xxcam_sensor_if_enable(struct omap24xxcam_device *cam) | ||
775 | { | ||
776 | int rval; | ||
777 | struct v4l2_ifparm p; | ||
778 | |||
779 | rval = vidioc_int_g_ifparm(cam->sdev, &p); | ||
780 | if (rval) { | ||
781 | dev_err(cam->dev, "vidioc_int_g_ifparm failed with %d\n", rval); | ||
782 | return rval; | ||
783 | } | ||
784 | |||
785 | cam->if_type = p.if_type; | ||
786 | |||
787 | cam->cc_ctrl = CC_CTRL_CC_EN; | ||
788 | |||
789 | switch (p.if_type) { | ||
790 | case V4L2_IF_TYPE_BT656: | ||
791 | if (p.u.bt656.frame_start_on_rising_vs) | ||
792 | cam->cc_ctrl |= CC_CTRL_NOBT_SYNCHRO; | ||
793 | if (p.u.bt656.bt_sync_correct) | ||
794 | cam->cc_ctrl |= CC_CTRL_BT_CORRECT; | ||
795 | if (p.u.bt656.swap) | ||
796 | cam->cc_ctrl |= CC_CTRL_PAR_ORDERCAM; | ||
797 | if (p.u.bt656.latch_clk_inv) | ||
798 | cam->cc_ctrl |= CC_CTRL_PAR_CLK_POL; | ||
799 | if (p.u.bt656.nobt_hs_inv) | ||
800 | cam->cc_ctrl |= CC_CTRL_NOBT_HS_POL; | ||
801 | if (p.u.bt656.nobt_vs_inv) | ||
802 | cam->cc_ctrl |= CC_CTRL_NOBT_VS_POL; | ||
803 | |||
804 | switch (p.u.bt656.mode) { | ||
805 | case V4L2_IF_TYPE_BT656_MODE_NOBT_8BIT: | ||
806 | cam->cc_ctrl |= CC_CTRL_PAR_MODE_NOBT8; | ||
807 | break; | ||
808 | case V4L2_IF_TYPE_BT656_MODE_NOBT_10BIT: | ||
809 | cam->cc_ctrl |= CC_CTRL_PAR_MODE_NOBT10; | ||
810 | break; | ||
811 | case V4L2_IF_TYPE_BT656_MODE_NOBT_12BIT: | ||
812 | cam->cc_ctrl |= CC_CTRL_PAR_MODE_NOBT12; | ||
813 | break; | ||
814 | case V4L2_IF_TYPE_BT656_MODE_BT_8BIT: | ||
815 | cam->cc_ctrl |= CC_CTRL_PAR_MODE_BT8; | ||
816 | break; | ||
817 | case V4L2_IF_TYPE_BT656_MODE_BT_10BIT: | ||
818 | cam->cc_ctrl |= CC_CTRL_PAR_MODE_BT10; | ||
819 | break; | ||
820 | default: | ||
821 | dev_err(cam->dev, | ||
822 | "bt656 interface mode %d not supported\n", | ||
823 | p.u.bt656.mode); | ||
824 | return -EINVAL; | ||
825 | } | ||
826 | /* | ||
827 | * The clock rate that the sensor wants has changed. | ||
828 | * We have to adjust the xclk from OMAP 2 side to | ||
829 | * match the sensor's wish as closely as possible. | ||
830 | */ | ||
831 | if (p.u.bt656.clock_curr != cam->if_u.bt656.xclk) { | ||
832 | u32 xclk = p.u.bt656.clock_curr; | ||
833 | u32 divisor; | ||
834 | |||
835 | if (xclk == 0) | ||
836 | return -EINVAL; | ||
837 | |||
838 | if (xclk > CAM_MCLK) | ||
839 | xclk = CAM_MCLK; | ||
840 | |||
841 | divisor = CAM_MCLK / xclk; | ||
842 | if (divisor * xclk < CAM_MCLK) | ||
843 | divisor++; | ||
844 | if (CAM_MCLK / divisor < p.u.bt656.clock_min | ||
845 | && divisor > 1) | ||
846 | divisor--; | ||
847 | if (divisor > 30) | ||
848 | divisor = 30; | ||
849 | |||
850 | xclk = CAM_MCLK / divisor; | ||
851 | |||
852 | if (xclk < p.u.bt656.clock_min | ||
853 | || xclk > p.u.bt656.clock_max) | ||
854 | return -EINVAL; | ||
855 | |||
856 | cam->if_u.bt656.xclk = xclk; | ||
857 | } | ||
858 | omap24xxcam_core_xclk_set(cam, cam->if_u.bt656.xclk); | ||
859 | break; | ||
860 | default: | ||
861 | /* FIXME: how about other interfaces? */ | ||
862 | dev_err(cam->dev, "interface type %d not supported\n", | ||
863 | p.if_type); | ||
864 | return -EINVAL; | ||
865 | } | ||
866 | |||
867 | return 0; | ||
868 | } | ||
869 | |||
870 | static void omap24xxcam_sensor_if_disable(const struct omap24xxcam_device *cam) | ||
871 | { | ||
872 | switch (cam->if_type) { | ||
873 | case V4L2_IF_TYPE_BT656: | ||
874 | omap24xxcam_core_xclk_set(cam, 0); | ||
875 | break; | ||
876 | } | ||
877 | } | ||
878 | |||
879 | /* | ||
880 | * Initialise the sensor hardware. | ||
881 | */ | ||
882 | static int omap24xxcam_sensor_init(struct omap24xxcam_device *cam) | ||
883 | { | ||
884 | int err = 0; | ||
885 | struct v4l2_int_device *sdev = cam->sdev; | ||
886 | |||
887 | omap24xxcam_clock_on(cam); | ||
888 | err = omap24xxcam_sensor_if_enable(cam); | ||
889 | if (err) { | ||
890 | dev_err(cam->dev, "sensor interface could not be enabled at " | ||
891 | "initialisation, %d\n", err); | ||
892 | cam->sdev = NULL; | ||
893 | goto out; | ||
894 | } | ||
895 | |||
896 | /* power up sensor during sensor initialization */ | ||
897 | vidioc_int_s_power(sdev, 1); | ||
898 | |||
899 | err = vidioc_int_dev_init(sdev); | ||
900 | if (err) { | ||
901 | dev_err(cam->dev, "cannot initialize sensor, error %d\n", err); | ||
902 | /* Sensor init failed --- it's nonexistent to us! */ | ||
903 | cam->sdev = NULL; | ||
904 | goto out; | ||
905 | } | ||
906 | |||
907 | dev_info(cam->dev, "sensor is %s\n", sdev->name); | ||
908 | |||
909 | out: | ||
910 | omap24xxcam_sensor_if_disable(cam); | ||
911 | omap24xxcam_clock_off(cam); | ||
912 | |||
913 | vidioc_int_s_power(sdev, 0); | ||
914 | |||
915 | return err; | ||
916 | } | ||
917 | |||
918 | static void omap24xxcam_sensor_exit(struct omap24xxcam_device *cam) | ||
919 | { | ||
920 | if (cam->sdev) | ||
921 | vidioc_int_dev_exit(cam->sdev); | ||
922 | } | ||
923 | |||
924 | static void omap24xxcam_sensor_disable(struct omap24xxcam_device *cam) | ||
925 | { | ||
926 | omap24xxcam_sensor_if_disable(cam); | ||
927 | omap24xxcam_clock_off(cam); | ||
928 | vidioc_int_s_power(cam->sdev, 0); | ||
929 | } | ||
930 | |||
931 | /* | ||
932 | * Power-up and configure camera sensor. It's ready for capturing now. | ||
933 | */ | ||
934 | static int omap24xxcam_sensor_enable(struct omap24xxcam_device *cam) | ||
935 | { | ||
936 | int rval; | ||
937 | |||
938 | omap24xxcam_clock_on(cam); | ||
939 | |||
940 | omap24xxcam_sensor_if_enable(cam); | ||
941 | |||
942 | rval = vidioc_int_s_power(cam->sdev, 1); | ||
943 | if (rval) | ||
944 | goto out; | ||
945 | |||
946 | rval = vidioc_int_init(cam->sdev); | ||
947 | if (rval) | ||
948 | goto out; | ||
949 | |||
950 | return 0; | ||
951 | |||
952 | out: | ||
953 | omap24xxcam_sensor_disable(cam); | ||
954 | |||
955 | return rval; | ||
956 | } | ||
957 | |||
958 | static void omap24xxcam_sensor_reset_work(struct work_struct *work) | ||
959 | { | ||
960 | struct omap24xxcam_device *cam = | ||
961 | container_of(work, struct omap24xxcam_device, | ||
962 | sensor_reset_work); | ||
963 | |||
964 | if (atomic_read(&cam->reset_disable)) | ||
965 | return; | ||
966 | |||
967 | omap24xxcam_capture_stop(cam); | ||
968 | |||
969 | if (vidioc_int_reset(cam->sdev) == 0) { | ||
970 | vidioc_int_init(cam->sdev); | ||
971 | } else { | ||
972 | /* Can't reset it by vidioc_int_reset. */ | ||
973 | omap24xxcam_sensor_disable(cam); | ||
974 | omap24xxcam_sensor_enable(cam); | ||
975 | } | ||
976 | |||
977 | omap24xxcam_capture_cont(cam); | ||
978 | } | ||
979 | |||
980 | /* | ||
981 | * | ||
982 | * IOCTL interface. | ||
983 | * | ||
984 | */ | ||
985 | |||
986 | static int vidioc_querycap(struct file *file, void *fh, | ||
987 | struct v4l2_capability *cap) | ||
988 | { | ||
989 | struct omap24xxcam_fh *ofh = fh; | ||
990 | struct omap24xxcam_device *cam = ofh->cam; | ||
991 | |||
992 | strlcpy(cap->driver, CAM_NAME, sizeof(cap->driver)); | ||
993 | strlcpy(cap->card, cam->vfd->name, sizeof(cap->card)); | ||
994 | cap->version = OMAP24XXCAM_VERSION; | ||
995 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; | ||
996 | |||
997 | return 0; | ||
998 | } | ||
999 | |||
1000 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, | ||
1001 | struct v4l2_fmtdesc *f) | ||
1002 | { | ||
1003 | struct omap24xxcam_fh *ofh = fh; | ||
1004 | struct omap24xxcam_device *cam = ofh->cam; | ||
1005 | int rval; | ||
1006 | |||
1007 | rval = vidioc_int_enum_fmt_cap(cam->sdev, f); | ||
1008 | |||
1009 | return rval; | ||
1010 | } | ||
1011 | |||
1012 | static int vidioc_g_fmt_vid_cap(struct file *file, void *fh, | ||
1013 | struct v4l2_format *f) | ||
1014 | { | ||
1015 | struct omap24xxcam_fh *ofh = fh; | ||
1016 | struct omap24xxcam_device *cam = ofh->cam; | ||
1017 | int rval; | ||
1018 | |||
1019 | mutex_lock(&cam->mutex); | ||
1020 | rval = vidioc_int_g_fmt_cap(cam->sdev, f); | ||
1021 | mutex_unlock(&cam->mutex); | ||
1022 | |||
1023 | return rval; | ||
1024 | } | ||
1025 | |||
1026 | static int vidioc_s_fmt_vid_cap(struct file *file, void *fh, | ||
1027 | struct v4l2_format *f) | ||
1028 | { | ||
1029 | struct omap24xxcam_fh *ofh = fh; | ||
1030 | struct omap24xxcam_device *cam = ofh->cam; | ||
1031 | int rval; | ||
1032 | |||
1033 | mutex_lock(&cam->mutex); | ||
1034 | if (cam->streaming) { | ||
1035 | rval = -EBUSY; | ||
1036 | goto out; | ||
1037 | } | ||
1038 | |||
1039 | rval = vidioc_int_s_fmt_cap(cam->sdev, f); | ||
1040 | |||
1041 | out: | ||
1042 | mutex_unlock(&cam->mutex); | ||
1043 | |||
1044 | if (!rval) { | ||
1045 | mutex_lock(&ofh->vbq.vb_lock); | ||
1046 | ofh->pix = f->fmt.pix; | ||
1047 | mutex_unlock(&ofh->vbq.vb_lock); | ||
1048 | } | ||
1049 | |||
1050 | memset(f, 0, sizeof(*f)); | ||
1051 | vidioc_g_fmt_vid_cap(file, fh, f); | ||
1052 | |||
1053 | return rval; | ||
1054 | } | ||
1055 | |||
1056 | static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, | ||
1057 | struct v4l2_format *f) | ||
1058 | { | ||
1059 | struct omap24xxcam_fh *ofh = fh; | ||
1060 | struct omap24xxcam_device *cam = ofh->cam; | ||
1061 | int rval; | ||
1062 | |||
1063 | mutex_lock(&cam->mutex); | ||
1064 | rval = vidioc_int_try_fmt_cap(cam->sdev, f); | ||
1065 | mutex_unlock(&cam->mutex); | ||
1066 | |||
1067 | return rval; | ||
1068 | } | ||
1069 | |||
1070 | static int vidioc_reqbufs(struct file *file, void *fh, | ||
1071 | struct v4l2_requestbuffers *b) | ||
1072 | { | ||
1073 | struct omap24xxcam_fh *ofh = fh; | ||
1074 | struct omap24xxcam_device *cam = ofh->cam; | ||
1075 | int rval; | ||
1076 | |||
1077 | mutex_lock(&cam->mutex); | ||
1078 | if (cam->streaming) { | ||
1079 | mutex_unlock(&cam->mutex); | ||
1080 | return -EBUSY; | ||
1081 | } | ||
1082 | |||
1083 | omap24xxcam_vbq_free_mmap_buffers(&ofh->vbq); | ||
1084 | mutex_unlock(&cam->mutex); | ||
1085 | |||
; /* entry inode number */ int newsize; /* new inode size */ xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ xfs_dir2_sf_t *oldsfp; /* old sf directory */ int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_t *sfp; /* new sf directory */ trace_xfs_dir2_sf_toino4(args); dp = args->dp; /* * Copy the old directory to the buffer. * Then nuke it from the inode, and add the new buffer to the inode. * Don't want xfs_idata_realloc copying the data here. */ oldsize = dp->i_df.if_bytes; buf = kmem_alloc(oldsize, KM_SLEEP); oldsfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data; ASSERT(oldsfp->hdr.i8count == 1); memcpy(buf, oldsfp, oldsize); /* * Compute the new inode size. */ newsize = oldsize - (oldsfp->hdr.count + 1) * ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)); xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); /* * Reset our pointers, the data has moved. */ oldsfp = (xfs_dir2_sf_t *)buf; sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data; /* * Fill in the new header. */ sfp->hdr.count = oldsfp->hdr.count; sfp->hdr.i8count = 0; ino = xfs_dir2_sf_get_inumber(oldsfp, &oldsfp->hdr.parent); xfs_dir2_sf_put_inumber(sfp, &ino, &sfp->hdr.parent); /* * Copy the entries field by field. */ for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp), oldsfep = xfs_dir2_sf_firstentry(oldsfp); i < sfp->hdr.count; i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep), oldsfep = xfs_dir2_sf_nextentry(oldsfp, oldsfep)) { sfep->namelen = oldsfep->namelen; sfep->offset = oldsfep->offset; memcpy(sfep->name, oldsfep->name, sfep->namelen); ino = xfs_dir2_sf_get_inumber(oldsfp, xfs_dir2_sf_inumberp(oldsfep)); xfs_dir2_sf_put_inumber(sfp, &ino, xfs_dir2_sf_inumberp(sfep)); } /* * Clean up the inode. */ kmem_free(buf); dp->i_d.di_size = newsize; xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); } /* * Convert from 4-byte inode numbers to 8-byte inode numbers. * The new 8-byte inode number is not there yet, we leave with the * count 1 but no corresponding entry. */ static void xfs_dir2_sf_toino8( xfs_da_args_t *args) /* operation arguments */ { char *buf; /* old dir's buffer */ xfs_inode_t *dp; /* incore directory inode */ int i; /* entry index */ xfs_ino_t ino; /* entry inode number */ int newsize; /* new inode size */ xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ xfs_dir2_sf_t *oldsfp; /* old sf directory */ int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_t *sfp; /* new sf directory */ trace_xfs_dir2_sf_toino8(args); dp = args->dp; /* * Copy the old directory to the buffer. * Then nuke it from the inode, and add the new buffer to the inode. * Don't want xfs_idata_realloc copying the data here. */ oldsize = dp->i_df.if_bytes; buf = kmem_alloc(oldsize, KM_SLEEP); oldsfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data; ASSERT(oldsfp->hdr.i8count == 0); memcpy(buf, oldsfp, oldsize); /* * Compute the new inode size. */ newsize = oldsize + (oldsfp->hdr.count + 1) * ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)); xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); /* * Reset our pointers, the data has moved. */ oldsfp = (xfs_dir2_sf_t *)buf; sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data; /* * Fill in the new header. */ sfp->hdr.count = oldsfp->hdr.count; sfp->hdr.i8count = 1; ino = xfs_dir2_sf_get_inumber(oldsfp, &oldsfp->hdr.parent); xfs_dir2_sf_put_inumber(sfp, &ino, &sfp->hdr.parent); /* * Copy the entries field by field. */ for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp), oldsfep = xfs_dir2_sf_firstentry(oldsfp); i < sfp->hdr.count; i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep), oldsfep = xfs_dir2_sf_nextentry(oldsfp, oldsfep)) { sfep->namelen = oldsfep->namelen; sfep->offset = oldsfep->offset; memcpy(sfep->name, oldsfep->name, sfep->namelen); ino = xfs_dir2_sf_get_inumber(oldsfp, xfs_dir2_sf_inumberp(oldsfep)); xfs_dir2_sf_put_inumber(sfp, &ino, xfs_dir2_sf_inumberp(sfep)); } /* * Clean up the inode. */ kmem_free(buf); dp->i_d.di_size = newsize; xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); } #endif /* XFS_BIG_INUMS */ |