2 * TI VPFE capture Driver
4 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
6 * Benoit Parrot <bparrot@ti.com>
7 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/pinctrl/consumer.h>
30 #include <linux/platform_device.h>
31 #include <linux/pm_runtime.h>
32 #include <linux/slab.h>
33 #include <linux/uaccess.h>
34 #include <linux/videodev2.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-ctrls.h>
38 #include <media/v4l2-event.h>
39 #include <media/v4l2-of.h>
41 #include "am437x-vpfe.h"
43 #define VPFE_MODULE_NAME "vpfe"
44 #define VPFE_VERSION "0.1.0"
47 module_param(debug, int, 0644);
48 MODULE_PARM_DESC(debug, "Debug level 0-8");
50 #define vpfe_dbg(level, dev, fmt, arg...) \
51 v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ##arg)
52 #define vpfe_info(dev, fmt, arg...) \
53 v4l2_info(&dev->v4l2_dev, fmt, ##arg)
54 #define vpfe_err(dev, fmt, arg...) \
55 v4l2_err(&dev->v4l2_dev, fmt, ##arg)
57 /* standard information */
58 struct vpfe_standard {
62 struct v4l2_fract pixelaspect;
66 static const struct vpfe_standard vpfe_standards[] = {
67 {V4L2_STD_525_60, 720, 480, {11, 10}, 1},
68 {V4L2_STD_625_50, 720, 576, {54, 59}, 1},
77 * struct vpfe_fmt - VPFE media bus format information
78 * @name: V4L2 format description
79 * @code: V4L2 media bus format code
80 * @shifted: V4L2 media bus format code for the same pixel layout but
81 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
82 * @pixelformat: V4L2 pixel format FCC identifier
83 * @width: Bits per pixel (when transferred over a bus)
84 * @bpp: Bytes per pixel (when stored in memory)
85 * @supported: Indicates format supported by subdev
97 static struct vpfe_fmt formats[] = {
99 .name = "YUV 4:2:2 packed, YCbYCr",
100 .fourcc = V4L2_PIX_FMT_YUYV,
101 .code = MEDIA_BUS_FMT_YUYV8_2X8,
108 .name = "YUV 4:2:2 packed, CbYCrY",
109 .fourcc = V4L2_PIX_FMT_UYVY,
110 .code = MEDIA_BUS_FMT_UYVY8_2X8,
117 .name = "YUV 4:2:2 packed, YCrYCb",
118 .fourcc = V4L2_PIX_FMT_YVYU,
119 .code = MEDIA_BUS_FMT_YVYU8_2X8,
126 .name = "YUV 4:2:2 packed, CrYCbY",
127 .fourcc = V4L2_PIX_FMT_VYUY,
128 .code = MEDIA_BUS_FMT_VYUY8_2X8,
136 .fourcc = V4L2_PIX_FMT_SBGGR8,
137 .code = MEDIA_BUS_FMT_SBGGR8_1X8,
145 .fourcc = V4L2_PIX_FMT_SGBRG8,
146 .code = MEDIA_BUS_FMT_SGBRG8_1X8,
154 .fourcc = V4L2_PIX_FMT_SGRBG8,
155 .code = MEDIA_BUS_FMT_SGRBG8_1X8,
163 .fourcc = V4L2_PIX_FMT_SRGGB8,
164 .code = MEDIA_BUS_FMT_SRGGB8_1X8,
171 .name = "RGB565 (LE)",
172 .fourcc = V4L2_PIX_FMT_RGB565,
173 .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
180 .name = "RGB565 (BE)",
181 .fourcc = V4L2_PIX_FMT_RGB565X,
182 .code = MEDIA_BUS_FMT_RGB565_2X8_BE,
192 __vpfe_get_format(struct vpfe_device *vpfe,
193 struct v4l2_format *format, unsigned int *bpp);
195 static struct vpfe_fmt *find_format_by_code(unsigned int code)
197 struct vpfe_fmt *fmt;
200 for (k = 0; k < ARRAY_SIZE(formats); k++) {
202 if (fmt->code == code)
209 static struct vpfe_fmt *find_format_by_pix(unsigned int pixelformat)
211 struct vpfe_fmt *fmt;
214 for (k = 0; k < ARRAY_SIZE(formats); k++) {
216 if (fmt->fourcc == pixelformat)
224 mbus_to_pix(struct vpfe_device *vpfe,
225 const struct v4l2_mbus_framefmt *mbus,
226 struct v4l2_pix_format *pix, unsigned int *bpp)
228 struct vpfe_subdev_info *sdinfo = vpfe->current_subdev;
229 unsigned int bus_width = sdinfo->vpfe_param.bus_width;
230 struct vpfe_fmt *fmt;
232 fmt = find_format_by_code(mbus->code);
233 if (WARN_ON(fmt == NULL)) {
234 pr_err("Invalid mbus code set\n");
239 memset(pix, 0, sizeof(*pix));
240 v4l2_fill_pix_format(pix, mbus);
241 pix->pixelformat = fmt->fourcc;
242 *bpp = (bus_width == 10) ? fmt->l.bpp : fmt->s.bpp;
244 /* pitch should be 32 bytes aligned */
245 pix->bytesperline = ALIGN(pix->width * *bpp, 32);
246 pix->sizeimage = pix->bytesperline * pix->height;
249 static void pix_to_mbus(struct vpfe_device *vpfe,
250 struct v4l2_pix_format *pix_fmt,
251 struct v4l2_mbus_framefmt *mbus_fmt)
253 struct vpfe_fmt *fmt;
255 fmt = find_format_by_pix(pix_fmt->pixelformat);
257 /* default to first entry */
258 vpfe_dbg(3, vpfe, "Invalid pixel code: %x, default used instead\n",
259 pix_fmt->pixelformat);
263 memset(mbus_fmt, 0, sizeof(*mbus_fmt));
264 v4l2_fill_mbus_format(mbus_fmt, pix_fmt, fmt->code);
267 /* Print Four-character-code (FOURCC) */
268 static char *print_fourcc(u32 fmt)
272 code[0] = (unsigned char)(fmt & 0xff);
273 code[1] = (unsigned char)((fmt >> 8) & 0xff);
274 code[2] = (unsigned char)((fmt >> 16) & 0xff);
275 code[3] = (unsigned char)((fmt >> 24) & 0xff);
282 cmp_v4l2_format(const struct v4l2_format *lhs, const struct v4l2_format *rhs)
284 return lhs->type == rhs->type &&
285 lhs->fmt.pix.width == rhs->fmt.pix.width &&
286 lhs->fmt.pix.height == rhs->fmt.pix.height &&
287 lhs->fmt.pix.pixelformat == rhs->fmt.pix.pixelformat &&
288 lhs->fmt.pix.field == rhs->fmt.pix.field &&
289 lhs->fmt.pix.colorspace == rhs->fmt.pix.colorspace &&
290 lhs->fmt.pix.ycbcr_enc == rhs->fmt.pix.ycbcr_enc &&
291 lhs->fmt.pix.quantization == rhs->fmt.pix.quantization;
294 static inline u32 vpfe_reg_read(struct vpfe_ccdc *ccdc, u32 offset)
296 return ioread32(ccdc->ccdc_cfg.base_addr + offset);
299 static inline void vpfe_reg_write(struct vpfe_ccdc *ccdc, u32 val, u32 offset)
301 iowrite32(val, ccdc->ccdc_cfg.base_addr + offset);
304 static inline struct vpfe_device *to_vpfe(struct vpfe_ccdc *ccdc)
306 return container_of(ccdc, struct vpfe_device, ccdc);
309 static inline struct vpfe_cap_buffer *to_vpfe_buffer(struct vb2_buffer *vb)
311 return container_of(vb, struct vpfe_cap_buffer, vb);
314 static inline void vpfe_pcr_enable(struct vpfe_ccdc *ccdc, int flag)
316 vpfe_reg_write(ccdc, !!flag, VPFE_PCR);
319 static void vpfe_config_enable(struct vpfe_ccdc *ccdc, int flag)
324 cfg = vpfe_reg_read(ccdc, VPFE_CONFIG);
325 cfg &= ~(VPFE_CONFIG_EN_ENABLE << VPFE_CONFIG_EN_SHIFT);
327 cfg = VPFE_CONFIG_EN_ENABLE << VPFE_CONFIG_EN_SHIFT;
330 vpfe_reg_write(ccdc, cfg, VPFE_CONFIG);
333 static void vpfe_ccdc_setwin(struct vpfe_ccdc *ccdc,
334 struct v4l2_rect *image_win,
335 enum ccdc_frmfmt frm_fmt,
338 int horz_start, horz_nr_pixels;
339 int vert_start, vert_nr_lines;
343 * ppc - per pixel count. indicates how many pixels per cell
344 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
345 * raw capture this is 1
347 horz_start = image_win->left * bpp;
348 horz_nr_pixels = (image_win->width * bpp) - 1;
349 vpfe_reg_write(ccdc, (horz_start << VPFE_HORZ_INFO_SPH_SHIFT) |
350 horz_nr_pixels, VPFE_HORZ_INFO);
352 vert_start = image_win->top;
354 if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
355 vert_nr_lines = (image_win->height >> 1) - 1;
357 /* Since first line doesn't have any data */
359 /* configure VDINT0 */
360 val = (vert_start << VPFE_VDINT_VDINT0_SHIFT);
362 /* Since first line doesn't have any data */
364 vert_nr_lines = image_win->height - 1;
366 * configure VDINT0 and VDINT1. VDINT1 will be at half
369 mid_img = vert_start + (image_win->height / 2);
370 val = (vert_start << VPFE_VDINT_VDINT0_SHIFT) |
371 (mid_img & VPFE_VDINT_VDINT1_MASK);
374 vpfe_reg_write(ccdc, val, VPFE_VDINT);
376 vpfe_reg_write(ccdc, (vert_start << VPFE_VERT_START_SLV0_SHIFT) |
377 vert_start, VPFE_VERT_START);
378 vpfe_reg_write(ccdc, vert_nr_lines, VPFE_VERT_LINES);
381 static void vpfe_reg_dump(struct vpfe_ccdc *ccdc)
383 struct vpfe_device *vpfe = to_vpfe(ccdc);
385 vpfe_dbg(3, vpfe, "ALAW: 0x%x\n", vpfe_reg_read(ccdc, VPFE_ALAW));
386 vpfe_dbg(3, vpfe, "CLAMP: 0x%x\n", vpfe_reg_read(ccdc, VPFE_CLAMP));
387 vpfe_dbg(3, vpfe, "DCSUB: 0x%x\n", vpfe_reg_read(ccdc, VPFE_DCSUB));
388 vpfe_dbg(3, vpfe, "BLKCMP: 0x%x\n", vpfe_reg_read(ccdc, VPFE_BLKCMP));
389 vpfe_dbg(3, vpfe, "COLPTN: 0x%x\n", vpfe_reg_read(ccdc, VPFE_COLPTN));
390 vpfe_dbg(3, vpfe, "SDOFST: 0x%x\n", vpfe_reg_read(ccdc, VPFE_SDOFST));
391 vpfe_dbg(3, vpfe, "SYN_MODE: 0x%x\n",
392 vpfe_reg_read(ccdc, VPFE_SYNMODE));
393 vpfe_dbg(3, vpfe, "HSIZE_OFF: 0x%x\n",
394 vpfe_reg_read(ccdc, VPFE_HSIZE_OFF));
395 vpfe_dbg(3, vpfe, "HORZ_INFO: 0x%x\n",
396 vpfe_reg_read(ccdc, VPFE_HORZ_INFO));
397 vpfe_dbg(3, vpfe, "VERT_START: 0x%x\n",
398 vpfe_reg_read(ccdc, VPFE_VERT_START));
399 vpfe_dbg(3, vpfe, "VERT_LINES: 0x%x\n",
400 vpfe_reg_read(ccdc, VPFE_VERT_LINES));
404 vpfe_ccdc_validate_param(struct vpfe_ccdc *ccdc,
405 struct vpfe_ccdc_config_params_raw *ccdcparam)
407 struct vpfe_device *vpfe = to_vpfe(ccdc);
408 u8 max_gamma, max_data;
410 if (!ccdcparam->alaw.enable)
413 max_gamma = ccdc_gamma_width_max_bit(ccdcparam->alaw.gamma_wd);
414 max_data = ccdc_data_size_max_bit(ccdcparam->data_sz);
416 if (ccdcparam->alaw.gamma_wd > VPFE_CCDC_GAMMA_BITS_09_0 ||
417 ccdcparam->alaw.gamma_wd < VPFE_CCDC_GAMMA_BITS_15_6 ||
418 max_gamma > max_data) {
419 vpfe_dbg(1, vpfe, "Invalid data line select\n");
427 vpfe_ccdc_update_raw_params(struct vpfe_ccdc *ccdc,
428 struct vpfe_ccdc_config_params_raw *raw_params)
430 struct vpfe_ccdc_config_params_raw *config_params =
431 &ccdc->ccdc_cfg.bayer.config_params;
433 config_params = raw_params;
437 * vpfe_ccdc_restore_defaults()
438 * This function will write defaults to all CCDC registers
440 static void vpfe_ccdc_restore_defaults(struct vpfe_ccdc *ccdc)
445 vpfe_pcr_enable(ccdc, 0);
447 /* set all registers to default value */
448 for (i = 4; i <= 0x94; i += 4)
449 vpfe_reg_write(ccdc, 0, i);
451 vpfe_reg_write(ccdc, VPFE_NO_CULLING, VPFE_CULLING);
452 vpfe_reg_write(ccdc, VPFE_CCDC_GAMMA_BITS_11_2, VPFE_ALAW);
455 static int vpfe_ccdc_close(struct vpfe_ccdc *ccdc, struct device *dev)
457 int dma_cntl, i, pcr;
459 /* If the CCDC module is still busy wait for it to be done */
460 for (i = 0; i < 10; i++) {
461 usleep_range(5000, 6000);
462 pcr = vpfe_reg_read(ccdc, VPFE_PCR);
466 /* make sure it it is disabled */
467 vpfe_pcr_enable(ccdc, 0);
470 /* Disable CCDC by resetting all register to default POR values */
471 vpfe_ccdc_restore_defaults(ccdc);
473 /* if DMA_CNTL overflow bit is set. Clear it
474 * It appears to take a while for this to become quiescent ~20ms
476 for (i = 0; i < 10; i++) {
477 dma_cntl = vpfe_reg_read(ccdc, VPFE_DMA_CNTL);
478 if (!(dma_cntl & VPFE_DMA_CNTL_OVERFLOW))
481 /* Clear the overflow bit */
482 vpfe_reg_write(ccdc, dma_cntl, VPFE_DMA_CNTL);
483 usleep_range(5000, 6000);
486 /* Disabled the module at the CONFIG level */
487 vpfe_config_enable(ccdc, 0);
489 pm_runtime_put_sync(dev);
494 static int vpfe_ccdc_set_params(struct vpfe_ccdc *ccdc, void __user *params)
496 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
497 struct vpfe_ccdc_config_params_raw raw_params;
500 if (ccdc->ccdc_cfg.if_type != VPFE_RAW_BAYER)
503 x = copy_from_user(&raw_params, params, sizeof(raw_params));
506 "vpfe_ccdc_set_params: error in copying ccdc params, %d\n",
511 if (!vpfe_ccdc_validate_param(ccdc, &raw_params)) {
512 vpfe_ccdc_update_raw_params(ccdc, &raw_params);
520 * vpfe_ccdc_config_ycbcr()
521 * This function will configure CCDC for YCbCr video capture
523 static void vpfe_ccdc_config_ycbcr(struct vpfe_ccdc *ccdc)
525 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
526 struct ccdc_params_ycbcr *params = &ccdc->ccdc_cfg.ycbcr;
529 vpfe_dbg(3, vpfe, "vpfe_ccdc_config_ycbcr:\n");
531 * first restore the CCDC registers to default values
532 * This is important since we assume default values to be set in
533 * a lot of registers that we didn't touch
535 vpfe_ccdc_restore_defaults(ccdc);
538 * configure pixel format, frame format, configure video frame
539 * format, enable output to SDRAM, enable internal timing generator
542 syn_mode = (((params->pix_fmt & VPFE_SYN_MODE_INPMOD_MASK) <<
543 VPFE_SYN_MODE_INPMOD_SHIFT) |
544 ((params->frm_fmt & VPFE_SYN_FLDMODE_MASK) <<
545 VPFE_SYN_FLDMODE_SHIFT) | VPFE_VDHDEN_ENABLE |
546 VPFE_WEN_ENABLE | VPFE_DATA_PACK_ENABLE);
548 /* setup BT.656 sync mode */
549 if (params->bt656_enable) {
550 vpfe_reg_write(ccdc, VPFE_REC656IF_BT656_EN, VPFE_REC656IF);
553 * configure the FID, VD, HD pin polarity,
554 * fld,hd pol positive, vd negative, 8-bit data
556 syn_mode |= VPFE_SYN_MODE_VD_POL_NEGATIVE;
557 if (ccdc->ccdc_cfg.if_type == VPFE_BT656_10BIT)
558 syn_mode |= VPFE_SYN_MODE_10BITS;
560 syn_mode |= VPFE_SYN_MODE_8BITS;
562 /* y/c external sync mode */
563 syn_mode |= (((params->fid_pol & VPFE_FID_POL_MASK) <<
564 VPFE_FID_POL_SHIFT) |
565 ((params->hd_pol & VPFE_HD_POL_MASK) <<
567 ((params->vd_pol & VPFE_VD_POL_MASK) <<
570 vpfe_reg_write(ccdc, syn_mode, VPFE_SYNMODE);
572 /* configure video window */
573 vpfe_ccdc_setwin(ccdc, ¶ms->win,
574 params->frm_fmt, params->bytesperpixel);
577 * configure the order of y cb cr in SDRAM, and disable latch
578 * internal register on vsync
580 if (ccdc->ccdc_cfg.if_type == VPFE_BT656_10BIT)
582 (params->pix_order << VPFE_CCDCFG_Y8POS_SHIFT) |
583 VPFE_LATCH_ON_VSYNC_DISABLE |
584 VPFE_CCDCFG_BW656_10BIT, VPFE_CCDCFG);
587 (params->pix_order << VPFE_CCDCFG_Y8POS_SHIFT) |
588 VPFE_LATCH_ON_VSYNC_DISABLE, VPFE_CCDCFG);
591 * configure the horizontal line offset. This should be a
592 * on 32 byte boundary. So clear LSB 5 bits
594 vpfe_reg_write(ccdc, params->bytesperline, VPFE_HSIZE_OFF);
596 /* configure the memory line offset */
597 if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED)
598 /* two fields are interleaved in memory */
599 vpfe_reg_write(ccdc, VPFE_SDOFST_FIELD_INTERLEAVED,
604 vpfe_ccdc_config_black_clamp(struct vpfe_ccdc *ccdc,
605 struct vpfe_ccdc_black_clamp *bclamp)
609 if (!bclamp->enable) {
610 /* configure DCSub */
611 val = (bclamp->dc_sub) & VPFE_BLK_DC_SUB_MASK;
612 vpfe_reg_write(ccdc, val, VPFE_DCSUB);
613 vpfe_reg_write(ccdc, VPFE_CLAMP_DEFAULT_VAL, VPFE_CLAMP);
617 * Configure gain, Start pixel, No of line to be avg,
618 * No of pixel/line to be avg, & Enable the Black clamping
620 val = ((bclamp->sgain & VPFE_BLK_SGAIN_MASK) |
621 ((bclamp->start_pixel & VPFE_BLK_ST_PXL_MASK) <<
622 VPFE_BLK_ST_PXL_SHIFT) |
623 ((bclamp->sample_ln & VPFE_BLK_SAMPLE_LINE_MASK) <<
624 VPFE_BLK_SAMPLE_LINE_SHIFT) |
625 ((bclamp->sample_pixel & VPFE_BLK_SAMPLE_LN_MASK) <<
626 VPFE_BLK_SAMPLE_LN_SHIFT) | VPFE_BLK_CLAMP_ENABLE);
627 vpfe_reg_write(ccdc, val, VPFE_CLAMP);
628 /* If Black clamping is enable then make dcsub 0 */
629 vpfe_reg_write(ccdc, VPFE_DCSUB_DEFAULT_VAL, VPFE_DCSUB);
633 vpfe_ccdc_config_black_compense(struct vpfe_ccdc *ccdc,
634 struct vpfe_ccdc_black_compensation *bcomp)
638 val = ((bcomp->b & VPFE_BLK_COMP_MASK) |
639 ((bcomp->gb & VPFE_BLK_COMP_MASK) <<
640 VPFE_BLK_COMP_GB_COMP_SHIFT) |
641 ((bcomp->gr & VPFE_BLK_COMP_MASK) <<
642 VPFE_BLK_COMP_GR_COMP_SHIFT) |
643 ((bcomp->r & VPFE_BLK_COMP_MASK) <<
644 VPFE_BLK_COMP_R_COMP_SHIFT));
645 vpfe_reg_write(ccdc, val, VPFE_BLKCMP);
649 * vpfe_ccdc_config_raw()
650 * This function will configure CCDC for Raw capture mode
652 static void vpfe_ccdc_config_raw(struct vpfe_ccdc *ccdc)
654 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
655 struct vpfe_ccdc_config_params_raw *config_params =
656 &ccdc->ccdc_cfg.bayer.config_params;
657 struct ccdc_params_raw *params = &ccdc->ccdc_cfg.bayer;
658 unsigned int syn_mode;
661 vpfe_dbg(3, vpfe, "vpfe_ccdc_config_raw:\n");
664 vpfe_ccdc_restore_defaults(ccdc);
666 /* Disable latching function registers on VSYNC */
667 vpfe_reg_write(ccdc, VPFE_LATCH_ON_VSYNC_DISABLE, VPFE_CCDCFG);
670 * Configure the vertical sync polarity(SYN_MODE.VDPOL),
671 * horizontal sync polarity (SYN_MODE.HDPOL), frame id polarity
672 * (SYN_MODE.FLDPOL), frame format(progressive or interlace),
673 * data size(SYNMODE.DATSIZ), &pixel format (Input mode), output
674 * SDRAM, enable internal timing generator
676 syn_mode = (((params->vd_pol & VPFE_VD_POL_MASK) << VPFE_VD_POL_SHIFT) |
677 ((params->hd_pol & VPFE_HD_POL_MASK) << VPFE_HD_POL_SHIFT) |
678 ((params->fid_pol & VPFE_FID_POL_MASK) <<
679 VPFE_FID_POL_SHIFT) | ((params->frm_fmt &
680 VPFE_FRM_FMT_MASK) << VPFE_FRM_FMT_SHIFT) |
681 ((config_params->data_sz & VPFE_DATA_SZ_MASK) <<
682 VPFE_DATA_SZ_SHIFT) | ((params->pix_fmt &
683 VPFE_PIX_FMT_MASK) << VPFE_PIX_FMT_SHIFT) |
684 VPFE_WEN_ENABLE | VPFE_VDHDEN_ENABLE);
686 /* Enable and configure aLaw register if needed */
687 if (config_params->alaw.enable) {
688 val = ((config_params->alaw.gamma_wd &
689 VPFE_ALAW_GAMMA_WD_MASK) | VPFE_ALAW_ENABLE);
690 vpfe_reg_write(ccdc, val, VPFE_ALAW);
691 vpfe_dbg(3, vpfe, "\nWriting 0x%x to ALAW...\n", val);
694 /* Configure video window */
695 vpfe_ccdc_setwin(ccdc, ¶ms->win, params->frm_fmt,
696 params->bytesperpixel);
698 /* Configure Black Clamp */
699 vpfe_ccdc_config_black_clamp(ccdc, &config_params->blk_clamp);
701 /* Configure Black level compensation */
702 vpfe_ccdc_config_black_compense(ccdc, &config_params->blk_comp);
704 /* If data size is 8 bit then pack the data */
705 if ((config_params->data_sz == VPFE_CCDC_DATA_8BITS) ||
706 config_params->alaw.enable)
707 syn_mode |= VPFE_DATA_PACK_ENABLE;
710 * Configure Horizontal offset register. If pack 8 is enabled then
711 * 1 pixel will take 1 byte
713 vpfe_reg_write(ccdc, params->bytesperline, VPFE_HSIZE_OFF);
715 vpfe_dbg(3, vpfe, "Writing %d (%x) to HSIZE_OFF\n",
716 params->bytesperline, params->bytesperline);
718 /* Set value for SDOFST */
719 if (params->frm_fmt == CCDC_FRMFMT_INTERLACED) {
720 if (params->image_invert_enable) {
721 /* For interlace inverse mode */
722 vpfe_reg_write(ccdc, VPFE_INTERLACED_IMAGE_INVERT,
725 /* For interlace non inverse mode */
726 vpfe_reg_write(ccdc, VPFE_INTERLACED_NO_IMAGE_INVERT,
729 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
730 vpfe_reg_write(ccdc, VPFE_PROGRESSIVE_NO_IMAGE_INVERT,
734 vpfe_reg_write(ccdc, syn_mode, VPFE_SYNMODE);
740 vpfe_ccdc_set_buftype(struct vpfe_ccdc *ccdc,
741 enum ccdc_buftype buf_type)
743 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
744 ccdc->ccdc_cfg.bayer.buf_type = buf_type;
746 ccdc->ccdc_cfg.ycbcr.buf_type = buf_type;
751 static inline enum ccdc_buftype vpfe_ccdc_get_buftype(struct vpfe_ccdc *ccdc)
753 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
754 return ccdc->ccdc_cfg.bayer.buf_type;
756 return ccdc->ccdc_cfg.ycbcr.buf_type;
759 static int vpfe_ccdc_set_pixel_format(struct vpfe_ccdc *ccdc, u32 pixfmt)
761 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
763 vpfe_dbg(1, vpfe, "vpfe_ccdc_set_pixel_format: if_type: %d, pixfmt:%s\n",
764 ccdc->ccdc_cfg.if_type, print_fourcc(pixfmt));
766 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER) {
767 ccdc->ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
769 * Need to clear it in case it was left on
770 * after the last capture.
772 ccdc->ccdc_cfg.bayer.config_params.alaw.enable = 0;
775 case V4L2_PIX_FMT_SBGGR8:
776 ccdc->ccdc_cfg.bayer.config_params.alaw.enable = 1;
779 case V4L2_PIX_FMT_YUYV:
780 case V4L2_PIX_FMT_UYVY:
781 case V4L2_PIX_FMT_YUV420:
782 case V4L2_PIX_FMT_NV12:
783 case V4L2_PIX_FMT_RGB565X:
786 case V4L2_PIX_FMT_SBGGR16:
792 case V4L2_PIX_FMT_YUYV:
793 ccdc->ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
796 case V4L2_PIX_FMT_UYVY:
797 ccdc->ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
808 static u32 vpfe_ccdc_get_pixel_format(struct vpfe_ccdc *ccdc)
812 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER) {
813 pixfmt = V4L2_PIX_FMT_YUYV;
815 if (ccdc->ccdc_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
816 pixfmt = V4L2_PIX_FMT_YUYV;
818 pixfmt = V4L2_PIX_FMT_UYVY;
825 vpfe_ccdc_set_image_window(struct vpfe_ccdc *ccdc,
826 struct v4l2_rect *win, unsigned int bpp)
828 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER) {
829 ccdc->ccdc_cfg.bayer.win = *win;
830 ccdc->ccdc_cfg.bayer.bytesperpixel = bpp;
831 ccdc->ccdc_cfg.bayer.bytesperline = ALIGN(win->width * bpp, 32);
833 ccdc->ccdc_cfg.ycbcr.win = *win;
834 ccdc->ccdc_cfg.ycbcr.bytesperpixel = bpp;
835 ccdc->ccdc_cfg.ycbcr.bytesperline = ALIGN(win->width * bpp, 32);
842 vpfe_ccdc_get_image_window(struct vpfe_ccdc *ccdc,
843 struct v4l2_rect *win)
845 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
846 *win = ccdc->ccdc_cfg.bayer.win;
848 *win = ccdc->ccdc_cfg.ycbcr.win;
851 static inline unsigned int vpfe_ccdc_get_line_length(struct vpfe_ccdc *ccdc)
853 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
854 return ccdc->ccdc_cfg.bayer.bytesperline;
856 return ccdc->ccdc_cfg.ycbcr.bytesperline;
860 vpfe_ccdc_set_frame_format(struct vpfe_ccdc *ccdc,
861 enum ccdc_frmfmt frm_fmt)
863 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
864 ccdc->ccdc_cfg.bayer.frm_fmt = frm_fmt;
866 ccdc->ccdc_cfg.ycbcr.frm_fmt = frm_fmt;
871 static inline enum ccdc_frmfmt
872 vpfe_ccdc_get_frame_format(struct vpfe_ccdc *ccdc)
874 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
875 return ccdc->ccdc_cfg.bayer.frm_fmt;
877 return ccdc->ccdc_cfg.ycbcr.frm_fmt;
880 static inline int vpfe_ccdc_getfid(struct vpfe_ccdc *ccdc)
882 return (vpfe_reg_read(ccdc, VPFE_SYNMODE) >> 15) & 1;
885 static inline void vpfe_set_sdr_addr(struct vpfe_ccdc *ccdc, unsigned long addr)
887 vpfe_reg_write(ccdc, addr & 0xffffffe0, VPFE_SDR_ADDR);
890 static int vpfe_ccdc_set_hw_if_params(struct vpfe_ccdc *ccdc,
891 struct vpfe_hw_if_param *params)
893 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
895 ccdc->ccdc_cfg.if_type = params->if_type;
897 switch (params->if_type) {
899 case VPFE_YCBCR_SYNC_16:
900 case VPFE_YCBCR_SYNC_8:
901 case VPFE_BT656_10BIT:
902 ccdc->ccdc_cfg.ycbcr.vd_pol = params->vdpol;
903 ccdc->ccdc_cfg.ycbcr.hd_pol = params->hdpol;
907 ccdc->ccdc_cfg.bayer.vd_pol = params->vdpol;
908 ccdc->ccdc_cfg.bayer.hd_pol = params->hdpol;
909 if (params->bus_width == 10)
910 ccdc->ccdc_cfg.bayer.config_params.data_sz =
911 VPFE_CCDC_DATA_10BITS;
913 ccdc->ccdc_cfg.bayer.config_params.data_sz =
914 VPFE_CCDC_DATA_8BITS;
915 vpfe_dbg(1, vpfe, "params.bus_width: %d\n",
917 vpfe_dbg(1, vpfe, "config_params.data_sz: %d\n",
918 ccdc->ccdc_cfg.bayer.config_params.data_sz);
928 static void vpfe_clear_intr(struct vpfe_ccdc *ccdc, int vdint)
930 unsigned int vpfe_int_status;
932 vpfe_int_status = vpfe_reg_read(ccdc, VPFE_IRQ_STS);
937 vpfe_int_status &= ~VPFE_VDINT0;
938 vpfe_int_status |= VPFE_VDINT0;
943 vpfe_int_status &= ~VPFE_VDINT1;
944 vpfe_int_status |= VPFE_VDINT1;
949 vpfe_int_status &= ~VPFE_VDINT2;
950 vpfe_int_status |= VPFE_VDINT2;
953 /* Clear all interrupts */
955 vpfe_int_status &= ~(VPFE_VDINT0 |
958 vpfe_int_status |= (VPFE_VDINT0 |
963 /* Clear specific VDINT from the status register */
964 vpfe_reg_write(ccdc, vpfe_int_status, VPFE_IRQ_STS);
966 vpfe_int_status = vpfe_reg_read(ccdc, VPFE_IRQ_STS);
968 /* Acknowledge that we are done with all interrupts */
969 vpfe_reg_write(ccdc, 1, VPFE_IRQ_EOI);
972 static void vpfe_ccdc_config_defaults(struct vpfe_ccdc *ccdc)
974 ccdc->ccdc_cfg.if_type = VPFE_RAW_BAYER;
976 ccdc->ccdc_cfg.ycbcr.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
977 ccdc->ccdc_cfg.ycbcr.frm_fmt = CCDC_FRMFMT_INTERLACED;
978 ccdc->ccdc_cfg.ycbcr.fid_pol = VPFE_PINPOL_POSITIVE;
979 ccdc->ccdc_cfg.ycbcr.vd_pol = VPFE_PINPOL_POSITIVE;
980 ccdc->ccdc_cfg.ycbcr.hd_pol = VPFE_PINPOL_POSITIVE;
981 ccdc->ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
982 ccdc->ccdc_cfg.ycbcr.buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED;
984 ccdc->ccdc_cfg.ycbcr.win.left = 0;
985 ccdc->ccdc_cfg.ycbcr.win.top = 0;
986 ccdc->ccdc_cfg.ycbcr.win.width = 720;
987 ccdc->ccdc_cfg.ycbcr.win.height = 576;
988 ccdc->ccdc_cfg.ycbcr.bt656_enable = 1;
990 ccdc->ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
991 ccdc->ccdc_cfg.bayer.frm_fmt = CCDC_FRMFMT_PROGRESSIVE;
992 ccdc->ccdc_cfg.bayer.fid_pol = VPFE_PINPOL_POSITIVE;
993 ccdc->ccdc_cfg.bayer.vd_pol = VPFE_PINPOL_POSITIVE;
994 ccdc->ccdc_cfg.bayer.hd_pol = VPFE_PINPOL_POSITIVE;
996 ccdc->ccdc_cfg.bayer.win.left = 0;
997 ccdc->ccdc_cfg.bayer.win.top = 0;
998 ccdc->ccdc_cfg.bayer.win.width = 800;
999 ccdc->ccdc_cfg.bayer.win.height = 600;
1000 ccdc->ccdc_cfg.bayer.config_params.data_sz = VPFE_CCDC_DATA_8BITS;
1001 ccdc->ccdc_cfg.bayer.config_params.alaw.gamma_wd =
1002 VPFE_CCDC_GAMMA_BITS_09_0;
1006 * vpfe_get_ccdc_image_format - Get image parameters based on CCDC settings
1008 static int vpfe_get_ccdc_image_format(struct vpfe_device *vpfe,
1009 struct v4l2_format *f)
1011 struct v4l2_rect image_win;
1012 enum ccdc_buftype buf_type;
1013 enum ccdc_frmfmt frm_fmt;
1015 memset(f, 0, sizeof(*f));
1016 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1017 vpfe_ccdc_get_image_window(&vpfe->ccdc, &image_win);
1018 f->fmt.pix.width = image_win.width;
1019 f->fmt.pix.height = image_win.height;
1020 f->fmt.pix.bytesperline = vpfe_ccdc_get_line_length(&vpfe->ccdc);
1021 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
1023 buf_type = vpfe_ccdc_get_buftype(&vpfe->ccdc);
1024 f->fmt.pix.pixelformat = vpfe_ccdc_get_pixel_format(&vpfe->ccdc);
1025 frm_fmt = vpfe_ccdc_get_frame_format(&vpfe->ccdc);
1027 if (frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
1028 f->fmt.pix.field = V4L2_FIELD_NONE;
1029 } else if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
1030 if (buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED) {
1031 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1032 } else if (buf_type == CCDC_BUFTYPE_FLD_SEPARATED) {
1033 f->fmt.pix.field = V4L2_FIELD_SEQ_TB;
1035 vpfe_err(vpfe, "Invalid buf_type\n");
1039 vpfe_err(vpfe, "Invalid frm_fmt\n");
1045 static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe)
1047 enum ccdc_frmfmt frm_fmt = CCDC_FRMFMT_INTERLACED;
1050 vpfe_dbg(2, vpfe, "vpfe_config_ccdc_image_format\n");
1052 vpfe_dbg(1, vpfe, "pixelformat: %s\n",
1053 print_fourcc(vpfe->fmt.fmt.pix.pixelformat));
1055 if (vpfe_ccdc_set_pixel_format(&vpfe->ccdc,
1056 vpfe->fmt.fmt.pix.pixelformat) < 0) {
1057 vpfe_err(vpfe, "couldn't set pix format in ccdc\n");
1061 /* configure the image window */
1062 vpfe_ccdc_set_image_window(&vpfe->ccdc, &vpfe->crop, vpfe->bpp);
1064 switch (vpfe->fmt.fmt.pix.field) {
1065 case V4L2_FIELD_INTERLACED:
1066 /* do nothing, since it is default */
1067 ret = vpfe_ccdc_set_buftype(
1069 CCDC_BUFTYPE_FLD_INTERLEAVED);
1072 case V4L2_FIELD_NONE:
1073 frm_fmt = CCDC_FRMFMT_PROGRESSIVE;
1074 /* buffer type only applicable for interlaced scan */
1077 case V4L2_FIELD_SEQ_TB:
1078 ret = vpfe_ccdc_set_buftype(
1080 CCDC_BUFTYPE_FLD_SEPARATED);
1090 return vpfe_ccdc_set_frame_format(&vpfe->ccdc, frm_fmt);
1094 * vpfe_config_image_format()
1095 * For a given standard, this functions sets up the default
1096 * pix format & crop values in the vpfe device and ccdc. It first
1097 * starts with defaults based values from the standard table.
1098 * It then checks if sub device support g_mbus_fmt and then override the
1099 * values based on that.Sets crop values to match with scan resolution
1100 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
1103 static int vpfe_config_image_format(struct vpfe_device *vpfe,
1106 struct v4l2_pix_format *pix = &vpfe->fmt.fmt.pix;
1109 for (i = 0; i < ARRAY_SIZE(vpfe_standards); i++) {
1110 if (vpfe_standards[i].std_id & std_id) {
1111 vpfe->std_info.active_pixels =
1112 vpfe_standards[i].width;
1113 vpfe->std_info.active_lines =
1114 vpfe_standards[i].height;
1115 vpfe->std_info.frame_format =
1116 vpfe_standards[i].frame_format;
1117 vpfe->std_index = i;
1123 if (i == ARRAY_SIZE(vpfe_standards)) {
1124 vpfe_err(vpfe, "standard not supported\n");
1128 vpfe->crop.top = vpfe->crop.left = 0;
1129 vpfe->crop.width = vpfe->std_info.active_pixels;
1130 vpfe->crop.height = vpfe->std_info.active_lines;
1131 pix->width = vpfe->crop.width;
1132 pix->height = vpfe->crop.height;
1133 pix->pixelformat = V4L2_PIX_FMT_YUYV;
1135 /* first field and frame format based on standard frame format */
1136 if (vpfe->std_info.frame_format)
1137 pix->field = V4L2_FIELD_INTERLACED;
1139 pix->field = V4L2_FIELD_NONE;
1141 ret = __vpfe_get_format(vpfe, &vpfe->fmt, &vpfe->bpp);
1145 /* Update the crop window based on found values */
1146 vpfe->crop.width = pix->width;
1147 vpfe->crop.height = pix->height;
1149 return vpfe_config_ccdc_image_format(vpfe);
1152 static int vpfe_initialize_device(struct vpfe_device *vpfe)
1154 struct vpfe_subdev_info *sdinfo;
1157 sdinfo = &vpfe->cfg->sub_devs[0];
1158 sdinfo->sd = vpfe->sd[0];
1159 vpfe->current_input = 0;
1160 vpfe->std_index = 0;
1161 /* Configure the default format information */
1162 ret = vpfe_config_image_format(vpfe,
1163 vpfe_standards[vpfe->std_index].std_id);
1167 pm_runtime_get_sync(vpfe->pdev);
1169 vpfe_config_enable(&vpfe->ccdc, 1);
1171 vpfe_ccdc_restore_defaults(&vpfe->ccdc);
1173 /* Clear all VPFE interrupts */
1174 vpfe_clear_intr(&vpfe->ccdc, -1);
1180 * vpfe_release : This function is based on the vb2_fop_release
1182 * It has been augmented to handle module power management,
1183 * by disabling/enabling h/w module fcntl clock when necessary.
1185 static int vpfe_release(struct file *file)
1187 struct vpfe_device *vpfe = video_drvdata(file);
1191 mutex_lock(&vpfe->lock);
1193 /* Save the singular status before we call the clean-up helper */
1194 fh_singular = v4l2_fh_is_singular_file(file);
1196 /* the release helper will cleanup any on-going streaming */
1197 ret = _vb2_fop_release(file, NULL);
1200 * If this was the last open file.
1201 * Then de-initialize hw module.
1204 vpfe_ccdc_close(&vpfe->ccdc, vpfe->pdev);
1206 mutex_unlock(&vpfe->lock);
1212 * vpfe_open : This function is based on the v4l2_fh_open helper function.
1213 * It has been augmented to handle module power management,
1214 * by disabling/enabling h/w module fcntl clock when necessary.
1216 static int vpfe_open(struct file *file)
1218 struct vpfe_device *vpfe = video_drvdata(file);
1221 mutex_lock(&vpfe->lock);
1223 ret = v4l2_fh_open(file);
1225 vpfe_err(vpfe, "v4l2_fh_open failed\n");
1229 if (!v4l2_fh_is_singular_file(file))
1232 if (vpfe_initialize_device(vpfe)) {
1233 v4l2_fh_release(file);
1238 mutex_unlock(&vpfe->lock);
1243 * vpfe_schedule_next_buffer: set next buffer address for capture
1244 * @vpfe : ptr to vpfe device
1246 * This function will get next buffer from the dma queue and
1247 * set the buffer address in the vpfe register for capture.
1248 * the buffer is marked active
1250 * Assumes caller is holding vpfe->dma_queue_lock already
1252 static inline void vpfe_schedule_next_buffer(struct vpfe_device *vpfe)
1254 vpfe->next_frm = list_entry(vpfe->dma_queue.next,
1255 struct vpfe_cap_buffer, list);
1256 list_del(&vpfe->next_frm->list);
1258 vpfe_set_sdr_addr(&vpfe->ccdc,
1259 vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb, 0));
1262 static inline void vpfe_schedule_bottom_field(struct vpfe_device *vpfe)
1266 addr = vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb, 0) +
1269 vpfe_set_sdr_addr(&vpfe->ccdc, addr);
1273 * vpfe_process_buffer_complete: process a completed buffer
1274 * @vpfe : ptr to vpfe device
1276 * This function time stamp the buffer and mark it as DONE. It also
1277 * wake up any process waiting on the QUEUE and set the next buffer
1280 static inline void vpfe_process_buffer_complete(struct vpfe_device *vpfe)
1282 v4l2_get_timestamp(&vpfe->cur_frm->vb.v4l2_buf.timestamp);
1283 vpfe->cur_frm->vb.v4l2_buf.field = vpfe->fmt.fmt.pix.field;
1284 vpfe->cur_frm->vb.v4l2_buf.sequence = vpfe->sequence++;
1285 vb2_buffer_done(&vpfe->cur_frm->vb, VB2_BUF_STATE_DONE);
1286 vpfe->cur_frm = vpfe->next_frm;
1290 * vpfe_isr : ISR handler for vpfe capture (VINT0)
1292 * @dev_id: dev_id ptr
1294 * It changes status of the captured buffer, takes next buffer from the queue
1295 * and sets its address in VPFE registers
1297 static irqreturn_t vpfe_isr(int irq, void *dev)
1299 struct vpfe_device *vpfe = (struct vpfe_device *)dev;
1300 enum v4l2_field field;
1304 intr_status = vpfe_reg_read(&vpfe->ccdc, VPFE_IRQ_STS);
1306 if (intr_status & VPFE_VDINT0) {
1307 field = vpfe->fmt.fmt.pix.field;
1309 if (field == V4L2_FIELD_NONE) {
1310 /* handle progressive frame capture */
1311 if (vpfe->cur_frm != vpfe->next_frm)
1312 vpfe_process_buffer_complete(vpfe);
1316 /* interlaced or TB capture check which field
1317 we are in hardware */
1318 fid = vpfe_ccdc_getfid(&vpfe->ccdc);
1320 /* switch the software maintained field id */
1322 if (fid == vpfe->field) {
1323 /* we are in-sync here,continue */
1326 * One frame is just being captured. If the
1327 * next frame is available, release the
1328 * current frame and move on
1330 if (vpfe->cur_frm != vpfe->next_frm)
1331 vpfe_process_buffer_complete(vpfe);
1333 * based on whether the two fields are stored
1334 * interleave or separately in memory,
1335 * reconfigure the CCDC memory address
1337 if (field == V4L2_FIELD_SEQ_TB)
1338 vpfe_schedule_bottom_field(vpfe);
1343 * if one field is just being captured configure
1344 * the next frame get the next frame from the empty
1345 * queue if no frame is available hold on to the
1348 spin_lock(&vpfe->dma_queue_lock);
1349 if (!list_empty(&vpfe->dma_queue) &&
1350 vpfe->cur_frm == vpfe->next_frm)
1351 vpfe_schedule_next_buffer(vpfe);
1352 spin_unlock(&vpfe->dma_queue_lock);
1353 } else if (fid == 0) {
1355 * out of sync. Recover from any hardware out-of-sync.
1356 * May loose one frame
1363 if (intr_status & VPFE_VDINT1) {
1364 spin_lock(&vpfe->dma_queue_lock);
1365 if (vpfe->fmt.fmt.pix.field == V4L2_FIELD_NONE &&
1366 !list_empty(&vpfe->dma_queue) &&
1367 vpfe->cur_frm == vpfe->next_frm)
1368 vpfe_schedule_next_buffer(vpfe);
1369 spin_unlock(&vpfe->dma_queue_lock);
1372 vpfe_clear_intr(&vpfe->ccdc, intr_status);
1377 static inline void vpfe_detach_irq(struct vpfe_device *vpfe)
1379 unsigned int intr = VPFE_VDINT0;
1380 enum ccdc_frmfmt frame_format;
1382 frame_format = vpfe_ccdc_get_frame_format(&vpfe->ccdc);
1383 if (frame_format == CCDC_FRMFMT_PROGRESSIVE)
1384 intr |= VPFE_VDINT1;
1386 vpfe_reg_write(&vpfe->ccdc, intr, VPFE_IRQ_EN_CLR);
1389 static inline void vpfe_attach_irq(struct vpfe_device *vpfe)
1391 unsigned int intr = VPFE_VDINT0;
1392 enum ccdc_frmfmt frame_format;
1394 frame_format = vpfe_ccdc_get_frame_format(&vpfe->ccdc);
1395 if (frame_format == CCDC_FRMFMT_PROGRESSIVE)
1396 intr |= VPFE_VDINT1;
1398 vpfe_reg_write(&vpfe->ccdc, intr, VPFE_IRQ_EN_SET);
1401 static int vpfe_querycap(struct file *file, void *priv,
1402 struct v4l2_capability *cap)
1404 struct vpfe_device *vpfe = video_drvdata(file);
1406 vpfe_dbg(2, vpfe, "vpfe_querycap\n");
1408 strlcpy(cap->driver, VPFE_MODULE_NAME, sizeof(cap->driver));
1409 strlcpy(cap->card, "TI AM437x VPFE", sizeof(cap->card));
1410 snprintf(cap->bus_info, sizeof(cap->bus_info),
1411 "platform:%s", vpfe->v4l2_dev.name);
1412 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
1414 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1419 /* get the format set at output pad of the adjacent subdev */
1420 static int __vpfe_get_format(struct vpfe_device *vpfe,
1421 struct v4l2_format *format, unsigned int *bpp)
1423 struct v4l2_mbus_framefmt mbus_fmt;
1424 struct vpfe_subdev_info *sdinfo;
1425 struct v4l2_subdev_format fmt;
1428 sdinfo = vpfe->current_subdev;
1432 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1435 ret = v4l2_subdev_call(sdinfo->sd, pad, get_fmt, NULL, &fmt);
1436 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1440 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format);
1441 mbus_to_pix(vpfe, &fmt.format, &format->fmt.pix, bpp);
1443 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev,
1447 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1449 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt);
1450 mbus_to_pix(vpfe, &mbus_fmt, &format->fmt.pix, bpp);
1453 format->type = vpfe->fmt.type;
1456 "%s size %dx%d (%s) bytesperline = %d, size = %d, bpp = %d\n",
1457 __func__, format->fmt.pix.width, format->fmt.pix.height,
1458 print_fourcc(format->fmt.pix.pixelformat),
1459 format->fmt.pix.bytesperline, format->fmt.pix.sizeimage, *bpp);
1464 /* set the format at output pad of the adjacent subdev */
1465 static int __vpfe_set_format(struct vpfe_device *vpfe,
1466 struct v4l2_format *format, unsigned int *bpp)
1468 struct v4l2_mbus_framefmt mbus_fmt;
1469 struct vpfe_subdev_info *sdinfo;
1470 struct v4l2_subdev_format fmt;
1473 vpfe_dbg(2, vpfe, "__vpfe_set_format\n");
1475 sdinfo = vpfe->current_subdev;
1479 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1482 pix_to_mbus(vpfe, &format->fmt.pix, &fmt.format);
1484 ret = v4l2_subdev_call(sdinfo->sd, pad, set_fmt, NULL, &fmt);
1485 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1489 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format);
1490 mbus_to_pix(vpfe, &fmt.format, &format->fmt.pix, bpp);
1492 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev,
1496 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1499 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt);
1500 mbus_to_pix(vpfe, &mbus_fmt, &format->fmt.pix, bpp);
1503 format->type = vpfe->fmt.type;
1506 "%s size %dx%d (%s) bytesperline = %d, size = %d, bpp = %d\n",
1507 __func__, format->fmt.pix.width, format->fmt.pix.height,
1508 print_fourcc(format->fmt.pix.pixelformat),
1509 format->fmt.pix.bytesperline, format->fmt.pix.sizeimage, *bpp);
1514 static int vpfe_g_fmt(struct file *file, void *priv,
1515 struct v4l2_format *fmt)
1517 struct vpfe_device *vpfe = video_drvdata(file);
1519 vpfe_dbg(2, vpfe, "vpfe_g_fmt\n");
1526 static int vpfe_enum_fmt(struct file *file, void *priv,
1527 struct v4l2_fmtdesc *f)
1529 struct vpfe_device *vpfe = video_drvdata(file);
1530 struct vpfe_subdev_info *sdinfo;
1531 struct vpfe_fmt *fmt = NULL;
1534 vpfe_dbg(2, vpfe, "vpfe_enum_format index:%d\n",
1537 sdinfo = vpfe->current_subdev;
1541 if (f->index > ARRAY_SIZE(formats))
1544 for (k = 0; k < ARRAY_SIZE(formats); k++) {
1545 if (formats[k].index == f->index) {
1553 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
1554 f->pixelformat = fmt->fourcc;
1555 f->type = vpfe->fmt.type;
1557 vpfe_dbg(1, vpfe, "vpfe_enum_format: mbus index: %d code: %x pixelformat: %s [%s]\n",
1558 f->index, fmt->code, print_fourcc(fmt->fourcc), fmt->name);
1563 static int vpfe_try_fmt(struct file *file, void *priv,
1564 struct v4l2_format *fmt)
1566 struct vpfe_device *vpfe = video_drvdata(file);
1569 vpfe_dbg(2, vpfe, "vpfe_try_fmt\n");
1571 return __vpfe_get_format(vpfe, fmt, &bpp);
1574 static int vpfe_s_fmt(struct file *file, void *priv,
1575 struct v4l2_format *fmt)
1577 struct vpfe_device *vpfe = video_drvdata(file);
1578 struct v4l2_format format;
1582 vpfe_dbg(2, vpfe, "vpfe_s_fmt\n");
1584 /* If streaming is started, return error */
1585 if (vb2_is_busy(&vpfe->buffer_queue)) {
1586 vpfe_err(vpfe, "%s device busy\n", __func__);
1590 ret = vpfe_try_fmt(file, priv, &format);
1595 if (!cmp_v4l2_format(fmt, &format)) {
1596 /* Sensor format is different from the requested format
1597 * so we need to change it
1599 ret = __vpfe_set_format(vpfe, fmt, &bpp);
1602 } else /* Just make sure all of the fields are consistent */
1605 /* First detach any IRQ if currently attached */
1606 vpfe_detach_irq(vpfe);
1610 /* Update the crop window based on found values */
1611 vpfe->crop.width = fmt->fmt.pix.width;
1612 vpfe->crop.height = fmt->fmt.pix.height;
1614 /* set image capture parameters in the ccdc */
1615 return vpfe_config_ccdc_image_format(vpfe);
1618 static int vpfe_enum_size(struct file *file, void *priv,
1619 struct v4l2_frmsizeenum *fsize)
1621 struct vpfe_device *vpfe = video_drvdata(file);
1622 struct v4l2_subdev_frame_size_enum fse;
1623 struct vpfe_subdev_info *sdinfo;
1624 struct v4l2_mbus_framefmt mbus;
1625 struct v4l2_pix_format pix;
1626 struct vpfe_fmt *fmt;
1629 vpfe_dbg(2, vpfe, "vpfe_enum_size\n");
1631 /* check for valid format */
1632 fmt = find_format_by_pix(fsize->pixel_format);
1634 vpfe_dbg(3, vpfe, "Invalid pixel code: %x, default used instead\n",
1635 fsize->pixel_format);
1639 memset(fsize->reserved, 0x0, sizeof(fsize->reserved));
1641 sdinfo = vpfe->current_subdev;
1645 memset(&pix, 0x0, sizeof(pix));
1646 /* Construct pix from parameter and use default for the rest */
1647 pix.pixelformat = fsize->pixel_format;
1650 pix.colorspace = V4L2_COLORSPACE_SRGB;
1651 pix.field = V4L2_FIELD_NONE;
1652 pix_to_mbus(vpfe, &pix, &mbus);
1654 memset(&fse, 0x0, sizeof(fse));
1655 fse.index = fsize->index;
1657 fse.code = mbus.code;
1658 fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1659 ret = v4l2_subdev_call(sdinfo->sd, pad, enum_frame_size, NULL, &fse);
1663 vpfe_dbg(1, vpfe, "vpfe_enum_size: index: %d code: %x W:[%d,%d] H:[%d,%d]\n",
1664 fse.index, fse.code, fse.min_width, fse.max_width,
1665 fse.min_height, fse.max_height);
1667 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1668 fsize->discrete.width = fse.max_width;
1669 fsize->discrete.height = fse.max_height;
1671 vpfe_dbg(1, vpfe, "vpfe_enum_size: index: %d pixformat: %s size: %dx%d\n",
1672 fsize->index, print_fourcc(fsize->pixel_format),
1673 fsize->discrete.width, fsize->discrete.height);
1679 * vpfe_get_subdev_input_index - Get subdev index and subdev input index for a
1680 * given app input index
1683 vpfe_get_subdev_input_index(struct vpfe_device *vpfe,
1685 int *subdev_input_index,
1686 int app_input_index)
1688 struct vpfe_config *cfg = vpfe->cfg;
1689 struct vpfe_subdev_info *sdinfo;
1692 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
1693 sdinfo = &cfg->sub_devs[i];
1694 if (app_input_index < (j + 1)) {
1696 *subdev_input_index = app_input_index - j;
1705 * vpfe_get_app_input - Get app input index for a given subdev input index
1706 * driver stores the input index of the current sub device and translate it
1707 * when application request the current input
1709 static int vpfe_get_app_input_index(struct vpfe_device *vpfe,
1710 int *app_input_index)
1712 struct vpfe_config *cfg = vpfe->cfg;
1713 struct vpfe_subdev_info *sdinfo;
1714 struct i2c_client *client;
1715 struct i2c_client *curr_client;
1718 curr_client = v4l2_get_subdevdata(vpfe->current_subdev->sd);
1719 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
1720 sdinfo = &cfg->sub_devs[i];
1721 client = v4l2_get_subdevdata(sdinfo->sd);
1722 if (client->addr == curr_client->addr &&
1723 client->adapter->nr == client->adapter->nr) {
1724 if (vpfe->current_input >= 1)
1726 *app_input_index = j + vpfe->current_input;
1734 static int vpfe_enum_input(struct file *file, void *priv,
1735 struct v4l2_input *inp)
1737 struct vpfe_device *vpfe = video_drvdata(file);
1738 struct vpfe_subdev_info *sdinfo;
1741 vpfe_dbg(2, vpfe, "vpfe_enum_input\n");
1743 if (vpfe_get_subdev_input_index(vpfe, &subdev, &index,
1746 "input information not found for the subdev\n");
1749 sdinfo = &vpfe->cfg->sub_devs[subdev];
1750 *inp = sdinfo->inputs[index];
1755 static int vpfe_g_input(struct file *file, void *priv, unsigned int *index)
1757 struct vpfe_device *vpfe = video_drvdata(file);
1759 vpfe_dbg(2, vpfe, "vpfe_g_input\n");
1761 return vpfe_get_app_input_index(vpfe, index);
1764 /* Assumes caller is holding vpfe_dev->lock */
1765 static int vpfe_set_input(struct vpfe_device *vpfe, unsigned int index)
1767 int subdev_index = 0, inp_index = 0;
1768 struct vpfe_subdev_info *sdinfo;
1769 struct vpfe_route *route;
1773 vpfe_dbg(2, vpfe, "vpfe_set_input: index: %d\n", index);
1775 /* If streaming is started, return error */
1776 if (vb2_is_busy(&vpfe->buffer_queue)) {
1777 vpfe_err(vpfe, "%s device busy\n", __func__);
1780 ret = vpfe_get_subdev_input_index(vpfe,
1785 vpfe_err(vpfe, "invalid input index: %d\n", index);
1789 sdinfo = &vpfe->cfg->sub_devs[subdev_index];
1790 sdinfo->sd = vpfe->sd[subdev_index];
1791 route = &sdinfo->routes[inp_index];
1792 if (route && sdinfo->can_route) {
1793 input = route->input;
1794 output = route->output;
1796 ret = v4l2_subdev_call(sdinfo->sd, video,
1797 s_routing, input, output, 0);
1799 vpfe_err(vpfe, "s_routing failed\n");
1807 vpfe->current_subdev = sdinfo;
1809 vpfe->v4l2_dev.ctrl_handler = sdinfo->sd->ctrl_handler;
1810 vpfe->current_input = index;
1811 vpfe->std_index = 0;
1813 /* set the bus/interface parameter for the sub device in ccdc */
1814 ret = vpfe_ccdc_set_hw_if_params(&vpfe->ccdc, &sdinfo->vpfe_param);
1818 /* set the default image parameters in the device */
1819 return vpfe_config_image_format(vpfe,
1820 vpfe_standards[vpfe->std_index].std_id);
1826 static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1828 struct vpfe_device *vpfe = video_drvdata(file);
1831 "vpfe_s_input: index: %d\n", index);
1833 return vpfe_set_input(vpfe, index);
1836 static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
1838 struct vpfe_device *vpfe = video_drvdata(file);
1839 struct vpfe_subdev_info *sdinfo;
1841 vpfe_dbg(2, vpfe, "vpfe_querystd\n");
1843 sdinfo = vpfe->current_subdev;
1844 if (!(sdinfo->inputs[0].capabilities & V4L2_IN_CAP_STD))
1847 /* Call querystd function of decoder device */
1848 return v4l2_device_call_until_err(&vpfe->v4l2_dev, sdinfo->grp_id,
1849 video, querystd, std_id);
1852 static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id std_id)
1854 struct vpfe_device *vpfe = video_drvdata(file);
1855 struct vpfe_subdev_info *sdinfo;
1858 vpfe_dbg(2, vpfe, "vpfe_s_std\n");
1860 sdinfo = vpfe->current_subdev;
1861 if (!(sdinfo->inputs[0].capabilities & V4L2_IN_CAP_STD))
1864 /* If streaming is started, return error */
1865 if (vb2_is_busy(&vpfe->buffer_queue)) {
1866 vpfe_err(vpfe, "%s device busy\n", __func__);
1871 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev, sdinfo->grp_id,
1872 video, s_std, std_id);
1874 vpfe_err(vpfe, "Failed to set standard\n");
1877 ret = vpfe_config_image_format(vpfe, std_id);
1882 static int vpfe_g_std(struct file *file, void *priv, v4l2_std_id *std_id)
1884 struct vpfe_device *vpfe = video_drvdata(file);
1885 struct vpfe_subdev_info *sdinfo;
1887 vpfe_dbg(2, vpfe, "vpfe_g_std\n");
1889 sdinfo = vpfe->current_subdev;
1890 if (sdinfo->inputs[0].capabilities != V4L2_IN_CAP_STD)
1893 *std_id = vpfe_standards[vpfe->std_index].std_id;
1899 * vpfe_calculate_offsets : This function calculates buffers offset
1900 * for top and bottom field
1902 static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
1904 struct v4l2_rect image_win;
1906 vpfe_dbg(2, vpfe, "vpfe_calculate_offsets\n");
1908 vpfe_ccdc_get_image_window(&vpfe->ccdc, &image_win);
1909 vpfe->field_off = image_win.height * image_win.width;
1913 * vpfe_queue_setup - Callback function for buffer setup.
1914 * @vq: vb2_queue ptr
1916 * @nbuffers: ptr to number of buffers requested by application
1917 * @nplanes:: contains number of distinct video planes needed to hold a frame
1918 * @sizes[]: contains the size (in bytes) of each plane.
1919 * @alloc_ctxs: ptr to allocation context
1921 * This callback function is called when reqbuf() is called to adjust
1922 * the buffer count and buffer size
1924 static int vpfe_queue_setup(struct vb2_queue *vq,
1925 const struct v4l2_format *fmt,
1926 unsigned int *nbuffers, unsigned int *nplanes,
1927 unsigned int sizes[], void *alloc_ctxs[])
1929 struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
1931 if (fmt && fmt->fmt.pix.sizeimage < vpfe->fmt.fmt.pix.sizeimage)
1934 if (vq->num_buffers + *nbuffers < 3)
1935 *nbuffers = 3 - vq->num_buffers;
1938 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : vpfe->fmt.fmt.pix.sizeimage;
1939 alloc_ctxs[0] = vpfe->alloc_ctx;
1942 "nbuffers=%d, size=%u\n", *nbuffers, sizes[0]);
1944 /* Calculate field offset */
1945 vpfe_calculate_offsets(vpfe);
1951 * vpfe_buffer_prepare : callback function for buffer prepare
1952 * @vb: ptr to vb2_buffer
1954 * This is the callback function for buffer prepare when vb2_qbuf()
1955 * function is called. The buffer is prepared and user space virtual address
1956 * or user address is converted into physical address
1958 static int vpfe_buffer_prepare(struct vb2_buffer *vb)
1960 struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
1962 vb2_set_plane_payload(vb, 0, vpfe->fmt.fmt.pix.sizeimage);
1964 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
1967 vb->v4l2_buf.field = vpfe->fmt.fmt.pix.field;
1973 * vpfe_buffer_queue : Callback function to add buffer to DMA queue
1974 * @vb: ptr to vb2_buffer
1976 static void vpfe_buffer_queue(struct vb2_buffer *vb)
1978 struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
1979 struct vpfe_cap_buffer *buf = to_vpfe_buffer(vb);
1980 unsigned long flags = 0;
1982 /* add the buffer to the DMA queue */
1983 spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
1984 list_add_tail(&buf->list, &vpfe->dma_queue);
1985 spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
1989 * vpfe_start_streaming : Starts the DMA engine for streaming
1990 * @vb: ptr to vb2_buffer
1991 * @count: number of buffers
1993 static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
1995 struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
1996 struct vpfe_cap_buffer *buf, *tmp;
1997 struct vpfe_subdev_info *sdinfo;
1998 unsigned long flags;
2002 spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
2007 sdinfo = vpfe->current_subdev;
2009 vpfe_attach_irq(vpfe);
2011 if (vpfe->ccdc.ccdc_cfg.if_type == VPFE_RAW_BAYER)
2012 vpfe_ccdc_config_raw(&vpfe->ccdc);
2014 vpfe_ccdc_config_ycbcr(&vpfe->ccdc);
2016 /* Get the next frame from the buffer queue */
2017 vpfe->next_frm = list_entry(vpfe->dma_queue.next,
2018 struct vpfe_cap_buffer, list);
2019 vpfe->cur_frm = vpfe->next_frm;
2020 /* Remove buffer from the buffer queue */
2021 list_del(&vpfe->cur_frm->list);
2022 spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
2024 addr = vb2_dma_contig_plane_dma_addr(&vpfe->cur_frm->vb, 0);
2026 vpfe_set_sdr_addr(&vpfe->ccdc, (unsigned long)(addr));
2028 vpfe_pcr_enable(&vpfe->ccdc, 1);
2030 ret = v4l2_subdev_call(sdinfo->sd, video, s_stream, 1);
2032 vpfe_err(vpfe, "Error in attaching interrupt handle\n");
2039 list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
2040 list_del(&buf->list);
2041 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
2048 * vpfe_stop_streaming : Stop the DMA engine
2049 * @vq: ptr to vb2_queue
2051 * This callback stops the DMA engine and any remaining buffers
2052 * in the DMA queue are released.
2054 static void vpfe_stop_streaming(struct vb2_queue *vq)
2056 struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
2057 struct vpfe_subdev_info *sdinfo;
2058 unsigned long flags;
2061 vpfe_pcr_enable(&vpfe->ccdc, 0);
2063 vpfe_detach_irq(vpfe);
2065 sdinfo = vpfe->current_subdev;
2066 ret = v4l2_subdev_call(sdinfo->sd, video, s_stream, 0);
2067 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
2068 vpfe_dbg(1, vpfe, "stream off failed in subdev\n");
2070 /* release all active buffers */
2071 spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
2072 if (vpfe->cur_frm == vpfe->next_frm) {
2073 vb2_buffer_done(&vpfe->cur_frm->vb, VB2_BUF_STATE_ERROR);
2075 if (vpfe->cur_frm != NULL)
2076 vb2_buffer_done(&vpfe->cur_frm->vb,
2077 VB2_BUF_STATE_ERROR);
2078 if (vpfe->next_frm != NULL)
2079 vb2_buffer_done(&vpfe->next_frm->vb,
2080 VB2_BUF_STATE_ERROR);
2083 while (!list_empty(&vpfe->dma_queue)) {
2084 vpfe->next_frm = list_entry(vpfe->dma_queue.next,
2085 struct vpfe_cap_buffer, list);
2086 list_del(&vpfe->next_frm->list);
2087 vb2_buffer_done(&vpfe->next_frm->vb, VB2_BUF_STATE_ERROR);
2089 spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
2092 static int vpfe_cropcap(struct file *file, void *priv,
2093 struct v4l2_cropcap *crop)
2095 struct vpfe_device *vpfe = video_drvdata(file);
2097 vpfe_dbg(2, vpfe, "vpfe_cropcap\n");
2099 if (vpfe->std_index >= ARRAY_SIZE(vpfe_standards))
2102 memset(crop, 0, sizeof(struct v4l2_cropcap));
2104 crop->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2105 crop->defrect.width = vpfe_standards[vpfe->std_index].width;
2106 crop->bounds.width = crop->defrect.width;
2107 crop->defrect.height = vpfe_standards[vpfe->std_index].height;
2108 crop->bounds.height = crop->defrect.height;
2109 crop->pixelaspect = vpfe_standards[vpfe->std_index].pixelaspect;
2115 vpfe_g_selection(struct file *file, void *fh, struct v4l2_selection *s)
2117 struct vpfe_device *vpfe = video_drvdata(file);
2119 switch (s->target) {
2120 case V4L2_SEL_TGT_CROP_BOUNDS:
2121 case V4L2_SEL_TGT_CROP_DEFAULT:
2122 s->r.left = s->r.top = 0;
2123 s->r.width = vpfe->crop.width;
2124 s->r.height = vpfe->crop.height;
2127 case V4L2_SEL_TGT_CROP:
2138 static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
2140 if (a->left < b->left || a->top < b->top)
2143 if (a->left + a->width > b->left + b->width)
2146 if (a->top + a->height > b->top + b->height)
2153 vpfe_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
2155 struct vpfe_device *vpfe = video_drvdata(file);
2156 struct v4l2_rect cr = vpfe->crop;
2157 struct v4l2_rect r = s->r;
2159 /* If streaming is started, return error */
2160 if (vb2_is_busy(&vpfe->buffer_queue)) {
2161 vpfe_err(vpfe, "%s device busy\n", __func__);
2165 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2166 s->target != V4L2_SEL_TGT_CROP)
2169 v4l_bound_align_image(&r.width, 0, cr.width, 0,
2170 &r.height, 0, cr.height, 0, 0);
2172 r.left = clamp_t(unsigned int, r.left, 0, cr.width - r.width);
2173 r.top = clamp_t(unsigned int, r.top, 0, cr.height - r.height);
2175 if (s->flags & V4L2_SEL_FLAG_LE && !enclosed_rectangle(&r, &s->r))
2178 if (s->flags & V4L2_SEL_FLAG_GE && !enclosed_rectangle(&s->r, &r))
2181 s->r = vpfe->crop = r;
2183 vpfe_ccdc_set_image_window(&vpfe->ccdc, &r, vpfe->bpp);
2184 vpfe->fmt.fmt.pix.width = r.width;
2185 vpfe->fmt.fmt.pix.height = r.height;
2186 vpfe->fmt.fmt.pix.bytesperline = vpfe_ccdc_get_line_length(&vpfe->ccdc);
2187 vpfe->fmt.fmt.pix.sizeimage = vpfe->fmt.fmt.pix.bytesperline *
2188 vpfe->fmt.fmt.pix.height;
2190 vpfe_dbg(1, vpfe, "cropped (%d,%d)/%dx%d of %dx%d\n",
2191 r.left, r.top, r.width, r.height, cr.width, cr.height);
2196 static long vpfe_ioctl_default(struct file *file, void *priv,
2197 bool valid_prio, unsigned int cmd, void *param)
2199 struct vpfe_device *vpfe = video_drvdata(file);
2202 vpfe_dbg(2, vpfe, "vpfe_ioctl_default\n");
2205 vpfe_err(vpfe, "%s device busy\n", __func__);
2209 /* If streaming is started, return error */
2210 if (vb2_is_busy(&vpfe->buffer_queue)) {
2211 vpfe_err(vpfe, "%s device busy\n", __func__);
2216 case VIDIOC_AM437X_CCDC_CFG:
2217 ret = vpfe_ccdc_set_params(&vpfe->ccdc, (void __user *)param);
2220 "Error setting parameters in CCDC\n");
2223 ret = vpfe_get_ccdc_image_format(vpfe,
2227 "Invalid image format at CCDC\n");
2240 static const struct vb2_ops vpfe_video_qops = {
2241 .wait_prepare = vb2_ops_wait_prepare,
2242 .wait_finish = vb2_ops_wait_finish,
2243 .queue_setup = vpfe_queue_setup,
2244 .buf_prepare = vpfe_buffer_prepare,
2245 .buf_queue = vpfe_buffer_queue,
2246 .start_streaming = vpfe_start_streaming,
2247 .stop_streaming = vpfe_stop_streaming,
2250 /* vpfe capture driver file operations */
2251 static const struct v4l2_file_operations vpfe_fops = {
2252 .owner = THIS_MODULE,
2254 .release = vpfe_release,
2255 .read = vb2_fop_read,
2256 .poll = vb2_fop_poll,
2257 .unlocked_ioctl = video_ioctl2,
2258 .mmap = vb2_fop_mmap,
2261 /* vpfe capture ioctl operations */
2262 static const struct v4l2_ioctl_ops vpfe_ioctl_ops = {
2263 .vidioc_querycap = vpfe_querycap,
2264 .vidioc_enum_fmt_vid_cap = vpfe_enum_fmt,
2265 .vidioc_g_fmt_vid_cap = vpfe_g_fmt,
2266 .vidioc_s_fmt_vid_cap = vpfe_s_fmt,
2267 .vidioc_try_fmt_vid_cap = vpfe_try_fmt,
2269 .vidioc_enum_framesizes = vpfe_enum_size,
2271 .vidioc_enum_input = vpfe_enum_input,
2272 .vidioc_g_input = vpfe_g_input,
2273 .vidioc_s_input = vpfe_s_input,
2275 .vidioc_querystd = vpfe_querystd,
2276 .vidioc_s_std = vpfe_s_std,
2277 .vidioc_g_std = vpfe_g_std,
2279 .vidioc_reqbufs = vb2_ioctl_reqbufs,
2280 .vidioc_create_bufs = vb2_ioctl_create_bufs,
2281 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
2282 .vidioc_querybuf = vb2_ioctl_querybuf,
2283 .vidioc_qbuf = vb2_ioctl_qbuf,
2284 .vidioc_dqbuf = vb2_ioctl_dqbuf,
2285 .vidioc_expbuf = vb2_ioctl_expbuf,
2286 .vidioc_streamon = vb2_ioctl_streamon,
2287 .vidioc_streamoff = vb2_ioctl_streamoff,
2289 .vidioc_log_status = v4l2_ctrl_log_status,
2290 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
2291 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2293 .vidioc_cropcap = vpfe_cropcap,
2294 .vidioc_g_selection = vpfe_g_selection,
2295 .vidioc_s_selection = vpfe_s_selection,
2297 .vidioc_default = vpfe_ioctl_default,
2301 vpfe_async_bound(struct v4l2_async_notifier *notifier,
2302 struct v4l2_subdev *subdev,
2303 struct v4l2_async_subdev *asd)
2305 struct vpfe_device *vpfe = container_of(notifier->v4l2_dev,
2306 struct vpfe_device, v4l2_dev);
2307 struct v4l2_subdev_mbus_code_enum mbus_code;
2308 struct vpfe_subdev_info *sdinfo;
2312 vpfe_dbg(1, vpfe, "vpfe_async_bound\n");
2314 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
2315 if (vpfe->cfg->asd[i]->match.of.node == asd[i].match.of.node) {
2316 sdinfo = &vpfe->cfg->sub_devs[i];
2317 vpfe->sd[i] = subdev;
2318 vpfe->sd[i]->grp_id = sdinfo->grp_id;
2325 vpfe_info(vpfe, "sub device (%s) not matched\n", subdev->name);
2329 vpfe->video_dev.tvnorms |= sdinfo->inputs[0].std;
2331 /* setup the supported formats & indexes */
2332 for (j = 0, i = 0; ; ++j) {
2333 struct vpfe_fmt *fmt;
2336 memset(&mbus_code, 0, sizeof(mbus_code));
2337 mbus_code.index = j;
2338 mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE;
2339 ret = v4l2_subdev_call(subdev, pad, enum_mbus_code,
2344 fmt = find_format_by_code(mbus_code.code);
2348 fmt->supported = true;
2355 static int vpfe_probe_complete(struct vpfe_device *vpfe)
2357 struct video_device *vdev;
2358 struct vb2_queue *q;
2361 spin_lock_init(&vpfe->dma_queue_lock);
2362 mutex_init(&vpfe->lock);
2364 vpfe->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2366 /* set first sub device as current one */
2367 vpfe->current_subdev = &vpfe->cfg->sub_devs[0];
2368 vpfe->v4l2_dev.ctrl_handler = vpfe->sd[0]->ctrl_handler;
2370 err = vpfe_set_input(vpfe, 0);
2374 /* Initialize videobuf2 queue as per the buffer type */
2375 vpfe->alloc_ctx = vb2_dma_contig_init_ctx(vpfe->pdev);
2376 if (IS_ERR(vpfe->alloc_ctx)) {
2377 vpfe_err(vpfe, "Failed to get the context\n");
2378 err = PTR_ERR(vpfe->alloc_ctx);
2382 q = &vpfe->buffer_queue;
2383 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2384 q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
2386 q->ops = &vpfe_video_qops;
2387 q->mem_ops = &vb2_dma_contig_memops;
2388 q->buf_struct_size = sizeof(struct vpfe_cap_buffer);
2389 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2390 q->lock = &vpfe->lock;
2391 q->min_buffers_needed = 1;
2393 err = vb2_queue_init(q);
2395 vpfe_err(vpfe, "vb2_queue_init() failed\n");
2396 vb2_dma_contig_cleanup_ctx(vpfe->alloc_ctx);
2400 INIT_LIST_HEAD(&vpfe->dma_queue);
2402 vdev = &vpfe->video_dev;
2403 strlcpy(vdev->name, VPFE_MODULE_NAME, sizeof(vdev->name));
2404 vdev->release = video_device_release_empty;
2405 vdev->fops = &vpfe_fops;
2406 vdev->ioctl_ops = &vpfe_ioctl_ops;
2407 vdev->v4l2_dev = &vpfe->v4l2_dev;
2408 vdev->vfl_dir = VFL_DIR_RX;
2410 vdev->lock = &vpfe->lock;
2411 video_set_drvdata(vdev, vpfe);
2412 err = video_register_device(&vpfe->video_dev, VFL_TYPE_GRABBER, -1);
2415 "Unable to register video device.\n");
2422 v4l2_device_unregister(&vpfe->v4l2_dev);
2426 static int vpfe_async_complete(struct v4l2_async_notifier *notifier)
2428 struct vpfe_device *vpfe = container_of(notifier->v4l2_dev,
2429 struct vpfe_device, v4l2_dev);
2431 return vpfe_probe_complete(vpfe);
2434 static struct vpfe_config *
2435 vpfe_get_pdata(struct platform_device *pdev)
2437 struct device_node *endpoint = NULL;
2438 struct v4l2_of_endpoint bus_cfg;
2439 struct vpfe_subdev_info *sdinfo;
2440 struct vpfe_config *pdata;
2445 dev_dbg(&pdev->dev, "vpfe_get_pdata\n");
2447 if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
2448 return pdev->dev.platform_data;
2450 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
2454 for (i = 0; ; i++) {
2455 struct device_node *rem;
2457 endpoint = of_graph_get_next_endpoint(pdev->dev.of_node,
2462 sdinfo = &pdata->sub_devs[i];
2465 /* we only support camera */
2466 sdinfo->inputs[0].index = i;
2467 strcpy(sdinfo->inputs[0].name, "Camera");
2468 sdinfo->inputs[0].type = V4L2_INPUT_TYPE_CAMERA;
2469 sdinfo->inputs[0].std = V4L2_STD_ALL;
2470 sdinfo->inputs[0].capabilities = V4L2_IN_CAP_STD;
2472 sdinfo->can_route = 0;
2473 sdinfo->routes = NULL;
2475 of_property_read_u32(endpoint, "ti,am437x-vpfe-interface",
2476 &sdinfo->vpfe_param.if_type);
2477 if (sdinfo->vpfe_param.if_type < 0 ||
2478 sdinfo->vpfe_param.if_type > 4) {
2479 sdinfo->vpfe_param.if_type = VPFE_RAW_BAYER;
2482 err = v4l2_of_parse_endpoint(endpoint, &bus_cfg);
2484 dev_err(&pdev->dev, "Could not parse the endpoint\n");
2488 sdinfo->vpfe_param.bus_width = bus_cfg.bus.parallel.bus_width;
2490 if (sdinfo->vpfe_param.bus_width < 8 ||
2491 sdinfo->vpfe_param.bus_width > 16) {
2492 dev_err(&pdev->dev, "Invalid bus width.\n");
2496 flags = bus_cfg.bus.parallel.flags;
2498 if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
2499 sdinfo->vpfe_param.hdpol = 1;
2501 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
2502 sdinfo->vpfe_param.vdpol = 1;
2504 rem = of_graph_get_remote_port_parent(endpoint);
2506 dev_err(&pdev->dev, "Remote device at %s not found\n",
2507 endpoint->full_name);
2511 pdata->asd[i] = devm_kzalloc(&pdev->dev,
2512 sizeof(struct v4l2_async_subdev),
2514 if (!pdata->asd[i]) {
2520 pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF;
2521 pdata->asd[i]->match.of.node = rem;
2525 of_node_put(endpoint);
2529 of_node_put(endpoint);
2534 * vpfe_probe : This function creates device entries by register
2535 * itself to the V4L2 driver and initializes fields of each
2538 static int vpfe_probe(struct platform_device *pdev)
2540 struct vpfe_config *vpfe_cfg = vpfe_get_pdata(pdev);
2541 struct vpfe_device *vpfe;
2542 struct vpfe_ccdc *ccdc;
2543 struct resource *res;
2547 dev_err(&pdev->dev, "No platform data\n");
2551 vpfe = devm_kzalloc(&pdev->dev, sizeof(*vpfe), GFP_KERNEL);
2555 vpfe->pdev = &pdev->dev;
2556 vpfe->cfg = vpfe_cfg;
2559 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2560 ccdc->ccdc_cfg.base_addr = devm_ioremap_resource(&pdev->dev, res);
2561 if (IS_ERR(ccdc->ccdc_cfg.base_addr))
2562 return PTR_ERR(ccdc->ccdc_cfg.base_addr);
2564 vpfe->irq = platform_get_irq(pdev, 0);
2565 if (vpfe->irq <= 0) {
2566 dev_err(&pdev->dev, "No IRQ resource\n");
2570 ret = devm_request_irq(vpfe->pdev, vpfe->irq, vpfe_isr, 0,
2571 "vpfe_capture0", vpfe);
2573 dev_err(&pdev->dev, "Unable to request interrupt\n");
2577 ret = v4l2_device_register(&pdev->dev, &vpfe->v4l2_dev);
2580 "Unable to register v4l2 device.\n");
2584 /* set the driver data in platform device */
2585 platform_set_drvdata(pdev, vpfe);
2586 /* Enabling module functional clock */
2587 pm_runtime_enable(&pdev->dev);
2589 /* for now just enable it here instead of waiting for the open */
2590 pm_runtime_get_sync(&pdev->dev);
2592 vpfe_ccdc_config_defaults(ccdc);
2594 pm_runtime_put_sync(&pdev->dev);
2596 vpfe->sd = devm_kzalloc(&pdev->dev, sizeof(struct v4l2_subdev *) *
2597 ARRAY_SIZE(vpfe->cfg->asd), GFP_KERNEL);
2600 goto probe_out_v4l2_unregister;
2603 vpfe->notifier.subdevs = vpfe->cfg->asd;
2604 vpfe->notifier.num_subdevs = ARRAY_SIZE(vpfe->cfg->asd);
2605 vpfe->notifier.bound = vpfe_async_bound;
2606 vpfe->notifier.complete = vpfe_async_complete;
2607 ret = v4l2_async_notifier_register(&vpfe->v4l2_dev,
2610 vpfe_err(vpfe, "Error registering async notifier\n");
2612 goto probe_out_v4l2_unregister;
2617 probe_out_v4l2_unregister:
2618 v4l2_device_unregister(&vpfe->v4l2_dev);
2623 * vpfe_remove : It un-register device from V4L2 driver
2625 static int vpfe_remove(struct platform_device *pdev)
2627 struct vpfe_device *vpfe = platform_get_drvdata(pdev);
2629 vpfe_dbg(2, vpfe, "vpfe_remove\n");
2631 pm_runtime_disable(&pdev->dev);
2633 v4l2_async_notifier_unregister(&vpfe->notifier);
2634 v4l2_device_unregister(&vpfe->v4l2_dev);
2635 video_unregister_device(&vpfe->video_dev);
2640 #ifdef CONFIG_PM_SLEEP
2642 static void vpfe_save_context(struct vpfe_ccdc *ccdc)
2644 ccdc->ccdc_ctx[VPFE_PCR >> 2] = vpfe_reg_read(ccdc, VPFE_PCR);
2645 ccdc->ccdc_ctx[VPFE_SYNMODE >> 2] = vpfe_reg_read(ccdc, VPFE_SYNMODE);
2646 ccdc->ccdc_ctx[VPFE_SDOFST >> 2] = vpfe_reg_read(ccdc, VPFE_SDOFST);
2647 ccdc->ccdc_ctx[VPFE_SDR_ADDR >> 2] = vpfe_reg_read(ccdc, VPFE_SDR_ADDR);
2648 ccdc->ccdc_ctx[VPFE_CLAMP >> 2] = vpfe_reg_read(ccdc, VPFE_CLAMP);
2649 ccdc->ccdc_ctx[VPFE_DCSUB >> 2] = vpfe_reg_read(ccdc, VPFE_DCSUB);
2650 ccdc->ccdc_ctx[VPFE_COLPTN >> 2] = vpfe_reg_read(ccdc, VPFE_COLPTN);
2651 ccdc->ccdc_ctx[VPFE_BLKCMP >> 2] = vpfe_reg_read(ccdc, VPFE_BLKCMP);
2652 ccdc->ccdc_ctx[VPFE_VDINT >> 2] = vpfe_reg_read(ccdc, VPFE_VDINT);
2653 ccdc->ccdc_ctx[VPFE_ALAW >> 2] = vpfe_reg_read(ccdc, VPFE_ALAW);
2654 ccdc->ccdc_ctx[VPFE_REC656IF >> 2] = vpfe_reg_read(ccdc, VPFE_REC656IF);
2655 ccdc->ccdc_ctx[VPFE_CCDCFG >> 2] = vpfe_reg_read(ccdc, VPFE_CCDCFG);
2656 ccdc->ccdc_ctx[VPFE_CULLING >> 2] = vpfe_reg_read(ccdc, VPFE_CULLING);
2657 ccdc->ccdc_ctx[VPFE_HD_VD_WID >> 2] = vpfe_reg_read(ccdc,
2659 ccdc->ccdc_ctx[VPFE_PIX_LINES >> 2] = vpfe_reg_read(ccdc,
2661 ccdc->ccdc_ctx[VPFE_HORZ_INFO >> 2] = vpfe_reg_read(ccdc,
2663 ccdc->ccdc_ctx[VPFE_VERT_START >> 2] = vpfe_reg_read(ccdc,
2665 ccdc->ccdc_ctx[VPFE_VERT_LINES >> 2] = vpfe_reg_read(ccdc,
2667 ccdc->ccdc_ctx[VPFE_HSIZE_OFF >> 2] = vpfe_reg_read(ccdc,
2671 static int vpfe_suspend(struct device *dev)
2673 struct platform_device *pdev = to_platform_device(dev);
2674 struct vpfe_device *vpfe = platform_get_drvdata(pdev);
2675 struct vpfe_ccdc *ccdc = &vpfe->ccdc;
2677 /* if streaming has not started we don't care */
2678 if (!vb2_start_streaming_called(&vpfe->buffer_queue))
2681 pm_runtime_get_sync(dev);
2682 vpfe_config_enable(ccdc, 1);
2684 /* Save VPFE context */
2685 vpfe_save_context(ccdc);
2688 vpfe_pcr_enable(ccdc, 0);
2689 vpfe_config_enable(ccdc, 0);
2691 /* Disable both master and slave clock */
2692 pm_runtime_put_sync(dev);
2694 /* Select sleep pin state */
2695 pinctrl_pm_select_sleep_state(dev);
2700 static void vpfe_restore_context(struct vpfe_ccdc *ccdc)
2702 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_SYNMODE >> 2], VPFE_SYNMODE);
2703 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_CULLING >> 2], VPFE_CULLING);
2704 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_SDOFST >> 2], VPFE_SDOFST);
2705 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_SDR_ADDR >> 2], VPFE_SDR_ADDR);
2706 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_CLAMP >> 2], VPFE_CLAMP);
2707 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_DCSUB >> 2], VPFE_DCSUB);
2708 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_COLPTN >> 2], VPFE_COLPTN);
2709 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_BLKCMP >> 2], VPFE_BLKCMP);
2710 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_VDINT >> 2], VPFE_VDINT);
2711 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_ALAW >> 2], VPFE_ALAW);
2712 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_REC656IF >> 2], VPFE_REC656IF);
2713 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_CCDCFG >> 2], VPFE_CCDCFG);
2714 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_PCR >> 2], VPFE_PCR);
2715 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_HD_VD_WID >> 2],
2717 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_PIX_LINES >> 2],
2719 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_HORZ_INFO >> 2],
2721 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_VERT_START >> 2],
2723 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_VERT_LINES >> 2],
2725 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_HSIZE_OFF >> 2],
2729 static int vpfe_resume(struct device *dev)
2731 struct platform_device *pdev = to_platform_device(dev);
2732 struct vpfe_device *vpfe = platform_get_drvdata(pdev);
2733 struct vpfe_ccdc *ccdc = &vpfe->ccdc;
2735 /* if streaming has not started we don't care */
2736 if (!vb2_start_streaming_called(&vpfe->buffer_queue))
2739 /* Enable both master and slave clock */
2740 pm_runtime_get_sync(dev);
2741 vpfe_config_enable(ccdc, 1);
2743 /* Restore VPFE context */
2744 vpfe_restore_context(ccdc);
2746 vpfe_config_enable(ccdc, 0);
2747 pm_runtime_put_sync(dev);
2749 /* Select default pin state */
2750 pinctrl_pm_select_default_state(dev);
2757 static SIMPLE_DEV_PM_OPS(vpfe_pm_ops, vpfe_suspend, vpfe_resume);
2759 static const struct of_device_id vpfe_of_match[] = {
2760 { .compatible = "ti,am437x-vpfe", },
2763 MODULE_DEVICE_TABLE(of, vpfe_of_match);
2765 static struct platform_driver vpfe_driver = {
2766 .probe = vpfe_probe,
2767 .remove = vpfe_remove,
2769 .name = VPFE_MODULE_NAME,
2771 .of_match_table = of_match_ptr(vpfe_of_match),
2775 module_platform_driver(vpfe_driver);
2777 MODULE_AUTHOR("Texas Instruments");
2778 MODULE_DESCRIPTION("TI AM437x VPFE driver");
2779 MODULE_LICENSE("GPL");
2780 MODULE_VERSION(VPFE_VERSION);