1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/module.h>
15#include <linux/uaccess.h>
16#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/dma-mapping.h>
19#include <linux/mm.h>
20#include <linux/sched.h>
21#include <linux/slab.h>
22#include <media/v4l2-event.h>
23
24#include "isp.h"
25#include "ispreg.h"
26#include "ispccdc.h"
27
28#define CCDC_MIN_WIDTH 32
29#define CCDC_MIN_HEIGHT 32
30
31static struct v4l2_mbus_framefmt *
32__ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg,
33 unsigned int pad, enum v4l2_subdev_format_whence which);
34
35static const unsigned int ccdc_fmts[] = {
36 MEDIA_BUS_FMT_Y8_1X8,
37 MEDIA_BUS_FMT_Y10_1X10,
38 MEDIA_BUS_FMT_Y12_1X12,
39 MEDIA_BUS_FMT_SGRBG8_1X8,
40 MEDIA_BUS_FMT_SRGGB8_1X8,
41 MEDIA_BUS_FMT_SBGGR8_1X8,
42 MEDIA_BUS_FMT_SGBRG8_1X8,
43 MEDIA_BUS_FMT_SGRBG10_1X10,
44 MEDIA_BUS_FMT_SRGGB10_1X10,
45 MEDIA_BUS_FMT_SBGGR10_1X10,
46 MEDIA_BUS_FMT_SGBRG10_1X10,
47 MEDIA_BUS_FMT_SGRBG12_1X12,
48 MEDIA_BUS_FMT_SRGGB12_1X12,
49 MEDIA_BUS_FMT_SBGGR12_1X12,
50 MEDIA_BUS_FMT_SGBRG12_1X12,
51 MEDIA_BUS_FMT_YUYV8_2X8,
52 MEDIA_BUS_FMT_UYVY8_2X8,
53};
54
55
56
57
58
59
60
61#define CCDC_PRINT_REGISTER(isp, name)\
62 dev_dbg(isp->dev, "###CCDC " #name "=0x%08x\n", \
63 isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_##name))
64
65static void ccdc_print_status(struct isp_ccdc_device *ccdc)
66{
67 struct isp_device *isp = to_isp_device(ccdc);
68
69 dev_dbg(isp->dev, "-------------CCDC Register dump-------------\n");
70
71 CCDC_PRINT_REGISTER(isp, PCR);
72 CCDC_PRINT_REGISTER(isp, SYN_MODE);
73 CCDC_PRINT_REGISTER(isp, HD_VD_WID);
74 CCDC_PRINT_REGISTER(isp, PIX_LINES);
75 CCDC_PRINT_REGISTER(isp, HORZ_INFO);
76 CCDC_PRINT_REGISTER(isp, VERT_START);
77 CCDC_PRINT_REGISTER(isp, VERT_LINES);
78 CCDC_PRINT_REGISTER(isp, CULLING);
79 CCDC_PRINT_REGISTER(isp, HSIZE_OFF);
80 CCDC_PRINT_REGISTER(isp, SDOFST);
81 CCDC_PRINT_REGISTER(isp, SDR_ADDR);
82 CCDC_PRINT_REGISTER(isp, CLAMP);
83 CCDC_PRINT_REGISTER(isp, DCSUB);
84 CCDC_PRINT_REGISTER(isp, COLPTN);
85 CCDC_PRINT_REGISTER(isp, BLKCMP);
86 CCDC_PRINT_REGISTER(isp, FPC);
87 CCDC_PRINT_REGISTER(isp, FPC_ADDR);
88 CCDC_PRINT_REGISTER(isp, VDINT);
89 CCDC_PRINT_REGISTER(isp, ALAW);
90 CCDC_PRINT_REGISTER(isp, REC656IF);
91 CCDC_PRINT_REGISTER(isp, CFG);
92 CCDC_PRINT_REGISTER(isp, FMTCFG);
93 CCDC_PRINT_REGISTER(isp, FMT_HORZ);
94 CCDC_PRINT_REGISTER(isp, FMT_VERT);
95 CCDC_PRINT_REGISTER(isp, PRGEVEN0);
96 CCDC_PRINT_REGISTER(isp, PRGEVEN1);
97 CCDC_PRINT_REGISTER(isp, PRGODD0);
98 CCDC_PRINT_REGISTER(isp, PRGODD1);
99 CCDC_PRINT_REGISTER(isp, VP_OUT);
100 CCDC_PRINT_REGISTER(isp, LSC_CONFIG);
101 CCDC_PRINT_REGISTER(isp, LSC_INITIAL);
102 CCDC_PRINT_REGISTER(isp, LSC_TABLE_BASE);
103 CCDC_PRINT_REGISTER(isp, LSC_TABLE_OFFSET);
104
105 dev_dbg(isp->dev, "--------------------------------------------\n");
106}
107
108
109
110
111
112int omap3isp_ccdc_busy(struct isp_ccdc_device *ccdc)
113{
114 struct isp_device *isp = to_isp_device(ccdc);
115
116 return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR) &
117 ISPCCDC_PCR_BUSY;
118}
119
120
121
122
123
124
125
126
127
128
129
130
131static int ccdc_lsc_validate_config(struct isp_ccdc_device *ccdc,
132 struct omap3isp_ccdc_lsc_config *lsc_cfg)
133{
134 struct isp_device *isp = to_isp_device(ccdc);
135 struct v4l2_mbus_framefmt *format;
136 unsigned int paxel_width, paxel_height;
137 unsigned int paxel_shift_x, paxel_shift_y;
138 unsigned int min_width, min_height, min_size;
139 unsigned int input_width, input_height;
140
141 paxel_shift_x = lsc_cfg->gain_mode_m;
142 paxel_shift_y = lsc_cfg->gain_mode_n;
143
144 if ((paxel_shift_x < 2) || (paxel_shift_x > 6) ||
145 (paxel_shift_y < 2) || (paxel_shift_y > 6)) {
146 dev_dbg(isp->dev, "CCDC: LSC: Invalid paxel size\n");
147 return -EINVAL;
148 }
149
150 if (lsc_cfg->offset & 3) {
151 dev_dbg(isp->dev,
152 "CCDC: LSC: Offset must be a multiple of 4\n");
153 return -EINVAL;
154 }
155
156 if ((lsc_cfg->initial_x & 1) || (lsc_cfg->initial_y & 1)) {
157 dev_dbg(isp->dev, "CCDC: LSC: initial_x and y must be even\n");
158 return -EINVAL;
159 }
160
161 format = __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK,
162 V4L2_SUBDEV_FORMAT_ACTIVE);
163 input_width = format->width;
164 input_height = format->height;
165
166
167 paxel_width = 1 << paxel_shift_x;
168 min_width = ((input_width + lsc_cfg->initial_x + paxel_width - 1)
169 >> paxel_shift_x) + 1;
170
171 paxel_height = 1 << paxel_shift_y;
172 min_height = ((input_height + lsc_cfg->initial_y + paxel_height - 1)
173 >> paxel_shift_y) + 1;
174
175 min_size = 4 * min_width * min_height;
176 if (min_size > lsc_cfg->size) {
177 dev_dbg(isp->dev, "CCDC: LSC: too small table\n");
178 return -EINVAL;
179 }
180 if (lsc_cfg->offset < (min_width * 4)) {
181 dev_dbg(isp->dev, "CCDC: LSC: Offset is too small\n");
182 return -EINVAL;
183 }
184 if ((lsc_cfg->size / lsc_cfg->offset) < min_height) {
185 dev_dbg(isp->dev, "CCDC: LSC: Wrong size/offset combination\n");
186 return -EINVAL;
187 }
188 return 0;
189}
190
191
192
193
194
195static void ccdc_lsc_program_table(struct isp_ccdc_device *ccdc,
196 dma_addr_t addr)
197{
198 isp_reg_writel(to_isp_device(ccdc), addr,
199 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_TABLE_BASE);
200}
201
202
203
204
205
206static void ccdc_lsc_setup_regs(struct isp_ccdc_device *ccdc,
207 struct omap3isp_ccdc_lsc_config *cfg)
208{
209 struct isp_device *isp = to_isp_device(ccdc);
210 int reg;
211
212 isp_reg_writel(isp, cfg->offset, OMAP3_ISP_IOMEM_CCDC,
213 ISPCCDC_LSC_TABLE_OFFSET);
214
215 reg = 0;
216 reg |= cfg->gain_mode_n << ISPCCDC_LSC_GAIN_MODE_N_SHIFT;
217 reg |= cfg->gain_mode_m << ISPCCDC_LSC_GAIN_MODE_M_SHIFT;
218 reg |= cfg->gain_format << ISPCCDC_LSC_GAIN_FORMAT_SHIFT;
219 isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG);
220
221 reg = 0;
222 reg &= ~ISPCCDC_LSC_INITIAL_X_MASK;
223 reg |= cfg->initial_x << ISPCCDC_LSC_INITIAL_X_SHIFT;
224 reg &= ~ISPCCDC_LSC_INITIAL_Y_MASK;
225 reg |= cfg->initial_y << ISPCCDC_LSC_INITIAL_Y_SHIFT;
226 isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC,
227 ISPCCDC_LSC_INITIAL);
228}
229
230static int ccdc_lsc_wait_prefetch(struct isp_ccdc_device *ccdc)
231{
232 struct isp_device *isp = to_isp_device(ccdc);
233 unsigned int wait;
234
235 isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ,
236 OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
237
238
239 for (wait = 0; wait < 1000; wait++) {
240 if (isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS) &
241 IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ) {
242 isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ,
243 OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
244 return 0;
245 }
246
247 rmb();
248 udelay(1);
249 }
250
251 return -ETIMEDOUT;
252}
253
254
255
256
257
258
259static int __ccdc_lsc_enable(struct isp_ccdc_device *ccdc, int enable)
260{
261 struct isp_device *isp = to_isp_device(ccdc);
262 const struct v4l2_mbus_framefmt *format =
263 __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK,
264 V4L2_SUBDEV_FORMAT_ACTIVE);
265
266 if ((format->code != MEDIA_BUS_FMT_SGRBG10_1X10) &&
267 (format->code != MEDIA_BUS_FMT_SRGGB10_1X10) &&
268 (format->code != MEDIA_BUS_FMT_SBGGR10_1X10) &&
269 (format->code != MEDIA_BUS_FMT_SGBRG10_1X10))
270 return -EINVAL;
271
272 if (enable)
273 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_LSC_READ);
274
275 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG,
276 ISPCCDC_LSC_ENABLE, enable ? ISPCCDC_LSC_ENABLE : 0);
277
278 if (enable) {
279 if (ccdc_lsc_wait_prefetch(ccdc) < 0) {
280 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC,
281 ISPCCDC_LSC_CONFIG, ISPCCDC_LSC_ENABLE);
282 ccdc->lsc.state = LSC_STATE_STOPPED;
283 dev_warn(to_device(ccdc), "LSC prefetch timeout\n");
284 return -ETIMEDOUT;
285 }
286 ccdc->lsc.state = LSC_STATE_RUNNING;
287 } else {
288 ccdc->lsc.state = LSC_STATE_STOPPING;
289 }
290
291 return 0;
292}
293
294static int ccdc_lsc_busy(struct isp_ccdc_device *ccdc)
295{
296 struct isp_device *isp = to_isp_device(ccdc);
297
298 return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG) &
299 ISPCCDC_LSC_BUSY;
300}
301
302
303
304
305
306
307
308static int __ccdc_lsc_configure(struct isp_ccdc_device *ccdc,
309 struct ispccdc_lsc_config_req *req)
310{
311 if (!req->enable)
312 return -EINVAL;
313
314 if (ccdc_lsc_validate_config(ccdc, &req->config) < 0) {
315 dev_dbg(to_device(ccdc), "Discard LSC configuration\n");
316 return -EINVAL;
317 }
318
319 if (ccdc_lsc_busy(ccdc))
320 return -EBUSY;
321
322 ccdc_lsc_setup_regs(ccdc, &req->config);
323 ccdc_lsc_program_table(ccdc, req->table.dma);
324 return 0;
325}
326
327
328
329
330
331
332
333static void ccdc_lsc_error_handler(struct isp_ccdc_device *ccdc)
334{
335 struct isp_device *isp = to_isp_device(ccdc);
336
337
338
339
340
341
342
343
344
345 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG,
346 ISPCCDC_LSC_ENABLE);
347 ccdc->lsc.state = LSC_STATE_STOPPED;
348}
349
350static void ccdc_lsc_free_request(struct isp_ccdc_device *ccdc,
351 struct ispccdc_lsc_config_req *req)
352{
353 struct isp_device *isp = to_isp_device(ccdc);
354
355 if (req == NULL)
356 return;
357
358 if (req->table.addr) {
359 sg_free_table(&req->table.sgt);
360 dma_free_coherent(isp->dev, req->config.size, req->table.addr,
361 req->table.dma);
362 }
363
364 kfree(req);
365}
366
367static void ccdc_lsc_free_queue(struct isp_ccdc_device *ccdc,
368 struct list_head *queue)
369{
370 struct ispccdc_lsc_config_req *req, *n;
371 unsigned long flags;
372
373 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
374 list_for_each_entry_safe(req, n, queue, list) {
375 list_del(&req->list);
376 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
377 ccdc_lsc_free_request(ccdc, req);
378 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
379 }
380 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
381}
382
383static void ccdc_lsc_free_table_work(struct work_struct *work)
384{
385 struct isp_ccdc_device *ccdc;
386 struct ispccdc_lsc *lsc;
387
388 lsc = container_of(work, struct ispccdc_lsc, table_work);
389 ccdc = container_of(lsc, struct isp_ccdc_device, lsc);
390
391 ccdc_lsc_free_queue(ccdc, &lsc->free_queue);
392}
393
394
395
396
397
398
399
400
401static int ccdc_lsc_config(struct isp_ccdc_device *ccdc,
402 struct omap3isp_ccdc_update_config *config)
403{
404 struct isp_device *isp = to_isp_device(ccdc);
405 struct ispccdc_lsc_config_req *req;
406 unsigned long flags;
407 u16 update;
408 int ret;
409
410 update = config->update &
411 (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC);
412 if (!update)
413 return 0;
414
415 if (update != (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC)) {
416 dev_dbg(to_device(ccdc),
417 "%s: Both LSC configuration and table need to be supplied\n",
418 __func__);
419 return -EINVAL;
420 }
421
422 req = kzalloc(sizeof(*req), GFP_KERNEL);
423 if (req == NULL)
424 return -ENOMEM;
425
426 if (config->flag & OMAP3ISP_CCDC_CONFIG_LSC) {
427 if (copy_from_user(&req->config, config->lsc_cfg,
428 sizeof(req->config))) {
429 ret = -EFAULT;
430 goto done;
431 }
432
433 req->enable = 1;
434
435 req->table.addr = dma_alloc_coherent(isp->dev, req->config.size,
436 &req->table.dma,
437 GFP_KERNEL);
438 if (req->table.addr == NULL) {
439 ret = -ENOMEM;
440 goto done;
441 }
442
443 ret = dma_get_sgtable(isp->dev, &req->table.sgt,
444 req->table.addr, req->table.dma,
445 req->config.size);
446 if (ret < 0)
447 goto done;
448
449 dma_sync_sg_for_cpu(isp->dev, req->table.sgt.sgl,
450 req->table.sgt.nents, DMA_TO_DEVICE);
451
452 if (copy_from_user(req->table.addr, config->lsc,
453 req->config.size)) {
454 ret = -EFAULT;
455 goto done;
456 }
457
458 dma_sync_sg_for_device(isp->dev, req->table.sgt.sgl,
459 req->table.sgt.nents, DMA_TO_DEVICE);
460 }
461
462 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
463 if (ccdc->lsc.request) {
464 list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue);
465 schedule_work(&ccdc->lsc.table_work);
466 }
467 ccdc->lsc.request = req;
468 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
469
470 ret = 0;
471
472done:
473 if (ret < 0)
474 ccdc_lsc_free_request(ccdc, req);
475
476 return ret;
477}
478
479static inline int ccdc_lsc_is_configured(struct isp_ccdc_device *ccdc)
480{
481 unsigned long flags;
482 int ret;
483
484 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
485 ret = ccdc->lsc.active != NULL;
486 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
487
488 return ret;
489}
490
491static int ccdc_lsc_enable(struct isp_ccdc_device *ccdc)
492{
493 struct ispccdc_lsc *lsc = &ccdc->lsc;
494
495 if (lsc->state != LSC_STATE_STOPPED)
496 return -EINVAL;
497
498 if (lsc->active) {
499 list_add_tail(&lsc->active->list, &lsc->free_queue);
500 lsc->active = NULL;
501 }
502
503 if (__ccdc_lsc_configure(ccdc, lsc->request) < 0) {
504 omap3isp_sbl_disable(to_isp_device(ccdc),
505 OMAP3_ISP_SBL_CCDC_LSC_READ);
506 list_add_tail(&lsc->request->list, &lsc->free_queue);
507 lsc->request = NULL;
508 goto done;
509 }
510
511 lsc->active = lsc->request;
512 lsc->request = NULL;
513 __ccdc_lsc_enable(ccdc, 1);
514
515done:
516 if (!list_empty(&lsc->free_queue))
517 schedule_work(&lsc->table_work);
518
519 return 0;
520}
521
522
523
524
525
526
527
528
529
530
531
532
533static void ccdc_configure_clamp(struct isp_ccdc_device *ccdc)
534{
535 struct isp_device *isp = to_isp_device(ccdc);
536 u32 clamp;
537
538 if (ccdc->obclamp) {
539 clamp = ccdc->clamp.obgain << ISPCCDC_CLAMP_OBGAIN_SHIFT;
540 clamp |= ccdc->clamp.oblen << ISPCCDC_CLAMP_OBSLEN_SHIFT;
541 clamp |= ccdc->clamp.oblines << ISPCCDC_CLAMP_OBSLN_SHIFT;
542 clamp |= ccdc->clamp.obstpixel << ISPCCDC_CLAMP_OBST_SHIFT;
543 isp_reg_writel(isp, clamp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP);
544 } else {
545 isp_reg_writel(isp, ccdc->clamp.dcsubval,
546 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_DCSUB);
547 }
548
549 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP,
550 ISPCCDC_CLAMP_CLAMPEN,
551 ccdc->obclamp ? ISPCCDC_CLAMP_CLAMPEN : 0);
552}
553
554
555
556
557
558static void ccdc_configure_fpc(struct isp_ccdc_device *ccdc)
559{
560 struct isp_device *isp = to_isp_device(ccdc);
561
562 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC, ISPCCDC_FPC_FPCEN);
563
564 if (!ccdc->fpc_en)
565 return;
566
567 isp_reg_writel(isp, ccdc->fpc.dma, OMAP3_ISP_IOMEM_CCDC,
568 ISPCCDC_FPC_ADDR);
569
570 isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT),
571 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC);
572 isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT) |
573 ISPCCDC_FPC_FPCEN, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC);
574}
575
576
577
578
579
580static void ccdc_configure_black_comp(struct isp_ccdc_device *ccdc)
581{
582 struct isp_device *isp = to_isp_device(ccdc);
583 u32 blcomp;
584
585 blcomp = ccdc->blcomp.b_mg << ISPCCDC_BLKCMP_B_MG_SHIFT;
586 blcomp |= ccdc->blcomp.gb_g << ISPCCDC_BLKCMP_GB_G_SHIFT;
587 blcomp |= ccdc->blcomp.gr_cy << ISPCCDC_BLKCMP_GR_CY_SHIFT;
588 blcomp |= ccdc->blcomp.r_ye << ISPCCDC_BLKCMP_R_YE_SHIFT;
589
590 isp_reg_writel(isp, blcomp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_BLKCMP);
591}
592
593
594
595
596
597static void ccdc_configure_lpf(struct isp_ccdc_device *ccdc)
598{
599 struct isp_device *isp = to_isp_device(ccdc);
600
601 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE,
602 ISPCCDC_SYN_MODE_LPF,
603 ccdc->lpf ? ISPCCDC_SYN_MODE_LPF : 0);
604}
605
606
607
608
609
610static void ccdc_configure_alaw(struct isp_ccdc_device *ccdc)
611{
612 struct isp_device *isp = to_isp_device(ccdc);
613 const struct isp_format_info *info;
614 u32 alaw = 0;
615
616 info = omap3isp_video_format_info(ccdc->formats[CCDC_PAD_SINK].code);
617
618 switch (info->width) {
619 case 8:
620 return;
621
622 case 10:
623 alaw = ISPCCDC_ALAW_GWDI_9_0;
624 break;
625 case 11:
626 alaw = ISPCCDC_ALAW_GWDI_10_1;
627 break;
628 case 12:
629 alaw = ISPCCDC_ALAW_GWDI_11_2;
630 break;
631 case 13:
632 alaw = ISPCCDC_ALAW_GWDI_12_3;
633 break;
634 }
635
636 if (ccdc->alaw)
637 alaw |= ISPCCDC_ALAW_CCDTBL;
638
639 isp_reg_writel(isp, alaw, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_ALAW);
640}
641
642
643
644
645
646
647static void ccdc_config_imgattr(struct isp_ccdc_device *ccdc, u32 colptn)
648{
649 struct isp_device *isp = to_isp_device(ccdc);
650
651 isp_reg_writel(isp, colptn, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_COLPTN);
652}
653
654
655
656
657
658
659
660
661
662
663static int ccdc_config(struct isp_ccdc_device *ccdc,
664 struct omap3isp_ccdc_update_config *ccdc_struct)
665{
666 struct isp_device *isp = to_isp_device(ccdc);
667 unsigned long flags;
668
669 spin_lock_irqsave(&ccdc->lock, flags);
670 ccdc->shadow_update = 1;
671 spin_unlock_irqrestore(&ccdc->lock, flags);
672
673 if (OMAP3ISP_CCDC_ALAW & ccdc_struct->update) {
674 ccdc->alaw = !!(OMAP3ISP_CCDC_ALAW & ccdc_struct->flag);
675 ccdc->update |= OMAP3ISP_CCDC_ALAW;
676 }
677
678 if (OMAP3ISP_CCDC_LPF & ccdc_struct->update) {
679 ccdc->lpf = !!(OMAP3ISP_CCDC_LPF & ccdc_struct->flag);
680 ccdc->update |= OMAP3ISP_CCDC_LPF;
681 }
682
683 if (OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->update) {
684 if (copy_from_user(&ccdc->clamp, ccdc_struct->bclamp,
685 sizeof(ccdc->clamp))) {
686 ccdc->shadow_update = 0;
687 return -EFAULT;
688 }
689
690 ccdc->obclamp = !!(OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->flag);
691 ccdc->update |= OMAP3ISP_CCDC_BLCLAMP;
692 }
693
694 if (OMAP3ISP_CCDC_BCOMP & ccdc_struct->update) {
695 if (copy_from_user(&ccdc->blcomp, ccdc_struct->blcomp,
696 sizeof(ccdc->blcomp))) {
697 ccdc->shadow_update = 0;
698 return -EFAULT;
699 }
700
701 ccdc->update |= OMAP3ISP_CCDC_BCOMP;
702 }
703
704 ccdc->shadow_update = 0;
705
706 if (OMAP3ISP_CCDC_FPC & ccdc_struct->update) {
707 struct omap3isp_ccdc_fpc fpc;
708 struct ispccdc_fpc fpc_old = { .addr = NULL, };
709 struct ispccdc_fpc fpc_new;
710 u32 size;
711
712 if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED)
713 return -EBUSY;
714
715 ccdc->fpc_en = !!(OMAP3ISP_CCDC_FPC & ccdc_struct->flag);
716
717 if (ccdc->fpc_en) {
718 if (copy_from_user(&fpc, ccdc_struct->fpc, sizeof(fpc)))
719 return -EFAULT;
720
721 size = fpc.fpnum * 4;
722
723
724
725
726
727 fpc_new.fpnum = fpc.fpnum;
728 fpc_new.addr = dma_alloc_coherent(isp->dev, size,
729 &fpc_new.dma,
730 GFP_KERNEL);
731 if (fpc_new.addr == NULL)
732 return -ENOMEM;
733
734 if (copy_from_user(fpc_new.addr,
735 (__force void __user *)(long)fpc.fpcaddr,
736 size)) {
737 dma_free_coherent(isp->dev, size, fpc_new.addr,
738 fpc_new.dma);
739 return -EFAULT;
740 }
741
742 fpc_old = ccdc->fpc;
743 ccdc->fpc = fpc_new;
744 }
745
746 ccdc_configure_fpc(ccdc);
747
748 if (fpc_old.addr != NULL)
749 dma_free_coherent(isp->dev, fpc_old.fpnum * 4,
750 fpc_old.addr, fpc_old.dma);
751 }
752
753 return ccdc_lsc_config(ccdc, ccdc_struct);
754}
755
756static void ccdc_apply_controls(struct isp_ccdc_device *ccdc)
757{
758 if (ccdc->update & OMAP3ISP_CCDC_ALAW) {
759 ccdc_configure_alaw(ccdc);
760 ccdc->update &= ~OMAP3ISP_CCDC_ALAW;
761 }
762
763 if (ccdc->update & OMAP3ISP_CCDC_LPF) {
764 ccdc_configure_lpf(ccdc);
765 ccdc->update &= ~OMAP3ISP_CCDC_LPF;
766 }
767
768 if (ccdc->update & OMAP3ISP_CCDC_BLCLAMP) {
769 ccdc_configure_clamp(ccdc);
770 ccdc->update &= ~OMAP3ISP_CCDC_BLCLAMP;
771 }
772
773 if (ccdc->update & OMAP3ISP_CCDC_BCOMP) {
774 ccdc_configure_black_comp(ccdc);
775 ccdc->update &= ~OMAP3ISP_CCDC_BCOMP;
776 }
777}
778
779
780
781
782
783void omap3isp_ccdc_restore_context(struct isp_device *isp)
784{
785 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
786
787 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, ISPCCDC_CFG_VDLC);
788
789 ccdc->update = OMAP3ISP_CCDC_ALAW | OMAP3ISP_CCDC_LPF
790 | OMAP3ISP_CCDC_BLCLAMP | OMAP3ISP_CCDC_BCOMP;
791 ccdc_apply_controls(ccdc);
792 ccdc_configure_fpc(ccdc);
793}
794
795
796
797
798
799
800
801
802
803static void ccdc_config_vp(struct isp_ccdc_device *ccdc)
804{
805 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
806 struct isp_device *isp = to_isp_device(ccdc);
807 const struct isp_format_info *info;
808 struct v4l2_mbus_framefmt *format;
809 unsigned long l3_ick = pipe->l3_ick;
810 unsigned int max_div = isp->revision == ISP_REVISION_15_0 ? 64 : 8;
811 unsigned int div = 0;
812 u32 fmtcfg = ISPCCDC_FMTCFG_VPEN;
813
814 format = &ccdc->formats[CCDC_PAD_SOURCE_VP];
815
816 if (!format->code) {
817
818
819
820 isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG);
821 return;
822 }
823
824 isp_reg_writel(isp, (0 << ISPCCDC_FMT_HORZ_FMTSPH_SHIFT) |
825 (format->width << ISPCCDC_FMT_HORZ_FMTLNH_SHIFT),
826 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_HORZ);
827 isp_reg_writel(isp, (0 << ISPCCDC_FMT_VERT_FMTSLV_SHIFT) |
828 ((format->height + 1) << ISPCCDC_FMT_VERT_FMTLNV_SHIFT),
829 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_VERT);
830
831 isp_reg_writel(isp, (format->width << ISPCCDC_VP_OUT_HORZ_NUM_SHIFT) |
832 (format->height << ISPCCDC_VP_OUT_VERT_NUM_SHIFT),
833 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VP_OUT);
834
835 info = omap3isp_video_format_info(ccdc->formats[CCDC_PAD_SINK].code);
836
837 switch (info->width) {
838 case 8:
839 case 10:
840 fmtcfg |= ISPCCDC_FMTCFG_VPIN_9_0;
841 break;
842 case 11:
843 fmtcfg |= ISPCCDC_FMTCFG_VPIN_10_1;
844 break;
845 case 12:
846 fmtcfg |= ISPCCDC_FMTCFG_VPIN_11_2;
847 break;
848 case 13:
849 fmtcfg |= ISPCCDC_FMTCFG_VPIN_12_3;
850 break;
851 }
852
853 if (pipe->input)
854 div = DIV_ROUND_UP(l3_ick, pipe->max_rate);
855 else if (pipe->external_rate)
856 div = l3_ick / pipe->external_rate;
857
858 div = clamp(div, 2U, max_div);
859 fmtcfg |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT;
860
861 isp_reg_writel(isp, fmtcfg, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG);
862}
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884static void ccdc_config_outlineoffset(struct isp_ccdc_device *ccdc,
885 unsigned int bpl,
886 enum v4l2_field field)
887{
888 struct isp_device *isp = to_isp_device(ccdc);
889 u32 sdofst = 0;
890
891 isp_reg_writel(isp, bpl & 0xffff, OMAP3_ISP_IOMEM_CCDC,
892 ISPCCDC_HSIZE_OFF);
893
894 switch (field) {
895 case V4L2_FIELD_INTERLACED_TB:
896 case V4L2_FIELD_INTERLACED_BT:
897
898
899
900 sdofst |= (1 << ISPCCDC_SDOFST_LOFST0_SHIFT)
901 | (1 << ISPCCDC_SDOFST_LOFST1_SHIFT)
902 | (1 << ISPCCDC_SDOFST_LOFST2_SHIFT)
903 | (1 << ISPCCDC_SDOFST_LOFST3_SHIFT);
904 break;
905
906 default:
907
908 break;
909 }
910
911 isp_reg_writel(isp, sdofst, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST);
912}
913
914
915
916
917
918
919
920
921static void ccdc_set_outaddr(struct isp_ccdc_device *ccdc, u32 addr)
922{
923 struct isp_device *isp = to_isp_device(ccdc);
924
925 isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDR_ADDR);
926}
927
928
929
930
931
932
933
934
935void omap3isp_ccdc_max_rate(struct isp_ccdc_device *ccdc,
936 unsigned int *max_rate)
937{
938 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
939 unsigned int rate;
940
941 if (pipe == NULL)
942 return;
943
944
945
946
947
948 if (ccdc->input == CCDC_INPUT_PARALLEL)
949 rate = pipe->l3_ick / 2 * 9 / 10;
950 else
951 rate = pipe->l3_ick / 2;
952
953 *max_rate = min(*max_rate, rate);
954}
955
956
957
958
959
960
961
962static void ccdc_config_sync_if(struct isp_ccdc_device *ccdc,
963 struct isp_parallel_cfg *parcfg,
964 unsigned int data_size)
965{
966 struct isp_device *isp = to_isp_device(ccdc);
967 const struct v4l2_mbus_framefmt *format;
968 u32 syn_mode = ISPCCDC_SYN_MODE_VDHDEN;
969
970 format = &ccdc->formats[CCDC_PAD_SINK];
971
972 if (format->code == MEDIA_BUS_FMT_YUYV8_2X8 ||
973 format->code == MEDIA_BUS_FMT_UYVY8_2X8) {
974
975
976
977
978
979
980 if (ccdc->bt656)
981 syn_mode |= ISPCCDC_SYN_MODE_INPMOD_YCBCR8;
982 else
983 syn_mode |= ISPCCDC_SYN_MODE_INPMOD_YCBCR16;
984 }
985
986 switch (data_size) {
987 case 8:
988 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_8;
989 break;
990 case 10:
991 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_10;
992 break;
993 case 11:
994 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_11;
995 break;
996 case 12:
997 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_12;
998 break;
999 }
1000
1001 if (parcfg && parcfg->data_pol)
1002 syn_mode |= ISPCCDC_SYN_MODE_DATAPOL;
1003
1004 if (parcfg && parcfg->hs_pol)
1005 syn_mode |= ISPCCDC_SYN_MODE_HDPOL;
1006
1007
1008
1009
1010 if ((parcfg && parcfg->vs_pol) || ccdc->bt656)
1011 syn_mode |= ISPCCDC_SYN_MODE_VDPOL;
1012
1013 if (parcfg && parcfg->fld_pol)
1014 syn_mode |= ISPCCDC_SYN_MODE_FLDPOL;
1015
1016 isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
1017
1018
1019
1020
1021 if (format->code == MEDIA_BUS_FMT_UYVY8_2X8)
1022 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1023 ISPCCDC_CFG_Y8POS);
1024 else
1025 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1026 ISPCCDC_CFG_Y8POS);
1027
1028
1029
1030
1031 if (ccdc->bt656)
1032 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_REC656IF,
1033 ISPCCDC_REC656IF_R656ON | ISPCCDC_REC656IF_ECCFVH);
1034 else
1035 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_REC656IF,
1036 ISPCCDC_REC656IF_R656ON | ISPCCDC_REC656IF_ECCFVH);
1037
1038}
1039
1040
1041static const u32 ccdc_sgrbg_pattern =
1042 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1043 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1044 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1045 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1046 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1047 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1048 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1049 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1050 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1051 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1052 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1053 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1054 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1055 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1056 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1057 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1058
1059static const u32 ccdc_srggb_pattern =
1060 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1061 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1062 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1063 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1064 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1065 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1066 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1067 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1068 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1069 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1070 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1071 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1072 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1073 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1074 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1075 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1076
1077static const u32 ccdc_sbggr_pattern =
1078 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1079 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1080 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1081 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1082 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1083 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1084 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1085 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1086 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1087 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1088 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1089 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1090 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1091 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1092 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1093 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1094
1095static const u32 ccdc_sgbrg_pattern =
1096 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1097 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1098 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1099 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1100 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1101 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1102 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1103 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1104 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1105 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1106 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1107 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1108 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1109 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1110 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1111 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1112
1113static void ccdc_configure(struct isp_ccdc_device *ccdc)
1114{
1115 struct isp_device *isp = to_isp_device(ccdc);
1116 struct isp_parallel_cfg *parcfg = NULL;
1117 struct v4l2_subdev *sensor;
1118 struct v4l2_mbus_framefmt *format;
1119 const struct v4l2_rect *crop;
1120 const struct isp_format_info *fmt_info;
1121 struct v4l2_subdev_format fmt_src;
1122 unsigned int depth_out;
1123 unsigned int depth_in = 0;
1124 struct media_pad *pad;
1125 unsigned long flags;
1126 unsigned int bridge;
1127 unsigned int shift;
1128 unsigned int nph;
1129 unsigned int sph;
1130 u32 syn_mode;
1131 u32 ccdc_pattern;
1132
1133 ccdc->bt656 = false;
1134 ccdc->fields = 0;
1135
1136 pad = media_entity_remote_pad(&ccdc->pads[CCDC_PAD_SINK]);
1137 sensor = media_entity_to_v4l2_subdev(pad->entity);
1138 if (ccdc->input == CCDC_INPUT_PARALLEL) {
1139 struct v4l2_subdev *sd =
1140 to_isp_pipeline(&ccdc->subdev.entity)->external;
1141
1142 parcfg = &v4l2_subdev_to_bus_cfg(sd)->bus.parallel;
1143 ccdc->bt656 = parcfg->bt656;
1144 }
1145
1146
1147 format = &ccdc->formats[CCDC_PAD_SINK];
1148
1149
1150
1151
1152 fmt_src.pad = pad->index;
1153 fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1154 if (!v4l2_subdev_call(sensor, pad, get_fmt, NULL, &fmt_src)) {
1155 fmt_info = omap3isp_video_format_info(fmt_src.format.code);
1156 depth_in = fmt_info->width;
1157 }
1158
1159 fmt_info = omap3isp_video_format_info(format->code);
1160 depth_out = fmt_info->width;
1161 shift = depth_in - depth_out;
1162
1163 if (ccdc->bt656)
1164 bridge = ISPCTRL_PAR_BRIDGE_DISABLE;
1165 else if (fmt_info->code == MEDIA_BUS_FMT_YUYV8_2X8)
1166 bridge = ISPCTRL_PAR_BRIDGE_LENDIAN;
1167 else if (fmt_info->code == MEDIA_BUS_FMT_UYVY8_2X8)
1168 bridge = ISPCTRL_PAR_BRIDGE_BENDIAN;
1169 else
1170 bridge = ISPCTRL_PAR_BRIDGE_DISABLE;
1171
1172 omap3isp_configure_bridge(isp, ccdc->input, parcfg, shift, bridge);
1173
1174
1175 ccdc_config_sync_if(ccdc, parcfg, depth_out);
1176
1177 syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
1178
1179
1180
1181
1182 syn_mode &= ~ISPCCDC_SYN_MODE_VP2SDR;
1183
1184 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1185 syn_mode |= ISPCCDC_SYN_MODE_WEN;
1186 else
1187 syn_mode &= ~ISPCCDC_SYN_MODE_WEN;
1188
1189 if (ccdc->output & CCDC_OUTPUT_RESIZER)
1190 syn_mode |= ISPCCDC_SYN_MODE_SDR2RSZ;
1191 else
1192 syn_mode &= ~ISPCCDC_SYN_MODE_SDR2RSZ;
1193
1194
1195 switch (format->code) {
1196 case MEDIA_BUS_FMT_SRGGB10_1X10:
1197 case MEDIA_BUS_FMT_SRGGB12_1X12:
1198 ccdc_pattern = ccdc_srggb_pattern;
1199 break;
1200 case MEDIA_BUS_FMT_SBGGR10_1X10:
1201 case MEDIA_BUS_FMT_SBGGR12_1X12:
1202 ccdc_pattern = ccdc_sbggr_pattern;
1203 break;
1204 case MEDIA_BUS_FMT_SGBRG10_1X10:
1205 case MEDIA_BUS_FMT_SGBRG12_1X12:
1206 ccdc_pattern = ccdc_sgbrg_pattern;
1207 break;
1208 default:
1209
1210 ccdc_pattern = ccdc_sgrbg_pattern;
1211 break;
1212 }
1213 ccdc_config_imgattr(ccdc, ccdc_pattern);
1214
1215
1216
1217
1218 isp_reg_writel(isp, ((format->height - 2) << ISPCCDC_VDINT_0_SHIFT) |
1219 ((format->height * 2 / 3) << ISPCCDC_VDINT_1_SHIFT),
1220 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VDINT);
1221
1222
1223 format = &ccdc->formats[CCDC_PAD_SOURCE_OF];
1224 crop = &ccdc->crop;
1225
1226
1227
1228
1229
1230
1231 if (ccdc->bt656) {
1232 sph = crop->left * 2;
1233 nph = crop->width * 2 - 1;
1234 } else {
1235 sph = crop->left;
1236 nph = crop->width - 1;
1237 }
1238
1239 isp_reg_writel(isp, (sph << ISPCCDC_HORZ_INFO_SPH_SHIFT) |
1240 (nph << ISPCCDC_HORZ_INFO_NPH_SHIFT),
1241 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_HORZ_INFO);
1242 isp_reg_writel(isp, (crop->top << ISPCCDC_VERT_START_SLV0_SHIFT) |
1243 (crop->top << ISPCCDC_VERT_START_SLV1_SHIFT),
1244 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_START);
1245 isp_reg_writel(isp, (crop->height - 1)
1246 << ISPCCDC_VERT_LINES_NLV_SHIFT,
1247 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_LINES);
1248
1249 ccdc_config_outlineoffset(ccdc, ccdc->video_out.bpl_value,
1250 format->field);
1251
1252
1253
1254
1255
1256 if (ccdc->formats[CCDC_PAD_SINK].field == V4L2_FIELD_ALTERNATE &&
1257 (format->field == V4L2_FIELD_INTERLACED_TB ||
1258 format->field == V4L2_FIELD_INTERLACED_BT))
1259 syn_mode |= ISPCCDC_SYN_MODE_FLDMODE;
1260
1261
1262
1263
1264 if (format->code == MEDIA_BUS_FMT_YUYV8_1X16)
1265 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1266 ISPCCDC_CFG_BSWD);
1267 else
1268 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1269 ISPCCDC_CFG_BSWD);
1270
1271
1272
1273
1274
1275 if (omap3isp_video_format_info(format->code)->width <= 8 || ccdc->bt656)
1276 syn_mode |= ISPCCDC_SYN_MODE_PACK8;
1277 else
1278 syn_mode &= ~ISPCCDC_SYN_MODE_PACK8;
1279
1280 isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
1281
1282
1283 ccdc_config_vp(ccdc);
1284
1285
1286 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
1287 if (ccdc->lsc.request == NULL)
1288 goto unlock;
1289
1290 WARN_ON(ccdc->lsc.active);
1291
1292
1293
1294
1295 if (ccdc->lsc.active == NULL &&
1296 __ccdc_lsc_configure(ccdc, ccdc->lsc.request) == 0) {
1297 ccdc->lsc.active = ccdc->lsc.request;
1298 } else {
1299 list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue);
1300 schedule_work(&ccdc->lsc.table_work);
1301 }
1302
1303 ccdc->lsc.request = NULL;
1304
1305unlock:
1306 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
1307
1308 ccdc_apply_controls(ccdc);
1309}
1310
1311static void __ccdc_enable(struct isp_ccdc_device *ccdc, int enable)
1312{
1313 struct isp_device *isp = to_isp_device(ccdc);
1314
1315
1316 if (enable && ccdc->stopping & CCDC_STOP_REQUEST)
1317 return;
1318
1319 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR,
1320 ISPCCDC_PCR_EN, enable ? ISPCCDC_PCR_EN : 0);
1321
1322 ccdc->running = enable;
1323}
1324
1325static int ccdc_disable(struct isp_ccdc_device *ccdc)
1326{
1327 unsigned long flags;
1328 int ret = 0;
1329
1330 spin_lock_irqsave(&ccdc->lock, flags);
1331 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS)
1332 ccdc->stopping = CCDC_STOP_REQUEST;
1333 if (!ccdc->running)
1334 ccdc->stopping = CCDC_STOP_FINISHED;
1335 spin_unlock_irqrestore(&ccdc->lock, flags);
1336
1337 ret = wait_event_timeout(ccdc->wait,
1338 ccdc->stopping == CCDC_STOP_FINISHED,
1339 msecs_to_jiffies(2000));
1340 if (ret == 0) {
1341 ret = -ETIMEDOUT;
1342 dev_warn(to_device(ccdc), "CCDC stop timeout!\n");
1343 }
1344
1345 omap3isp_sbl_disable(to_isp_device(ccdc), OMAP3_ISP_SBL_CCDC_LSC_READ);
1346
1347 mutex_lock(&ccdc->ioctl_lock);
1348 ccdc_lsc_free_request(ccdc, ccdc->lsc.request);
1349 ccdc->lsc.request = ccdc->lsc.active;
1350 ccdc->lsc.active = NULL;
1351 cancel_work_sync(&ccdc->lsc.table_work);
1352 ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
1353 mutex_unlock(&ccdc->ioctl_lock);
1354
1355 ccdc->stopping = CCDC_STOP_NOT_REQUESTED;
1356
1357 return ret > 0 ? 0 : ret;
1358}
1359
1360static void ccdc_enable(struct isp_ccdc_device *ccdc)
1361{
1362 if (ccdc_lsc_is_configured(ccdc))
1363 __ccdc_lsc_enable(ccdc, 1);
1364 __ccdc_enable(ccdc, 1);
1365}
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378static int ccdc_sbl_busy(struct isp_ccdc_device *ccdc)
1379{
1380 struct isp_device *isp = to_isp_device(ccdc);
1381
1382 return omap3isp_ccdc_busy(ccdc)
1383 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_0) &
1384 ISPSBL_CCDC_WR_0_DATA_READY)
1385 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_1) &
1386 ISPSBL_CCDC_WR_0_DATA_READY)
1387 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_2) &
1388 ISPSBL_CCDC_WR_0_DATA_READY)
1389 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_3) &
1390 ISPSBL_CCDC_WR_0_DATA_READY);
1391}
1392
1393
1394
1395
1396
1397
1398static int ccdc_sbl_wait_idle(struct isp_ccdc_device *ccdc,
1399 unsigned int max_wait)
1400{
1401 unsigned int wait = 0;
1402
1403 if (max_wait == 0)
1404 max_wait = 10000;
1405
1406 for (wait = 0; wait <= max_wait; wait++) {
1407 if (!ccdc_sbl_busy(ccdc))
1408 return 0;
1409
1410 rmb();
1411 udelay(1);
1412 }
1413
1414 return -EBUSY;
1415}
1416
1417
1418
1419
1420
1421
1422
1423
1424static int ccdc_handle_stopping(struct isp_ccdc_device *ccdc, u32 event)
1425{
1426 int rval = 0;
1427
1428 switch ((ccdc->stopping & 3) | event) {
1429 case CCDC_STOP_REQUEST | CCDC_EVENT_VD1:
1430 if (ccdc->lsc.state != LSC_STATE_STOPPED)
1431 __ccdc_lsc_enable(ccdc, 0);
1432 __ccdc_enable(ccdc, 0);
1433 ccdc->stopping = CCDC_STOP_EXECUTED;
1434 return 1;
1435
1436 case CCDC_STOP_EXECUTED | CCDC_EVENT_VD0:
1437 ccdc->stopping |= CCDC_STOP_CCDC_FINISHED;
1438 if (ccdc->lsc.state == LSC_STATE_STOPPED)
1439 ccdc->stopping |= CCDC_STOP_LSC_FINISHED;
1440 rval = 1;
1441 break;
1442
1443 case CCDC_STOP_EXECUTED | CCDC_EVENT_LSC_DONE:
1444 ccdc->stopping |= CCDC_STOP_LSC_FINISHED;
1445 rval = 1;
1446 break;
1447
1448 case CCDC_STOP_EXECUTED | CCDC_EVENT_VD1:
1449 return 1;
1450 }
1451
1452 if (ccdc->stopping == CCDC_STOP_FINISHED) {
1453 wake_up(&ccdc->wait);
1454 rval = 1;
1455 }
1456
1457 return rval;
1458}
1459
1460static void ccdc_hs_vs_isr(struct isp_ccdc_device *ccdc)
1461{
1462 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
1463 struct video_device *vdev = ccdc->subdev.devnode;
1464 struct v4l2_event event;
1465
1466
1467 atomic_inc(&pipe->frame_number);
1468
1469 memset(&event, 0, sizeof(event));
1470 event.type = V4L2_EVENT_FRAME_SYNC;
1471 event.u.frame_sync.frame_sequence = atomic_read(&pipe->frame_number);
1472
1473 v4l2_event_queue(vdev, &event);
1474}
1475
1476
1477
1478
1479
1480
1481static void ccdc_lsc_isr(struct isp_ccdc_device *ccdc, u32 events)
1482{
1483 unsigned long flags;
1484
1485 if (events & IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ) {
1486 struct isp_pipeline *pipe =
1487 to_isp_pipeline(&ccdc->subdev.entity);
1488
1489 ccdc_lsc_error_handler(ccdc);
1490 pipe->error = true;
1491 dev_dbg(to_device(ccdc), "lsc prefetch error\n");
1492 }
1493
1494 if (!(events & IRQ0STATUS_CCDC_LSC_DONE_IRQ))
1495 return;
1496
1497
1498
1499
1500
1501 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
1502
1503 if (ccdc->lsc.state == LSC_STATE_STOPPING)
1504 ccdc->lsc.state = LSC_STATE_STOPPED;
1505
1506 if (ccdc_handle_stopping(ccdc, CCDC_EVENT_LSC_DONE))
1507 goto done;
1508
1509 if (ccdc->lsc.state != LSC_STATE_RECONFIG)
1510 goto done;
1511
1512
1513 ccdc->lsc.state = LSC_STATE_STOPPED;
1514
1515
1516
1517
1518
1519 if (events & IRQ0STATUS_HS_VS_IRQ)
1520 goto done;
1521
1522
1523
1524
1525 if (ccdc->lsc.request == NULL)
1526 goto done;
1527
1528 ccdc_lsc_enable(ccdc);
1529
1530done:
1531 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
1532}
1533
1534
1535
1536
1537
1538static bool ccdc_has_all_fields(struct isp_ccdc_device *ccdc)
1539{
1540 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
1541 struct isp_device *isp = to_isp_device(ccdc);
1542 enum v4l2_field of_field = ccdc->formats[CCDC_PAD_SOURCE_OF].field;
1543 enum v4l2_field field;
1544
1545
1546 if (of_field == V4L2_FIELD_NONE)
1547 return true;
1548
1549
1550 field = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE)
1551 & ISPCCDC_SYN_MODE_FLDSTAT
1552 ? V4L2_FIELD_BOTTOM : V4L2_FIELD_TOP;
1553
1554
1555
1556
1557 if (of_field == V4L2_FIELD_ALTERNATE) {
1558 pipe->field = field;
1559 return true;
1560 }
1561
1562
1563 ccdc->fields |= field == V4L2_FIELD_BOTTOM
1564 ? CCDC_FIELD_BOTTOM : CCDC_FIELD_TOP;
1565
1566 if (ccdc->fields != CCDC_FIELD_BOTH)
1567 return false;
1568
1569
1570
1571
1572 if ((of_field == V4L2_FIELD_INTERLACED_TB && field == V4L2_FIELD_TOP) ||
1573 (of_field == V4L2_FIELD_INTERLACED_BT && field == V4L2_FIELD_BOTTOM))
1574 return false;
1575
1576
1577 ccdc->fields = 0;
1578
1579 return true;
1580}
1581
1582static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
1583{
1584 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
1585 struct isp_device *isp = to_isp_device(ccdc);
1586 struct isp_buffer *buffer;
1587
1588
1589
1590
1591
1592
1593
1594 if (list_empty(&ccdc->video_out.dmaqueue))
1595 return 0;
1596
1597
1598
1599
1600
1601 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && ccdc->underrun) {
1602 ccdc->underrun = 0;
1603 return 1;
1604 }
1605
1606
1607 if (ccdc_sbl_wait_idle(ccdc, 1000)) {
1608 dev_info(isp->dev, "CCDC won't become idle!\n");
1609 media_entity_enum_set(&isp->crashed, &ccdc->subdev.entity);
1610 omap3isp_pipeline_cancel_stream(pipe);
1611 return 0;
1612 }
1613
1614
1615 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS &&
1616 ccdc->stopping & CCDC_STOP_REQUEST)
1617 return 0;
1618
1619 if (!ccdc_has_all_fields(ccdc))
1620 return 1;
1621
1622 buffer = omap3isp_video_buffer_next(&ccdc->video_out);
1623 if (buffer != NULL)
1624 ccdc_set_outaddr(ccdc, buffer->dma);
1625
1626 pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
1627
1628 if (ccdc->state == ISP_PIPELINE_STREAM_SINGLESHOT &&
1629 isp_pipeline_ready(pipe))
1630 omap3isp_pipeline_set_stream(pipe,
1631 ISP_PIPELINE_STREAM_SINGLESHOT);
1632
1633 return buffer != NULL;
1634}
1635
1636
1637
1638
1639
1640
1641
1642static void ccdc_vd0_isr(struct isp_ccdc_device *ccdc)
1643{
1644 unsigned long flags;
1645 int restart = 0;
1646
1647
1648
1649
1650 if (ccdc->bt656) {
1651 struct isp_pipeline *pipe =
1652 to_isp_pipeline(&ccdc->subdev.entity);
1653
1654 atomic_inc(&pipe->frame_number);
1655 }
1656
1657
1658
1659
1660
1661 if (ccdc->bt656) {
1662 spin_lock_irqsave(&ccdc->lock, flags);
1663 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS &&
1664 ccdc->output & CCDC_OUTPUT_MEMORY) {
1665 if (ccdc->lsc.state != LSC_STATE_STOPPED)
1666 __ccdc_lsc_enable(ccdc, 0);
1667 __ccdc_enable(ccdc, 0);
1668 }
1669 ccdc_handle_stopping(ccdc, CCDC_EVENT_VD1);
1670 spin_unlock_irqrestore(&ccdc->lock, flags);
1671 }
1672
1673 spin_lock_irqsave(&ccdc->lock, flags);
1674 if (ccdc_handle_stopping(ccdc, CCDC_EVENT_VD0)) {
1675 spin_unlock_irqrestore(&ccdc->lock, flags);
1676 return;
1677 }
1678
1679 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1680 restart = ccdc_isr_buffer(ccdc);
1681
1682 if (!ccdc->shadow_update)
1683 ccdc_apply_controls(ccdc);
1684 spin_unlock_irqrestore(&ccdc->lock, flags);
1685
1686 if (restart)
1687 ccdc_enable(ccdc);
1688}
1689
1690
1691
1692
1693
1694static void ccdc_vd1_isr(struct isp_ccdc_device *ccdc)
1695{
1696 unsigned long flags;
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707 if (ccdc->bt656)
1708 return;
1709
1710 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722 switch (ccdc->state) {
1723 case ISP_PIPELINE_STREAM_SINGLESHOT:
1724 ccdc->stopping = CCDC_STOP_REQUEST;
1725 break;
1726
1727 case ISP_PIPELINE_STREAM_CONTINUOUS:
1728 if (ccdc->output & CCDC_OUTPUT_MEMORY) {
1729 if (ccdc->lsc.state != LSC_STATE_STOPPED)
1730 __ccdc_lsc_enable(ccdc, 0);
1731 __ccdc_enable(ccdc, 0);
1732 }
1733 break;
1734
1735 case ISP_PIPELINE_STREAM_STOPPED:
1736 break;
1737 }
1738
1739 if (ccdc_handle_stopping(ccdc, CCDC_EVENT_VD1))
1740 goto done;
1741
1742 if (ccdc->lsc.request == NULL)
1743 goto done;
1744
1745
1746
1747
1748
1749 if (ccdc->lsc.state == LSC_STATE_RUNNING) {
1750 __ccdc_lsc_enable(ccdc, 0);
1751 ccdc->lsc.state = LSC_STATE_RECONFIG;
1752 goto done;
1753 }
1754
1755
1756 if (ccdc->lsc.state == LSC_STATE_STOPPED)
1757 ccdc_lsc_enable(ccdc);
1758
1759done:
1760 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
1761}
1762
1763
1764
1765
1766
1767
1768int omap3isp_ccdc_isr(struct isp_ccdc_device *ccdc, u32 events)
1769{
1770 if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED)
1771 return 0;
1772
1773 if (events & IRQ0STATUS_CCDC_VD1_IRQ)
1774 ccdc_vd1_isr(ccdc);
1775
1776 ccdc_lsc_isr(ccdc, events);
1777
1778 if (events & IRQ0STATUS_CCDC_VD0_IRQ)
1779 ccdc_vd0_isr(ccdc);
1780
1781 if (events & IRQ0STATUS_HS_VS_IRQ)
1782 ccdc_hs_vs_isr(ccdc);
1783
1784 return 0;
1785}
1786
1787
1788
1789
1790
1791static int ccdc_video_queue(struct isp_video *video, struct isp_buffer *buffer)
1792{
1793 struct isp_ccdc_device *ccdc = &video->isp->isp_ccdc;
1794 unsigned long flags;
1795 bool restart = false;
1796
1797 if (!(ccdc->output & CCDC_OUTPUT_MEMORY))
1798 return -ENODEV;
1799
1800 ccdc_set_outaddr(ccdc, buffer->dma);
1801
1802
1803
1804
1805
1806
1807
1808 spin_lock_irqsave(&ccdc->lock, flags);
1809 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && !ccdc->running &&
1810 ccdc->bt656)
1811 restart = true;
1812 else
1813 ccdc->underrun = 1;
1814 spin_unlock_irqrestore(&ccdc->lock, flags);
1815
1816 if (restart)
1817 ccdc_enable(ccdc);
1818
1819 return 0;
1820}
1821
1822static const struct isp_video_operations ccdc_video_ops = {
1823 .queue = ccdc_video_queue,
1824};
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838static long ccdc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1839{
1840 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
1841 int ret;
1842
1843 switch (cmd) {
1844 case VIDIOC_OMAP3ISP_CCDC_CFG:
1845 mutex_lock(&ccdc->ioctl_lock);
1846 ret = ccdc_config(ccdc, arg);
1847 mutex_unlock(&ccdc->ioctl_lock);
1848 break;
1849
1850 default:
1851 return -ENOIOCTLCMD;
1852 }
1853
1854 return ret;
1855}
1856
1857static int ccdc_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1858 struct v4l2_event_subscription *sub)
1859{
1860 if (sub->type != V4L2_EVENT_FRAME_SYNC)
1861 return -EINVAL;
1862
1863
1864 if (sub->id != 0)
1865 return -EINVAL;
1866
1867 return v4l2_event_subscribe(fh, sub, OMAP3ISP_CCDC_NEVENTS, NULL);
1868}
1869
1870static int ccdc_unsubscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1871 struct v4l2_event_subscription *sub)
1872{
1873 return v4l2_event_unsubscribe(fh, sub);
1874}
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888static int ccdc_set_stream(struct v4l2_subdev *sd, int enable)
1889{
1890 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
1891 struct isp_device *isp = to_isp_device(ccdc);
1892 int ret = 0;
1893
1894 if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED) {
1895 if (enable == ISP_PIPELINE_STREAM_STOPPED)
1896 return 0;
1897
1898 omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_CCDC);
1899 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1900 ISPCCDC_CFG_VDLC);
1901
1902 ccdc_configure(ccdc);
1903
1904 ccdc_print_status(ccdc);
1905 }
1906
1907 switch (enable) {
1908 case ISP_PIPELINE_STREAM_CONTINUOUS:
1909 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1910 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
1911
1912 if (ccdc->underrun || !(ccdc->output & CCDC_OUTPUT_MEMORY))
1913 ccdc_enable(ccdc);
1914
1915 ccdc->underrun = 0;
1916 break;
1917
1918 case ISP_PIPELINE_STREAM_SINGLESHOT:
1919 if (ccdc->output & CCDC_OUTPUT_MEMORY &&
1920 ccdc->state != ISP_PIPELINE_STREAM_SINGLESHOT)
1921 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
1922
1923 ccdc_enable(ccdc);
1924 break;
1925
1926 case ISP_PIPELINE_STREAM_STOPPED:
1927 ret = ccdc_disable(ccdc);
1928 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1929 omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
1930 omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_CCDC);
1931 ccdc->underrun = 0;
1932 break;
1933 }
1934
1935 ccdc->state = enable;
1936 return ret;
1937}
1938
1939static struct v4l2_mbus_framefmt *
1940__ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg,
1941 unsigned int pad, enum v4l2_subdev_format_whence which)
1942{
1943 if (which == V4L2_SUBDEV_FORMAT_TRY)
1944 return v4l2_subdev_get_try_format(&ccdc->subdev, cfg, pad);
1945 else
1946 return &ccdc->formats[pad];
1947}
1948
1949static struct v4l2_rect *
1950__ccdc_get_crop(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg,
1951 enum v4l2_subdev_format_whence which)
1952{
1953 if (which == V4L2_SUBDEV_FORMAT_TRY)
1954 return v4l2_subdev_get_try_crop(&ccdc->subdev, cfg, CCDC_PAD_SOURCE_OF);
1955 else
1956 return &ccdc->crop;
1957}
1958
1959
1960
1961
1962
1963
1964
1965
1966static void
1967ccdc_try_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_pad_config *cfg,
1968 unsigned int pad, struct v4l2_mbus_framefmt *fmt,
1969 enum v4l2_subdev_format_whence which)
1970{
1971 const struct isp_format_info *info;
1972 u32 pixelcode;
1973 unsigned int width = fmt->width;
1974 unsigned int height = fmt->height;
1975 struct v4l2_rect *crop;
1976 enum v4l2_field field;
1977 unsigned int i;
1978
1979 switch (pad) {
1980 case CCDC_PAD_SINK:
1981 for (i = 0; i < ARRAY_SIZE(ccdc_fmts); i++) {
1982 if (fmt->code == ccdc_fmts[i])
1983 break;
1984 }
1985
1986
1987 if (i >= ARRAY_SIZE(ccdc_fmts))
1988 fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
1989
1990
1991 fmt->width = clamp_t(u32, width, 32, 4096);
1992 fmt->height = clamp_t(u32, height, 32, 4096);
1993
1994
1995 if (fmt->field == V4L2_FIELD_ANY)
1996 fmt->field = V4L2_FIELD_NONE;
1997
1998 break;
1999
2000 case CCDC_PAD_SOURCE_OF:
2001 pixelcode = fmt->code;
2002 field = fmt->field;
2003 *fmt = *__ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, which);
2004
2005
2006
2007
2008
2009
2010
2011
2012 if (fmt->code == MEDIA_BUS_FMT_YUYV8_2X8 ||
2013 fmt->code == MEDIA_BUS_FMT_UYVY8_2X8) {
2014
2015 if (pixelcode == MEDIA_BUS_FMT_YUYV8_2X8 ||
2016 pixelcode == MEDIA_BUS_FMT_UYVY8_2X8 ||
2017 pixelcode == MEDIA_BUS_FMT_YUYV8_1X16 ||
2018 pixelcode == MEDIA_BUS_FMT_UYVY8_1X16)
2019 fmt->code = pixelcode;
2020
2021 if (fmt->code == MEDIA_BUS_FMT_YUYV8_2X8)
2022 fmt->code = MEDIA_BUS_FMT_YUYV8_1X16;
2023 else if (fmt->code == MEDIA_BUS_FMT_UYVY8_2X8)
2024 fmt->code = MEDIA_BUS_FMT_UYVY8_1X16;
2025 }
2026
2027
2028 crop = __ccdc_get_crop(ccdc, cfg, which);
2029 fmt->width = crop->width;
2030 fmt->height = crop->height;
2031
2032
2033
2034
2035 if (fmt->field == V4L2_FIELD_ALTERNATE &&
2036 (field == V4L2_FIELD_INTERLACED_TB ||
2037 field == V4L2_FIELD_INTERLACED_BT)) {
2038 fmt->field = field;
2039 fmt->height *= 2;
2040 }
2041
2042 break;
2043
2044 case CCDC_PAD_SOURCE_VP:
2045 *fmt = *__ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, which);
2046
2047
2048 info = omap3isp_video_format_info(fmt->code);
2049 fmt->code = info->truncated;
2050
2051
2052 if (fmt->code == MEDIA_BUS_FMT_YUYV8_2X8 ||
2053 fmt->code == MEDIA_BUS_FMT_UYVY8_2X8)
2054 fmt->code = 0;
2055
2056
2057
2058
2059
2060 fmt->width = clamp_t(u32, width, 32, fmt->width);
2061 fmt->height = clamp_t(u32, height, 32, fmt->height - 1);
2062 break;
2063 }
2064
2065
2066
2067
2068 fmt->colorspace = V4L2_COLORSPACE_SRGB;
2069}
2070
2071
2072
2073
2074
2075
2076
2077static void ccdc_try_crop(struct isp_ccdc_device *ccdc,
2078 const struct v4l2_mbus_framefmt *sink,
2079 struct v4l2_rect *crop)
2080{
2081 const struct isp_format_info *info;
2082 unsigned int max_width;
2083
2084
2085
2086
2087 info = omap3isp_video_format_info(sink->code);
2088 if (info->flavor != MEDIA_BUS_FMT_Y8_1X8) {
2089 crop->left &= ~1;
2090 crop->top &= ~1;
2091 }
2092
2093 crop->left = clamp_t(u32, crop->left, 0, sink->width - CCDC_MIN_WIDTH);
2094 crop->top = clamp_t(u32, crop->top, 0, sink->height - CCDC_MIN_HEIGHT);
2095
2096
2097
2098
2099
2100
2101 max_width = (sink->width - crop->left + 15) & ~15;
2102 crop->width = clamp_t(u32, crop->width, CCDC_MIN_WIDTH, max_width)
2103 & ~15;
2104 crop->height = clamp_t(u32, crop->height, CCDC_MIN_HEIGHT,
2105 sink->height - crop->top);
2106
2107
2108 if (info->flavor != MEDIA_BUS_FMT_Y8_1X8) {
2109 crop->width &= ~1;
2110 crop->height &= ~1;
2111 }
2112}
2113
2114
2115
2116
2117
2118
2119
2120
2121static int ccdc_enum_mbus_code(struct v4l2_subdev *sd,
2122 struct v4l2_subdev_pad_config *cfg,
2123 struct v4l2_subdev_mbus_code_enum *code)
2124{
2125 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2126 struct v4l2_mbus_framefmt *format;
2127
2128 switch (code->pad) {
2129 case CCDC_PAD_SINK:
2130 if (code->index >= ARRAY_SIZE(ccdc_fmts))
2131 return -EINVAL;
2132
2133 code->code = ccdc_fmts[code->index];
2134 break;
2135
2136 case CCDC_PAD_SOURCE_OF:
2137 format = __ccdc_get_format(ccdc, cfg, code->pad,
2138 code->which);
2139
2140 if (format->code == MEDIA_BUS_FMT_YUYV8_2X8 ||
2141 format->code == MEDIA_BUS_FMT_UYVY8_2X8) {
2142
2143 if (code->index == 0)
2144 code->code = MEDIA_BUS_FMT_YUYV8_1X16;
2145 else if (code->index == 1)
2146 code->code = MEDIA_BUS_FMT_UYVY8_1X16;
2147 else
2148 return -EINVAL;
2149 } else {
2150
2151
2152
2153 if (code->index == 0)
2154 code->code = format->code;
2155 else
2156 return -EINVAL;
2157 }
2158 break;
2159
2160 case CCDC_PAD_SOURCE_VP:
2161
2162
2163
2164
2165 if (code->index != 0)
2166 return -EINVAL;
2167
2168 format = __ccdc_get_format(ccdc, cfg, code->pad,
2169 code->which);
2170
2171
2172
2173
2174 if (format->code == 0)
2175 return -EINVAL;
2176
2177 code->code = format->code;
2178 break;
2179
2180 default:
2181 return -EINVAL;
2182 }
2183
2184 return 0;
2185}
2186
2187static int ccdc_enum_frame_size(struct v4l2_subdev *sd,
2188 struct v4l2_subdev_pad_config *cfg,
2189 struct v4l2_subdev_frame_size_enum *fse)
2190{
2191 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2192 struct v4l2_mbus_framefmt format;
2193
2194 if (fse->index != 0)
2195 return -EINVAL;
2196
2197 format.code = fse->code;
2198 format.width = 1;
2199 format.height = 1;
2200 ccdc_try_format(ccdc, cfg, fse->pad, &format, fse->which);
2201 fse->min_width = format.width;
2202 fse->min_height = format.height;
2203
2204 if (format.code != fse->code)
2205 return -EINVAL;
2206
2207 format.code = fse->code;
2208 format.width = -1;
2209 format.height = -1;
2210 ccdc_try_format(ccdc, cfg, fse->pad, &format, fse->which);
2211 fse->max_width = format.width;
2212 fse->max_height = format.height;
2213
2214 return 0;
2215}
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228static int ccdc_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
2229 struct v4l2_subdev_selection *sel)
2230{
2231 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2232 struct v4l2_mbus_framefmt *format;
2233
2234 if (sel->pad != CCDC_PAD_SOURCE_OF)
2235 return -EINVAL;
2236
2237 switch (sel->target) {
2238 case V4L2_SEL_TGT_CROP_BOUNDS:
2239 sel->r.left = 0;
2240 sel->r.top = 0;
2241 sel->r.width = INT_MAX;
2242 sel->r.height = INT_MAX;
2243
2244 format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, sel->which);
2245 ccdc_try_crop(ccdc, format, &sel->r);
2246 break;
2247
2248 case V4L2_SEL_TGT_CROP:
2249 sel->r = *__ccdc_get_crop(ccdc, cfg, sel->which);
2250 break;
2251
2252 default:
2253 return -EINVAL;
2254 }
2255
2256 return 0;
2257}
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270static int ccdc_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
2271 struct v4l2_subdev_selection *sel)
2272{
2273 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2274 struct v4l2_mbus_framefmt *format;
2275
2276 if (sel->target != V4L2_SEL_TGT_CROP ||
2277 sel->pad != CCDC_PAD_SOURCE_OF)
2278 return -EINVAL;
2279
2280
2281 if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED)
2282 return -EBUSY;
2283
2284
2285
2286
2287
2288 if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
2289 sel->r = *__ccdc_get_crop(ccdc, cfg, sel->which);
2290 return 0;
2291 }
2292
2293 format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SINK, sel->which);
2294 ccdc_try_crop(ccdc, format, &sel->r);
2295 *__ccdc_get_crop(ccdc, cfg, sel->which) = sel->r;
2296
2297
2298 format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, sel->which);
2299 ccdc_try_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, format, sel->which);
2300
2301 return 0;
2302}
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313static int ccdc_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
2314 struct v4l2_subdev_format *fmt)
2315{
2316 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2317 struct v4l2_mbus_framefmt *format;
2318
2319 format = __ccdc_get_format(ccdc, cfg, fmt->pad, fmt->which);
2320 if (format == NULL)
2321 return -EINVAL;
2322
2323 fmt->format = *format;
2324 return 0;
2325}
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336static int ccdc_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
2337 struct v4l2_subdev_format *fmt)
2338{
2339 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2340 struct v4l2_mbus_framefmt *format;
2341 struct v4l2_rect *crop;
2342
2343 format = __ccdc_get_format(ccdc, cfg, fmt->pad, fmt->which);
2344 if (format == NULL)
2345 return -EINVAL;
2346
2347 ccdc_try_format(ccdc, cfg, fmt->pad, &fmt->format, fmt->which);
2348 *format = fmt->format;
2349
2350
2351 if (fmt->pad == CCDC_PAD_SINK) {
2352
2353 crop = __ccdc_get_crop(ccdc, cfg, fmt->which);
2354 crop->left = 0;
2355 crop->top = 0;
2356 crop->width = fmt->format.width;
2357 crop->height = fmt->format.height;
2358
2359 ccdc_try_crop(ccdc, &fmt->format, crop);
2360
2361
2362 format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SOURCE_OF,
2363 fmt->which);
2364 *format = fmt->format;
2365 ccdc_try_format(ccdc, cfg, CCDC_PAD_SOURCE_OF, format,
2366 fmt->which);
2367
2368 format = __ccdc_get_format(ccdc, cfg, CCDC_PAD_SOURCE_VP,
2369 fmt->which);
2370 *format = fmt->format;
2371 ccdc_try_format(ccdc, cfg, CCDC_PAD_SOURCE_VP, format,
2372 fmt->which);
2373 }
2374
2375 return 0;
2376}
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388static bool ccdc_is_shiftable(u32 in, u32 out, unsigned int additional_shift)
2389{
2390 const struct isp_format_info *in_info, *out_info;
2391
2392 if (in == out)
2393 return true;
2394
2395 in_info = omap3isp_video_format_info(in);
2396 out_info = omap3isp_video_format_info(out);
2397
2398 if ((in_info->flavor == 0) || (out_info->flavor == 0))
2399 return false;
2400
2401 if (in_info->flavor != out_info->flavor)
2402 return false;
2403
2404 return in_info->width - out_info->width + additional_shift <= 6;
2405}
2406
2407static int ccdc_link_validate(struct v4l2_subdev *sd,
2408 struct media_link *link,
2409 struct v4l2_subdev_format *source_fmt,
2410 struct v4l2_subdev_format *sink_fmt)
2411{
2412 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2413 unsigned long parallel_shift;
2414
2415
2416 if (source_fmt->format.width != sink_fmt->format.width ||
2417 source_fmt->format.height != sink_fmt->format.height)
2418 return -EPIPE;
2419
2420
2421 if (ccdc->input == CCDC_INPUT_PARALLEL) {
2422 struct v4l2_subdev *sd =
2423 media_entity_to_v4l2_subdev(link->source->entity);
2424 struct isp_bus_cfg *bus_cfg = v4l2_subdev_to_bus_cfg(sd);
2425
2426 parallel_shift = bus_cfg->bus.parallel.data_lane_shift;
2427 } else {
2428 parallel_shift = 0;
2429 }
2430
2431
2432 if (!ccdc_is_shiftable(source_fmt->format.code,
2433 sink_fmt->format.code, parallel_shift))
2434 return -EPIPE;
2435
2436 return 0;
2437}
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448static int ccdc_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2449{
2450 struct v4l2_subdev_format format;
2451
2452 memset(&format, 0, sizeof(format));
2453 format.pad = CCDC_PAD_SINK;
2454 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
2455 format.format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
2456 format.format.width = 4096;
2457 format.format.height = 4096;
2458 ccdc_set_format(sd, fh ? fh->pad : NULL, &format);
2459
2460 return 0;
2461}
2462
2463
2464static const struct v4l2_subdev_core_ops ccdc_v4l2_core_ops = {
2465 .ioctl = ccdc_ioctl,
2466 .subscribe_event = ccdc_subscribe_event,
2467 .unsubscribe_event = ccdc_unsubscribe_event,
2468};
2469
2470
2471static const struct v4l2_subdev_video_ops ccdc_v4l2_video_ops = {
2472 .s_stream = ccdc_set_stream,
2473};
2474
2475
2476static const struct v4l2_subdev_pad_ops ccdc_v4l2_pad_ops = {
2477 .enum_mbus_code = ccdc_enum_mbus_code,
2478 .enum_frame_size = ccdc_enum_frame_size,
2479 .get_fmt = ccdc_get_format,
2480 .set_fmt = ccdc_set_format,
2481 .get_selection = ccdc_get_selection,
2482 .set_selection = ccdc_set_selection,
2483 .link_validate = ccdc_link_validate,
2484};
2485
2486
2487static const struct v4l2_subdev_ops ccdc_v4l2_ops = {
2488 .core = &ccdc_v4l2_core_ops,
2489 .video = &ccdc_v4l2_video_ops,
2490 .pad = &ccdc_v4l2_pad_ops,
2491};
2492
2493
2494static const struct v4l2_subdev_internal_ops ccdc_v4l2_internal_ops = {
2495 .open = ccdc_init_formats,
2496};
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511static int ccdc_link_setup(struct media_entity *entity,
2512 const struct media_pad *local,
2513 const struct media_pad *remote, u32 flags)
2514{
2515 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
2516 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2517 struct isp_device *isp = to_isp_device(ccdc);
2518 unsigned int index = local->index;
2519
2520
2521 if (is_media_entity_v4l2_subdev(remote->entity))
2522 index |= 2 << 16;
2523
2524 switch (index) {
2525 case CCDC_PAD_SINK | 2 << 16:
2526
2527
2528
2529 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
2530 ccdc->input = CCDC_INPUT_NONE;
2531 break;
2532 }
2533
2534 if (ccdc->input != CCDC_INPUT_NONE)
2535 return -EBUSY;
2536
2537 if (remote->entity == &isp->isp_ccp2.subdev.entity)
2538 ccdc->input = CCDC_INPUT_CCP2B;
2539 else if (remote->entity == &isp->isp_csi2a.subdev.entity)
2540 ccdc->input = CCDC_INPUT_CSI2A;
2541 else if (remote->entity == &isp->isp_csi2c.subdev.entity)
2542 ccdc->input = CCDC_INPUT_CSI2C;
2543 else
2544 ccdc->input = CCDC_INPUT_PARALLEL;
2545
2546 break;
2547
2548
2549
2550
2551
2552
2553 case CCDC_PAD_SOURCE_VP | 2 << 16:
2554
2555
2556
2557 if (flags & MEDIA_LNK_FL_ENABLED) {
2558 if (ccdc->output & ~CCDC_OUTPUT_PREVIEW)
2559 return -EBUSY;
2560 ccdc->output |= CCDC_OUTPUT_PREVIEW;
2561 } else {
2562 ccdc->output &= ~CCDC_OUTPUT_PREVIEW;
2563 }
2564 break;
2565
2566 case CCDC_PAD_SOURCE_OF:
2567
2568 if (flags & MEDIA_LNK_FL_ENABLED) {
2569 if (ccdc->output & ~CCDC_OUTPUT_MEMORY)
2570 return -EBUSY;
2571 ccdc->output |= CCDC_OUTPUT_MEMORY;
2572 } else {
2573 ccdc->output &= ~CCDC_OUTPUT_MEMORY;
2574 }
2575 break;
2576
2577 case CCDC_PAD_SOURCE_OF | 2 << 16:
2578
2579 if (flags & MEDIA_LNK_FL_ENABLED) {
2580 if (ccdc->output & ~CCDC_OUTPUT_RESIZER)
2581 return -EBUSY;
2582 ccdc->output |= CCDC_OUTPUT_RESIZER;
2583 } else {
2584 ccdc->output &= ~CCDC_OUTPUT_RESIZER;
2585 }
2586 break;
2587
2588 default:
2589 return -EINVAL;
2590 }
2591
2592 return 0;
2593}
2594
2595
2596static const struct media_entity_operations ccdc_media_ops = {
2597 .link_setup = ccdc_link_setup,
2598 .link_validate = v4l2_subdev_link_validate,
2599};
2600
2601void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
2602{
2603 v4l2_device_unregister_subdev(&ccdc->subdev);
2604 omap3isp_video_unregister(&ccdc->video_out);
2605}
2606
2607int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
2608 struct v4l2_device *vdev)
2609{
2610 int ret;
2611
2612
2613 ccdc->subdev.dev = vdev->mdev->dev;
2614 ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
2615 if (ret < 0)
2616 goto error;
2617
2618 ret = omap3isp_video_register(&ccdc->video_out, vdev);
2619 if (ret < 0)
2620 goto error;
2621
2622 return 0;
2623
2624error:
2625 omap3isp_ccdc_unregister_entities(ccdc);
2626 return ret;
2627}
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
2640{
2641 struct v4l2_subdev *sd = &ccdc->subdev;
2642 struct media_pad *pads = ccdc->pads;
2643 struct media_entity *me = &sd->entity;
2644 int ret;
2645
2646 ccdc->input = CCDC_INPUT_NONE;
2647
2648 v4l2_subdev_init(sd, &ccdc_v4l2_ops);
2649 sd->internal_ops = &ccdc_v4l2_internal_ops;
2650 strscpy(sd->name, "OMAP3 ISP CCDC", sizeof(sd->name));
2651 sd->grp_id = 1 << 16;
2652 v4l2_set_subdevdata(sd, ccdc);
2653 sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
2654
2655 pads[CCDC_PAD_SINK].flags = MEDIA_PAD_FL_SINK
2656 | MEDIA_PAD_FL_MUST_CONNECT;
2657 pads[CCDC_PAD_SOURCE_VP].flags = MEDIA_PAD_FL_SOURCE;
2658 pads[CCDC_PAD_SOURCE_OF].flags = MEDIA_PAD_FL_SOURCE;
2659
2660 me->ops = &ccdc_media_ops;
2661 ret = media_entity_pads_init(me, CCDC_PADS_NUM, pads);
2662 if (ret < 0)
2663 return ret;
2664
2665 ccdc_init_formats(sd, NULL);
2666
2667 ccdc->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2668 ccdc->video_out.ops = &ccdc_video_ops;
2669 ccdc->video_out.isp = to_isp_device(ccdc);
2670 ccdc->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 3;
2671 ccdc->video_out.bpl_alignment = 32;
2672
2673 ret = omap3isp_video_init(&ccdc->video_out, "CCDC");
2674 if (ret < 0)
2675 goto error;
2676
2677 return 0;
2678
2679error:
2680 media_entity_cleanup(me);
2681 return ret;
2682}
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692int omap3isp_ccdc_init(struct isp_device *isp)
2693{
2694 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2695 int ret;
2696
2697 spin_lock_init(&ccdc->lock);
2698 init_waitqueue_head(&ccdc->wait);
2699 mutex_init(&ccdc->ioctl_lock);
2700
2701 ccdc->stopping = CCDC_STOP_NOT_REQUESTED;
2702
2703 INIT_WORK(&ccdc->lsc.table_work, ccdc_lsc_free_table_work);
2704 ccdc->lsc.state = LSC_STATE_STOPPED;
2705 INIT_LIST_HEAD(&ccdc->lsc.free_queue);
2706 spin_lock_init(&ccdc->lsc.req_lock);
2707
2708 ccdc->clamp.oblen = 0;
2709 ccdc->clamp.dcsubval = 0;
2710
2711 ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
2712 ccdc_apply_controls(ccdc);
2713
2714 ret = ccdc_init_entities(ccdc);
2715 if (ret < 0) {
2716 mutex_destroy(&ccdc->ioctl_lock);
2717 return ret;
2718 }
2719
2720 return 0;
2721}
2722
2723
2724
2725
2726
2727void omap3isp_ccdc_cleanup(struct isp_device *isp)
2728{
2729 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2730
2731 omap3isp_video_cleanup(&ccdc->video_out);
2732 media_entity_cleanup(&ccdc->subdev.entity);
2733
2734
2735
2736
2737 ccdc_lsc_free_request(ccdc, ccdc->lsc.request);
2738 cancel_work_sync(&ccdc->lsc.table_work);
2739 ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
2740
2741 if (ccdc->fpc.addr != NULL)
2742 dma_free_coherent(isp->dev, ccdc->fpc.fpnum * 4, ccdc->fpc.addr,
2743 ccdc->fpc.dma);
2744
2745 mutex_destroy(&ccdc->ioctl_lock);
2746}
2747