2 * TI OMAP4 ISS V4L2 Driver - ISP IPIPEIF module
4 * Copyright (C) 2012 Texas Instruments, Inc.
6 * Author: Sergio Aguirre <sergio.a.aguirre@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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>
20 #include <linux/sched.h>
24 #include "iss_ipipeif.h"
26 static const unsigned int ipipeif_fmts
[] = {
27 MEDIA_BUS_FMT_SGRBG10_1X10
,
28 MEDIA_BUS_FMT_SRGGB10_1X10
,
29 MEDIA_BUS_FMT_SBGGR10_1X10
,
30 MEDIA_BUS_FMT_SGBRG10_1X10
,
31 MEDIA_BUS_FMT_UYVY8_1X16
,
32 MEDIA_BUS_FMT_YUYV8_1X16
,
36 * ipipeif_print_status - Print current IPIPEIF Module register values.
37 * @ipipeif: Pointer to ISS ISP IPIPEIF device.
39 * Also prints other debug information stored in the IPIPEIF module.
41 #define IPIPEIF_PRINT_REGISTER(iss, name)\
42 dev_dbg(iss->dev, "###IPIPEIF " #name "=0x%08x\n", \
43 iss_reg_read(iss, OMAP4_ISS_MEM_ISP_IPIPEIF, IPIPEIF_##name))
45 #define ISIF_PRINT_REGISTER(iss, name)\
46 dev_dbg(iss->dev, "###ISIF " #name "=0x%08x\n", \
47 iss_reg_read(iss, OMAP4_ISS_MEM_ISP_ISIF, ISIF_##name))
49 #define ISP5_PRINT_REGISTER(iss, name)\
50 dev_dbg(iss->dev, "###ISP5 " #name "=0x%08x\n", \
51 iss_reg_read(iss, OMAP4_ISS_MEM_ISP_SYS1, ISP5_##name))
53 static void ipipeif_print_status(struct iss_ipipeif_device
*ipipeif
)
55 struct iss_device
*iss
= to_iss_device(ipipeif
);
57 dev_dbg(iss
->dev
, "-------------IPIPEIF Register dump-------------\n");
59 IPIPEIF_PRINT_REGISTER(iss
, CFG1
);
60 IPIPEIF_PRINT_REGISTER(iss
, CFG2
);
62 ISIF_PRINT_REGISTER(iss
, SYNCEN
);
63 ISIF_PRINT_REGISTER(iss
, CADU
);
64 ISIF_PRINT_REGISTER(iss
, CADL
);
65 ISIF_PRINT_REGISTER(iss
, MODESET
);
66 ISIF_PRINT_REGISTER(iss
, CCOLP
);
67 ISIF_PRINT_REGISTER(iss
, SPH
);
68 ISIF_PRINT_REGISTER(iss
, LNH
);
69 ISIF_PRINT_REGISTER(iss
, LNV
);
70 ISIF_PRINT_REGISTER(iss
, VDINT(0));
71 ISIF_PRINT_REGISTER(iss
, HSIZE
);
73 ISP5_PRINT_REGISTER(iss
, SYSCONFIG
);
74 ISP5_PRINT_REGISTER(iss
, CTRL
);
75 ISP5_PRINT_REGISTER(iss
, IRQSTATUS(0));
76 ISP5_PRINT_REGISTER(iss
, IRQENABLE_SET(0));
77 ISP5_PRINT_REGISTER(iss
, IRQENABLE_CLR(0));
79 dev_dbg(iss
->dev
, "-----------------------------------------------\n");
82 static void ipipeif_write_enable(struct iss_ipipeif_device
*ipipeif
, u8 enable
)
84 struct iss_device
*iss
= to_iss_device(ipipeif
);
86 iss_reg_update(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_SYNCEN
,
87 ISIF_SYNCEN_DWEN
, enable
? ISIF_SYNCEN_DWEN
: 0);
91 * ipipeif_enable - Enable/Disable IPIPEIF.
92 * @enable: enable flag
95 static void ipipeif_enable(struct iss_ipipeif_device
*ipipeif
, u8 enable
)
97 struct iss_device
*iss
= to_iss_device(ipipeif
);
99 iss_reg_update(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_SYNCEN
,
100 ISIF_SYNCEN_SYEN
, enable
? ISIF_SYNCEN_SYEN
: 0);
103 /* -----------------------------------------------------------------------------
104 * Format- and pipeline-related configuration helpers
108 * ipipeif_set_outaddr - Set memory address to save output image
109 * @ipipeif: Pointer to ISP IPIPEIF device.
110 * @addr: 32-bit memory address aligned on 32 byte boundary.
112 * Sets the memory address where the output will be saved.
114 static void ipipeif_set_outaddr(struct iss_ipipeif_device
*ipipeif
, u32 addr
)
116 struct iss_device
*iss
= to_iss_device(ipipeif
);
118 /* Save address split in Base Address H & L */
119 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_CADU
,
120 (addr
>> (16 + 5)) & ISIF_CADU_MASK
);
121 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_CADL
,
122 (addr
>> 5) & ISIF_CADL_MASK
);
125 static void ipipeif_configure(struct iss_ipipeif_device
*ipipeif
)
127 struct iss_device
*iss
= to_iss_device(ipipeif
);
128 const struct iss_format_info
*info
;
129 struct v4l2_mbus_framefmt
*format
;
132 omap4iss_configure_bridge(iss
, ipipeif
->input
);
134 /* IPIPEIF_PAD_SINK */
135 format
= &ipipeif
->formats
[IPIPEIF_PAD_SINK
];
137 /* IPIPEIF with YUV422 input from ISIF */
138 iss_reg_clr(iss
, OMAP4_ISS_MEM_ISP_IPIPEIF
, IPIPEIF_CFG1
,
139 IPIPEIF_CFG1_INPSRC1_MASK
| IPIPEIF_CFG1_INPSRC2_MASK
);
141 /* Select ISIF/IPIPEIF input format */
142 switch (format
->code
) {
143 case MEDIA_BUS_FMT_UYVY8_1X16
:
144 case MEDIA_BUS_FMT_YUYV8_1X16
:
145 iss_reg_update(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_MODESET
,
146 ISIF_MODESET_CCDMD
| ISIF_MODESET_INPMOD_MASK
|
147 ISIF_MODESET_CCDW_MASK
,
148 ISIF_MODESET_INPMOD_YCBCR16
);
150 iss_reg_update(iss
, OMAP4_ISS_MEM_ISP_IPIPEIF
, IPIPEIF_CFG2
,
151 IPIPEIF_CFG2_YUV8
, IPIPEIF_CFG2_YUV16
);
154 case MEDIA_BUS_FMT_SGRBG10_1X10
:
155 isif_ccolp
= ISIF_CCOLP_CP0_F0_GR
|
156 ISIF_CCOLP_CP1_F0_R
|
157 ISIF_CCOLP_CP2_F0_B
|
158 ISIF_CCOLP_CP3_F0_GB
;
160 case MEDIA_BUS_FMT_SRGGB10_1X10
:
161 isif_ccolp
= ISIF_CCOLP_CP0_F0_R
|
162 ISIF_CCOLP_CP1_F0_GR
|
163 ISIF_CCOLP_CP2_F0_GB
|
166 case MEDIA_BUS_FMT_SBGGR10_1X10
:
167 isif_ccolp
= ISIF_CCOLP_CP0_F0_B
|
168 ISIF_CCOLP_CP1_F0_GB
|
169 ISIF_CCOLP_CP2_F0_GR
|
172 case MEDIA_BUS_FMT_SGBRG10_1X10
:
173 isif_ccolp
= ISIF_CCOLP_CP0_F0_GB
|
174 ISIF_CCOLP_CP1_F0_B
|
175 ISIF_CCOLP_CP2_F0_R
|
176 ISIF_CCOLP_CP3_F0_GR
;
178 iss_reg_clr(iss
, OMAP4_ISS_MEM_ISP_IPIPEIF
, IPIPEIF_CFG2
,
181 iss_reg_update(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_MODESET
,
182 ISIF_MODESET_CCDMD
| ISIF_MODESET_INPMOD_MASK
|
183 ISIF_MODESET_CCDW_MASK
, ISIF_MODESET_INPMOD_RAW
|
184 ISIF_MODESET_CCDW_2BIT
);
186 info
= omap4iss_video_format_info(format
->code
);
187 iss_reg_update(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_CGAMMAWD
,
188 ISIF_CGAMMAWD_GWDI_MASK
,
189 ISIF_CGAMMAWD_GWDI(info
->bpp
));
191 /* Set RAW Bayer pattern */
192 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_CCOLP
,
197 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_SPH
, 0 & ISIF_SPH_MASK
);
198 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_LNH
,
199 (format
->width
- 1) & ISIF_LNH_MASK
);
200 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_LNV
,
201 (format
->height
- 1) & ISIF_LNV_MASK
);
203 /* Generate ISIF0 on the last line of the image */
204 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_VDINT(0),
207 /* IPIPEIF_PAD_SOURCE_ISIF_SF */
208 format
= &ipipeif
->formats
[IPIPEIF_PAD_SOURCE_ISIF_SF
];
210 iss_reg_write(iss
, OMAP4_ISS_MEM_ISP_ISIF
, ISIF_HSIZE
,
211 (ipipeif
->video_out
.bpl_value
>> 5) &
212 ISIF_HSIZE_HSIZE_MASK
);
214 /* IPIPEIF_PAD_SOURCE_VP */
218 /* -----------------------------------------------------------------------------
222 static void ipipeif_isr_buffer(struct iss_ipipeif_device
*ipipeif
)
224 struct iss_buffer
*buffer
;
226 /* The ISIF generates VD0 interrupts even when writes are disabled.
227 * deal with it anyway). Disabling the ISIF when no buffer is available
228 * is thus not be enough, we need to handle the situation explicitly.
230 if (list_empty(&ipipeif
->video_out
.dmaqueue
))
233 ipipeif_write_enable(ipipeif
, 0);
235 buffer
= omap4iss_video_buffer_next(&ipipeif
->video_out
);
239 ipipeif_set_outaddr(ipipeif
, buffer
->iss_addr
);
241 ipipeif_write_enable(ipipeif
, 1);
245 * omap4iss_ipipeif_isr - Configure ipipeif during interframe time.
246 * @ipipeif: Pointer to ISP IPIPEIF device.
247 * @events: IPIPEIF events
249 void omap4iss_ipipeif_isr(struct iss_ipipeif_device
*ipipeif
, u32 events
)
251 if (omap4iss_module_sync_is_stopping(&ipipeif
->wait
,
255 if ((events
& ISP5_IRQ_ISIF_INT(0)) &&
256 (ipipeif
->output
& IPIPEIF_OUTPUT_MEMORY
))
257 ipipeif_isr_buffer(ipipeif
);
260 /* -----------------------------------------------------------------------------
261 * ISP video operations
264 static int ipipeif_video_queue(struct iss_video
*video
,
265 struct iss_buffer
*buffer
)
267 struct iss_ipipeif_device
*ipipeif
= container_of(video
,
268 struct iss_ipipeif_device
, video_out
);
270 if (!(ipipeif
->output
& IPIPEIF_OUTPUT_MEMORY
))
273 ipipeif_set_outaddr(ipipeif
, buffer
->iss_addr
);
276 * If streaming was enabled before there was a buffer queued
277 * or underrun happened in the ISR, the hardware was not enabled
278 * and DMA queue flag ISS_VIDEO_DMAQUEUE_UNDERRUN is still set.
281 if (video
->dmaqueue_flags
& ISS_VIDEO_DMAQUEUE_UNDERRUN
) {
282 if (ipipeif
->output
& IPIPEIF_OUTPUT_MEMORY
)
283 ipipeif_write_enable(ipipeif
, 1);
284 ipipeif_enable(ipipeif
, 1);
285 iss_video_dmaqueue_flags_clr(video
);
291 static const struct iss_video_operations ipipeif_video_ops
= {
292 .queue
= ipipeif_video_queue
,
295 /* -----------------------------------------------------------------------------
296 * V4L2 subdev operations
299 #define IPIPEIF_DRV_SUBCLK_MASK (OMAP4_ISS_ISP_SUBCLK_IPIPEIF |\
300 OMAP4_ISS_ISP_SUBCLK_ISIF)
302 * ipipeif_set_stream - Enable/Disable streaming on the IPIPEIF module
303 * @sd: ISP IPIPEIF V4L2 subdevice
304 * @enable: Enable/disable stream
306 static int ipipeif_set_stream(struct v4l2_subdev
*sd
, int enable
)
308 struct iss_ipipeif_device
*ipipeif
= v4l2_get_subdevdata(sd
);
309 struct iss_device
*iss
= to_iss_device(ipipeif
);
310 struct iss_video
*video_out
= &ipipeif
->video_out
;
313 if (ipipeif
->state
== ISS_PIPELINE_STREAM_STOPPED
) {
314 if (enable
== ISS_PIPELINE_STREAM_STOPPED
)
317 omap4iss_isp_subclk_enable(iss
, IPIPEIF_DRV_SUBCLK_MASK
);
321 case ISS_PIPELINE_STREAM_CONTINUOUS
:
323 ipipeif_configure(ipipeif
);
324 ipipeif_print_status(ipipeif
);
327 * When outputting to memory with no buffer available, let the
328 * buffer queue handler start the hardware. A DMA queue flag
329 * ISS_VIDEO_DMAQUEUE_QUEUED will be set as soon as there is
330 * a buffer available.
332 if (ipipeif
->output
& IPIPEIF_OUTPUT_MEMORY
&&
333 !(video_out
->dmaqueue_flags
& ISS_VIDEO_DMAQUEUE_QUEUED
))
336 atomic_set(&ipipeif
->stopping
, 0);
337 if (ipipeif
->output
& IPIPEIF_OUTPUT_MEMORY
)
338 ipipeif_write_enable(ipipeif
, 1);
339 ipipeif_enable(ipipeif
, 1);
340 iss_video_dmaqueue_flags_clr(video_out
);
343 case ISS_PIPELINE_STREAM_STOPPED
:
344 if (ipipeif
->state
== ISS_PIPELINE_STREAM_STOPPED
)
346 if (omap4iss_module_sync_idle(&sd
->entity
, &ipipeif
->wait
,
350 if (ipipeif
->output
& IPIPEIF_OUTPUT_MEMORY
)
351 ipipeif_write_enable(ipipeif
, 0);
352 ipipeif_enable(ipipeif
, 0);
353 omap4iss_isp_subclk_disable(iss
, IPIPEIF_DRV_SUBCLK_MASK
);
354 iss_video_dmaqueue_flags_clr(video_out
);
358 ipipeif
->state
= enable
;
362 static struct v4l2_mbus_framefmt
*
363 __ipipeif_get_format(struct iss_ipipeif_device
*ipipeif
,
364 struct v4l2_subdev_pad_config
*cfg
, unsigned int pad
,
365 enum v4l2_subdev_format_whence which
)
367 if (which
== V4L2_SUBDEV_FORMAT_TRY
)
368 return v4l2_subdev_get_try_format(&ipipeif
->subdev
, cfg
, pad
);
369 return &ipipeif
->formats
[pad
];
373 * ipipeif_try_format - Try video format on a pad
374 * @ipipeif: ISS IPIPEIF device
375 * @cfg: V4L2 subdev pad config
380 ipipeif_try_format(struct iss_ipipeif_device
*ipipeif
,
381 struct v4l2_subdev_pad_config
*cfg
, unsigned int pad
,
382 struct v4l2_mbus_framefmt
*fmt
,
383 enum v4l2_subdev_format_whence which
)
385 struct v4l2_mbus_framefmt
*format
;
386 unsigned int width
= fmt
->width
;
387 unsigned int height
= fmt
->height
;
391 case IPIPEIF_PAD_SINK
:
392 /* TODO: If the IPIPEIF output formatter pad is connected
393 * directly to the resizer, only YUV formats can be used.
395 for (i
= 0; i
< ARRAY_SIZE(ipipeif_fmts
); i
++) {
396 if (fmt
->code
== ipipeif_fmts
[i
])
400 /* If not found, use SGRBG10 as default */
401 if (i
>= ARRAY_SIZE(ipipeif_fmts
))
402 fmt
->code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
404 /* Clamp the input size. */
405 fmt
->width
= clamp_t(u32
, width
, 1, 8192);
406 fmt
->height
= clamp_t(u32
, height
, 1, 8192);
409 case IPIPEIF_PAD_SOURCE_ISIF_SF
:
410 format
= __ipipeif_get_format(ipipeif
, cfg
, IPIPEIF_PAD_SINK
,
412 memcpy(fmt
, format
, sizeof(*fmt
));
414 /* The data formatter truncates the number of horizontal output
415 * pixels to a multiple of 16. To avoid clipping data, allow
416 * callers to request an output size bigger than the input size
417 * up to the nearest multiple of 16.
419 fmt
->width
= clamp_t(u32
, width
, 32, (fmt
->width
+ 15) & ~15);
421 fmt
->height
= clamp_t(u32
, height
, 32, fmt
->height
);
424 case IPIPEIF_PAD_SOURCE_VP
:
425 format
= __ipipeif_get_format(ipipeif
, cfg
, IPIPEIF_PAD_SINK
,
427 memcpy(fmt
, format
, sizeof(*fmt
));
429 fmt
->width
= clamp_t(u32
, width
, 32, fmt
->width
);
430 fmt
->height
= clamp_t(u32
, height
, 32, fmt
->height
);
434 /* Data is written to memory unpacked, each 10-bit or 12-bit pixel is
437 fmt
->colorspace
= V4L2_COLORSPACE_SRGB
;
438 fmt
->field
= V4L2_FIELD_NONE
;
442 * ipipeif_enum_mbus_code - Handle pixel format enumeration
443 * @sd : pointer to v4l2 subdev structure
444 * @cfg : V4L2 subdev pad config
445 * @code : pointer to v4l2_subdev_mbus_code_enum structure
446 * return -EINVAL or zero on success
448 static int ipipeif_enum_mbus_code(struct v4l2_subdev
*sd
,
449 struct v4l2_subdev_pad_config
*cfg
,
450 struct v4l2_subdev_mbus_code_enum
*code
)
452 struct iss_ipipeif_device
*ipipeif
= v4l2_get_subdevdata(sd
);
453 struct v4l2_mbus_framefmt
*format
;
456 case IPIPEIF_PAD_SINK
:
457 if (code
->index
>= ARRAY_SIZE(ipipeif_fmts
))
460 code
->code
= ipipeif_fmts
[code
->index
];
463 case IPIPEIF_PAD_SOURCE_ISIF_SF
:
464 case IPIPEIF_PAD_SOURCE_VP
:
465 /* No format conversion inside IPIPEIF */
466 if (code
->index
!= 0)
469 format
= __ipipeif_get_format(ipipeif
, cfg
, IPIPEIF_PAD_SINK
,
472 code
->code
= format
->code
;
482 static int ipipeif_enum_frame_size(struct v4l2_subdev
*sd
,
483 struct v4l2_subdev_pad_config
*cfg
,
484 struct v4l2_subdev_frame_size_enum
*fse
)
486 struct iss_ipipeif_device
*ipipeif
= v4l2_get_subdevdata(sd
);
487 struct v4l2_mbus_framefmt format
;
492 format
.code
= fse
->code
;
495 ipipeif_try_format(ipipeif
, cfg
, fse
->pad
, &format
, fse
->which
);
496 fse
->min_width
= format
.width
;
497 fse
->min_height
= format
.height
;
499 if (format
.code
!= fse
->code
)
502 format
.code
= fse
->code
;
505 ipipeif_try_format(ipipeif
, cfg
, fse
->pad
, &format
, fse
->which
);
506 fse
->max_width
= format
.width
;
507 fse
->max_height
= format
.height
;
513 * ipipeif_get_format - Retrieve the video format on a pad
514 * @sd : ISP IPIPEIF V4L2 subdevice
515 * @cfg: V4L2 subdev pad config
518 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
519 * to the format type.
521 static int ipipeif_get_format(struct v4l2_subdev
*sd
,
522 struct v4l2_subdev_pad_config
*cfg
,
523 struct v4l2_subdev_format
*fmt
)
525 struct iss_ipipeif_device
*ipipeif
= v4l2_get_subdevdata(sd
);
526 struct v4l2_mbus_framefmt
*format
;
528 format
= __ipipeif_get_format(ipipeif
, cfg
, fmt
->pad
, fmt
->which
);
532 fmt
->format
= *format
;
537 * ipipeif_set_format - Set the video format on a pad
538 * @sd : ISP IPIPEIF V4L2 subdevice
539 * @cfg: V4L2 subdev pad config
542 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
543 * to the format type.
545 static int ipipeif_set_format(struct v4l2_subdev
*sd
,
546 struct v4l2_subdev_pad_config
*cfg
,
547 struct v4l2_subdev_format
*fmt
)
549 struct iss_ipipeif_device
*ipipeif
= v4l2_get_subdevdata(sd
);
550 struct v4l2_mbus_framefmt
*format
;
552 format
= __ipipeif_get_format(ipipeif
, cfg
, fmt
->pad
, fmt
->which
);
556 ipipeif_try_format(ipipeif
, cfg
, fmt
->pad
, &fmt
->format
, fmt
->which
);
557 *format
= fmt
->format
;
559 /* Propagate the format from sink to source */
560 if (fmt
->pad
== IPIPEIF_PAD_SINK
) {
561 format
= __ipipeif_get_format(ipipeif
, cfg
,
562 IPIPEIF_PAD_SOURCE_ISIF_SF
,
564 *format
= fmt
->format
;
565 ipipeif_try_format(ipipeif
, cfg
, IPIPEIF_PAD_SOURCE_ISIF_SF
,
568 format
= __ipipeif_get_format(ipipeif
, cfg
,
569 IPIPEIF_PAD_SOURCE_VP
,
571 *format
= fmt
->format
;
572 ipipeif_try_format(ipipeif
, cfg
, IPIPEIF_PAD_SOURCE_VP
, format
,
579 static int ipipeif_link_validate(struct v4l2_subdev
*sd
,
580 struct media_link
*link
,
581 struct v4l2_subdev_format
*source_fmt
,
582 struct v4l2_subdev_format
*sink_fmt
)
584 /* Check if the two ends match */
585 if (source_fmt
->format
.width
!= sink_fmt
->format
.width
||
586 source_fmt
->format
.height
!= sink_fmt
->format
.height
)
589 if (source_fmt
->format
.code
!= sink_fmt
->format
.code
)
596 * ipipeif_init_formats - Initialize formats on all pads
597 * @sd: ISP IPIPEIF V4L2 subdevice
598 * @fh: V4L2 subdev file handle
600 * Initialize all pad formats with default values. If fh is not NULL, try
601 * formats are initialized on the file handle. Otherwise active formats are
602 * initialized on the device.
604 static int ipipeif_init_formats(struct v4l2_subdev
*sd
,
605 struct v4l2_subdev_fh
*fh
)
607 struct v4l2_subdev_format format
;
609 memset(&format
, 0, sizeof(format
));
610 format
.pad
= IPIPEIF_PAD_SINK
;
611 format
.which
= fh
? V4L2_SUBDEV_FORMAT_TRY
: V4L2_SUBDEV_FORMAT_ACTIVE
;
612 format
.format
.code
= MEDIA_BUS_FMT_SGRBG10_1X10
;
613 format
.format
.width
= 4096;
614 format
.format
.height
= 4096;
615 ipipeif_set_format(sd
, fh
? fh
->pad
: NULL
, &format
);
620 /* V4L2 subdev video operations */
621 static const struct v4l2_subdev_video_ops ipipeif_v4l2_video_ops
= {
622 .s_stream
= ipipeif_set_stream
,
625 /* V4L2 subdev pad operations */
626 static const struct v4l2_subdev_pad_ops ipipeif_v4l2_pad_ops
= {
627 .enum_mbus_code
= ipipeif_enum_mbus_code
,
628 .enum_frame_size
= ipipeif_enum_frame_size
,
629 .get_fmt
= ipipeif_get_format
,
630 .set_fmt
= ipipeif_set_format
,
631 .link_validate
= ipipeif_link_validate
,
634 /* V4L2 subdev operations */
635 static const struct v4l2_subdev_ops ipipeif_v4l2_ops
= {
636 .video
= &ipipeif_v4l2_video_ops
,
637 .pad
= &ipipeif_v4l2_pad_ops
,
640 /* V4L2 subdev internal operations */
641 static const struct v4l2_subdev_internal_ops ipipeif_v4l2_internal_ops
= {
642 .open
= ipipeif_init_formats
,
645 /* -----------------------------------------------------------------------------
646 * Media entity operations
650 * ipipeif_link_setup - Setup IPIPEIF connections
651 * @entity: IPIPEIF media entity
652 * @local: Pad at the local end of the link
653 * @remote: Pad at the remote end of the link
656 * return -EINVAL or zero on success
658 static int ipipeif_link_setup(struct media_entity
*entity
,
659 const struct media_pad
*local
,
660 const struct media_pad
*remote
, u32 flags
)
662 struct v4l2_subdev
*sd
= media_entity_to_v4l2_subdev(entity
);
663 struct iss_ipipeif_device
*ipipeif
= v4l2_get_subdevdata(sd
);
664 struct iss_device
*iss
= to_iss_device(ipipeif
);
666 switch (local
->index
| media_entity_type(remote
->entity
)) {
667 case IPIPEIF_PAD_SINK
| MEDIA_ENT_T_V4L2_SUBDEV
:
668 /* Read from the sensor CSI2a or CSI2b. */
669 if (!(flags
& MEDIA_LNK_FL_ENABLED
)) {
670 ipipeif
->input
= IPIPEIF_INPUT_NONE
;
674 if (ipipeif
->input
!= IPIPEIF_INPUT_NONE
)
677 if (remote
->entity
== &iss
->csi2a
.subdev
.entity
)
678 ipipeif
->input
= IPIPEIF_INPUT_CSI2A
;
679 else if (remote
->entity
== &iss
->csi2b
.subdev
.entity
)
680 ipipeif
->input
= IPIPEIF_INPUT_CSI2B
;
684 case IPIPEIF_PAD_SOURCE_ISIF_SF
| MEDIA_ENT_T_DEVNODE
:
685 /* Write to memory */
686 if (flags
& MEDIA_LNK_FL_ENABLED
) {
687 if (ipipeif
->output
& ~IPIPEIF_OUTPUT_MEMORY
)
689 ipipeif
->output
|= IPIPEIF_OUTPUT_MEMORY
;
691 ipipeif
->output
&= ~IPIPEIF_OUTPUT_MEMORY
;
695 case IPIPEIF_PAD_SOURCE_VP
| MEDIA_ENT_T_V4L2_SUBDEV
:
696 /* Send to IPIPE/RESIZER */
697 if (flags
& MEDIA_LNK_FL_ENABLED
) {
698 if (ipipeif
->output
& ~IPIPEIF_OUTPUT_VP
)
700 ipipeif
->output
|= IPIPEIF_OUTPUT_VP
;
702 ipipeif
->output
&= ~IPIPEIF_OUTPUT_VP
;
713 /* media operations */
714 static const struct media_entity_operations ipipeif_media_ops
= {
715 .link_setup
= ipipeif_link_setup
,
716 .link_validate
= v4l2_subdev_link_validate
,
720 * ipipeif_init_entities - Initialize V4L2 subdev and media entity
721 * @ipipeif: ISS ISP IPIPEIF module
723 * Return 0 on success and a negative error code on failure.
725 static int ipipeif_init_entities(struct iss_ipipeif_device
*ipipeif
)
727 struct v4l2_subdev
*sd
= &ipipeif
->subdev
;
728 struct media_pad
*pads
= ipipeif
->pads
;
729 struct media_entity
*me
= &sd
->entity
;
732 ipipeif
->input
= IPIPEIF_INPUT_NONE
;
734 v4l2_subdev_init(sd
, &ipipeif_v4l2_ops
);
735 sd
->internal_ops
= &ipipeif_v4l2_internal_ops
;
736 strlcpy(sd
->name
, "OMAP4 ISS ISP IPIPEIF", sizeof(sd
->name
));
737 sd
->grp_id
= 1 << 16; /* group ID for iss subdevs */
738 v4l2_set_subdevdata(sd
, ipipeif
);
739 sd
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
741 pads
[IPIPEIF_PAD_SINK
].flags
= MEDIA_PAD_FL_SINK
;
742 pads
[IPIPEIF_PAD_SOURCE_ISIF_SF
].flags
= MEDIA_PAD_FL_SOURCE
;
743 pads
[IPIPEIF_PAD_SOURCE_VP
].flags
= MEDIA_PAD_FL_SOURCE
;
745 me
->ops
= &ipipeif_media_ops
;
746 ret
= media_entity_init(me
, IPIPEIF_PADS_NUM
, pads
, 0);
750 ipipeif_init_formats(sd
, NULL
);
752 ipipeif
->video_out
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
753 ipipeif
->video_out
.ops
= &ipipeif_video_ops
;
754 ipipeif
->video_out
.iss
= to_iss_device(ipipeif
);
755 ipipeif
->video_out
.capture_mem
= PAGE_ALIGN(4096 * 4096) * 3;
756 ipipeif
->video_out
.bpl_alignment
= 32;
757 ipipeif
->video_out
.bpl_zero_padding
= 1;
758 ipipeif
->video_out
.bpl_max
= 0x1ffe0;
760 ret
= omap4iss_video_init(&ipipeif
->video_out
, "ISP IPIPEIF");
764 /* Connect the IPIPEIF subdev to the video node. */
765 ret
= media_entity_create_link(&ipipeif
->subdev
.entity
,
766 IPIPEIF_PAD_SOURCE_ISIF_SF
,
767 &ipipeif
->video_out
.video
.entity
, 0, 0);
774 void omap4iss_ipipeif_unregister_entities(struct iss_ipipeif_device
*ipipeif
)
776 v4l2_device_unregister_subdev(&ipipeif
->subdev
);
777 omap4iss_video_unregister(&ipipeif
->video_out
);
780 int omap4iss_ipipeif_register_entities(struct iss_ipipeif_device
*ipipeif
,
781 struct v4l2_device
*vdev
)
785 /* Register the subdev and video node. */
786 ret
= v4l2_device_register_subdev(vdev
, &ipipeif
->subdev
);
790 ret
= omap4iss_video_register(&ipipeif
->video_out
, vdev
);
797 omap4iss_ipipeif_unregister_entities(ipipeif
);
801 /* -----------------------------------------------------------------------------
802 * ISP IPIPEIF initialisation and cleanup
806 * omap4iss_ipipeif_init - IPIPEIF module initialization.
807 * @iss: Device pointer specific to the OMAP4 ISS.
809 * TODO: Get the initialisation values from platform data.
811 * Return 0 on success or a negative error code otherwise.
813 int omap4iss_ipipeif_init(struct iss_device
*iss
)
815 struct iss_ipipeif_device
*ipipeif
= &iss
->ipipeif
;
817 ipipeif
->state
= ISS_PIPELINE_STREAM_STOPPED
;
818 init_waitqueue_head(&ipipeif
->wait
);
820 return ipipeif_init_entities(ipipeif
);
824 * omap4iss_ipipeif_cleanup - IPIPEIF module cleanup.
825 * @iss: Device pointer specific to the OMAP4 ISS.
827 void omap4iss_ipipeif_cleanup(struct iss_device
*iss
)
829 struct iss_ipipeif_device
*ipipeif
= &iss
->ipipeif
;
831 media_entity_cleanup(&ipipeif
->subdev
.entity
);