diff options
Diffstat (limited to 'drivers/media/platform/soc_camera')
-rw-r--r-- | drivers/media/platform/soc_camera/Kconfig | 25 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/Makefile | 3 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/atmel-isi.c | 2 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/pxa_camera.c | 1866 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/rcar_vin.c | 1970 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c | 269 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/sh_mobile_csi2.c | 400 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/soc_camera.c | 130 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/soc_camera_platform.c | 45 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/soc_scale_crop.c | 97 | ||||
-rw-r--r-- | drivers/media/platform/soc_camera/soc_scale_crop.h | 6 |
11 files changed, 143 insertions, 4670 deletions
diff --git a/drivers/media/platform/soc_camera/Kconfig b/drivers/media/platform/soc_camera/Kconfig index 39f66414f621..86d74788544f 100644 --- a/drivers/media/platform/soc_camera/Kconfig +++ b/drivers/media/platform/soc_camera/Kconfig @@ -17,31 +17,6 @@ config SOC_CAMERA_PLATFORM help This is a generic SoC camera platform driver, useful for testing -config VIDEO_PXA27x - tristate "PXA27x Quick Capture Interface driver" - depends on VIDEO_DEV && PXA27x && SOC_CAMERA - select VIDEOBUF_DMA_SG - select SG_SPLIT - ---help--- - This is a v4l2 driver for the PXA27x Quick Capture Interface - -config VIDEO_RCAR_VIN_OLD - tristate "R-Car Video Input (VIN) support (DEPRECATED)" - depends on VIDEO_DEV && SOC_CAMERA - depends on ARCH_RENESAS || COMPILE_TEST - depends on HAS_DMA - select VIDEOBUF2_DMA_CONTIG - select SOC_CAMERA_SCALE_CROP - ---help--- - This is a v4l2 driver for the R-Car VIN Interface - -config VIDEO_SH_MOBILE_CSI2 - tristate "SuperH Mobile MIPI CSI-2 Interface driver" - depends on VIDEO_DEV && SOC_CAMERA && HAVE_CLK - depends on ARCH_SHMOBILE || SUPERH || COMPILE_TEST - ---help--- - This is a v4l2 driver for the SuperH MIPI CSI-2 Interface - config VIDEO_SH_MOBILE_CEU tristate "SuperH Mobile CEU Interface driver" depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA && HAVE_CLK diff --git a/drivers/media/platform/soc_camera/Makefile b/drivers/media/platform/soc_camera/Makefile index 7703cb7ce456..7633a0f2f66f 100644 --- a/drivers/media/platform/soc_camera/Makefile +++ b/drivers/media/platform/soc_camera/Makefile @@ -7,7 +7,4 @@ obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o # soc-camera host drivers have to be linked after camera drivers obj-$(CONFIG_VIDEO_ATMEL_ISI) += atmel-isi.o -obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o -obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o -obj-$(CONFIG_VIDEO_RCAR_VIN_OLD) += rcar_vin.o diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c index 30211f6b4483..46de657c3e6d 100644 --- a/drivers/media/platform/soc_camera/atmel-isi.c +++ b/drivers/media/platform/soc_camera/atmel-isi.c @@ -536,7 +536,7 @@ static void stop_streaming(struct vb2_queue *vq) pm_runtime_put(ici->v4l2_dev.dev); } -static struct vb2_ops isi_video_qops = { +static const struct vb2_ops isi_video_qops = { .queue_setup = queue_setup, .buf_init = buffer_init, .buf_prepare = buffer_prepare, diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c deleted file mode 100644 index 2aaf4a8f71a0..000000000000 --- a/drivers/media/platform/soc_camera/pxa_camera.c +++ /dev/null @@ -1,1866 +0,0 @@ -/* - * V4L2 Driver for PXA camera host - * - * Copyright (C) 2006, Sascha Hauer, Pengutronix - * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -#include <linux/init.h> -#include <linux/module.h> -#include <linux/io.h> -#include <linux/delay.h> -#include <linux/dma-mapping.h> -#include <linux/err.h> -#include <linux/errno.h> -#include <linux/fs.h> -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/mm.h> -#include <linux/moduleparam.h> -#include <linux/time.h> -#include <linux/device.h> -#include <linux/platform_device.h> -#include <linux/clk.h> -#include <linux/sched.h> -#include <linux/slab.h> -#include <linux/dmaengine.h> -#include <linux/dma-mapping.h> -#include <linux/dma/pxa-dma.h> - -#include <media/v4l2-common.h> -#include <media/v4l2-dev.h> -#include <media/videobuf-dma-sg.h> -#include <media/soc_camera.h> -#include <media/drv-intf/soc_mediabus.h> -#include <media/v4l2-of.h> - -#include <linux/videodev2.h> - -#include <linux/platform_data/media/camera-pxa.h> - -#define PXA_CAM_VERSION "0.0.6" -#define PXA_CAM_DRV_NAME "pxa27x-camera" - -/* Camera Interface */ -#define CICR0 0x0000 -#define CICR1 0x0004 -#define CICR2 0x0008 -#define CICR3 0x000C -#define CICR4 0x0010 -#define CISR 0x0014 -#define CIFR 0x0018 -#define CITOR 0x001C -#define CIBR0 0x0028 -#define CIBR1 0x0030 -#define CIBR2 0x0038 - -#define CICR0_DMAEN (1 << 31) /* DMA request enable */ -#define CICR0_PAR_EN (1 << 30) /* Parity enable */ -#define CICR0_SL_CAP_EN (1 << 29) /* Capture enable for slave mode */ -#define CICR0_ENB (1 << 28) /* Camera interface enable */ -#define CICR0_DIS (1 << 27) /* Camera interface disable */ -#define CICR0_SIM (0x7 << 24) /* Sensor interface mode mask */ -#define CICR0_TOM (1 << 9) /* Time-out mask */ -#define CICR0_RDAVM (1 << 8) /* Receive-data-available mask */ -#define CICR0_FEM (1 << 7) /* FIFO-empty mask */ -#define CICR0_EOLM (1 << 6) /* End-of-line mask */ -#define CICR0_PERRM (1 << 5) /* Parity-error mask */ -#define CICR0_QDM (1 << 4) /* Quick-disable mask */ -#define CICR0_CDM (1 << 3) /* Disable-done mask */ -#define CICR0_SOFM (1 << 2) /* Start-of-frame mask */ -#define CICR0_EOFM (1 << 1) /* End-of-frame mask */ -#define CICR0_FOM (1 << 0) /* FIFO-overrun mask */ - -#define CICR1_TBIT (1 << 31) /* Transparency bit */ -#define CICR1_RGBT_CONV (0x3 << 29) /* RGBT conversion mask */ -#define CICR1_PPL (0x7ff << 15) /* Pixels per line mask */ -#define CICR1_RGB_CONV (0x7 << 12) /* RGB conversion mask */ -#define CICR1_RGB_F (1 << 11) /* RGB format */ -#define CICR1_YCBCR_F (1 << 10) /* YCbCr format */ -#define CICR1_RGB_BPP (0x7 << 7) /* RGB bis per pixel mask */ -#define CICR1_RAW_BPP (0x3 << 5) /* Raw bis per pixel mask */ -#define CICR1_COLOR_SP (0x3 << 3) /* Color space mask */ -#define CICR1_DW (0x7 << 0) /* Data width mask */ - -#define CICR2_BLW (0xff << 24) /* Beginning-of-line pixel clock - wait count mask */ -#define CICR2_ELW (0xff << 16) /* End-of-line pixel clock - wait count mask */ -#define CICR2_HSW (0x3f << 10) /* Horizontal sync pulse width mask */ -#define CICR2_BFPW (0x3f << 3) /* Beginning-of-frame pixel clock - wait count mask */ -#define CICR2_FSW (0x7 << 0) /* Frame stabilization - wait count mask */ - -#define CICR3_BFW (0xff << 24) /* Beginning-of-frame line clock - wait count mask */ -#define CICR3_EFW (0xff << 16) /* End-of-frame line clock - wait count mask */ -#define CICR3_VSW (0x3f << 10) /* Vertical sync pulse width mask */ -#define CICR3_BFPW (0x3f << 3) /* Beginning-of-frame pixel clock - wait count mask */ -#define CICR3_LPF (0x7ff << 0) /* Lines per frame mask */ - -#define CICR4_MCLK_DLY (0x3 << 24) /* MCLK Data Capture Delay mask */ -#define CICR4_PCLK_EN (1 << 23) /* Pixel clock enable */ -#define CICR4_PCP (1 << 22) /* Pixel clock polarity */ -#define CICR4_HSP (1 << 21) /* Horizontal sync polarity */ -#define CICR4_VSP (1 << 20) /* Vertical sync polarity */ -#define CICR4_MCLK_EN (1 << 19) /* MCLK enable */ -#define CICR4_FR_RATE (0x7 << 8) /* Frame rate mask */ -#define CICR4_DIV (0xff << 0) /* Clock divisor mask */ - -#define CISR_FTO (1 << 15) /* FIFO time-out */ -#define CISR_RDAV_2 (1 << 14) /* Channel 2 receive data available */ -#define CISR_RDAV_1 (1 << 13) /* Channel 1 receive data available */ -#define CISR_RDAV_0 (1 << 12) /* Channel 0 receive data available */ -#define CISR_FEMPTY_2 (1 << 11) /* Channel 2 FIFO empty */ -#define CISR_FEMPTY_1 (1 << 10) /* Channel 1 FIFO empty */ -#define CISR_FEMPTY_0 (1 << 9) /* Channel 0 FIFO empty */ -#define CISR_EOL (1 << 8) /* End of line */ -#define CISR_PAR_ERR (1 << 7) /* Parity error */ -#define CISR_CQD (1 << 6) /* Camera interface quick disable */ -#define CISR_CDD (1 << 5) /* Camera interface disable done */ -#define CISR_SOF (1 << 4) /* Start of frame */ -#define CISR_EOF (1 << 3) /* End of frame */ -#define CISR_IFO_2 (1 << 2) /* FIFO overrun for Channel 2 */ -#define CISR_IFO_1 (1 << 1) /* FIFO overrun for Channel 1 */ -#define CISR_IFO_0 (1 << 0) /* FIFO overrun for Channel 0 */ - -#define CIFR_FLVL2 (0x7f << 23) /* FIFO 2 level mask */ -#define CIFR_FLVL1 (0x7f << 16) /* FIFO 1 level mask */ -#define CIFR_FLVL0 (0xff << 8) /* FIFO 0 level mask */ -#define CIFR_THL_0 (0x3 << 4) /* Threshold Level for Channel 0 FIFO */ -#define CIFR_RESET_F (1 << 3) /* Reset input FIFOs */ -#define CIFR_FEN2 (1 << 2) /* FIFO enable for channel 2 */ -#define CIFR_FEN1 (1 << 1) /* FIFO enable for channel 1 */ -#define CIFR_FEN0 (1 << 0) /* FIFO enable for channel 0 */ - -#define CICR0_SIM_MP (0 << 24) -#define CICR0_SIM_SP (1 << 24) -#define CICR0_SIM_MS (2 << 24) -#define CICR0_SIM_EP (3 << 24) -#define CICR0_SIM_ES (4 << 24) - -#define CICR1_DW_VAL(x) ((x) & CICR1_DW) /* Data bus width */ -#define CICR1_PPL_VAL(x) (((x) << 15) & CICR1_PPL) /* Pixels per line */ -#define CICR1_COLOR_SP_VAL(x) (((x) << 3) & CICR1_COLOR_SP) /* color space */ -#define CICR1_RGB_BPP_VAL(x) (((x) << 7) & CICR1_RGB_BPP) /* bpp for rgb */ -#define CICR1_RGBT_CONV_VAL(x) (((x) << 29) & CICR1_RGBT_CONV) /* rgbt conv */ - -#define CICR2_BLW_VAL(x) (((x) << 24) & CICR2_BLW) /* Beginning-of-line pixel clock wait count */ -#define CICR2_ELW_VAL(x) (((x) << 16) & CICR2_ELW) /* End-of-line pixel clock wait count */ -#define CICR2_HSW_VAL(x) (((x) << 10) & CICR2_HSW) /* Horizontal sync pulse width */ -#define CICR2_BFPW_VAL(x) (((x) << 3) & CICR2_BFPW) /* Beginning-of-frame pixel clock wait count */ -#define CICR2_FSW_VAL(x) (((x) << 0) & CICR2_FSW) /* Frame stabilization wait count */ - -#define CICR3_BFW_VAL(x) (((x) << 24) & CICR3_BFW) /* Beginning-of-frame line clock wait count */ -#define CICR3_EFW_VAL(x) (((x) << 16) & CICR3_EFW) /* End-of-frame line clock wait count */ -#define CICR3_VSW_VAL(x) (((x) << 11) & CICR3_VSW) /* Vertical sync pulse width */ -#define CICR3_LPF_VAL(x) (((x) << 0) & CICR3_LPF) /* Lines per frame */ - -#define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \ - CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \ - CICR0_EOFM | CICR0_FOM) - -/* - * Structures - */ -enum pxa_camera_active_dma { - DMA_Y = 0x1, - DMA_U = 0x2, - DMA_V = 0x4, -}; - -/* buffer for one video frame */ -struct pxa_buffer { - /* common v4l buffer stuff -- must be first */ - struct videobuf_buffer vb; - u32 code; - /* our descriptor lists for Y, U and V channels */ - struct dma_async_tx_descriptor *descs[3]; - dma_cookie_t cookie[3]; - struct scatterlist *sg[3]; - int sg_len[3]; - int inwork; - enum pxa_camera_active_dma active_dma; -}; - -struct pxa_camera_dev { - struct soc_camera_host soc_host; - /* - * PXA27x is only supposed to handle one camera on its Quick Capture - * interface. If anyone ever builds hardware to enable more than - * one camera, they will have to modify this driver too - */ - struct clk *clk; - - unsigned int irq; - void __iomem *base; - - int channels; - struct dma_chan *dma_chans[3]; - - struct pxacamera_platform_data *pdata; - struct resource *res; - unsigned long platform_flags; - unsigned long ciclk; - unsigned long mclk; - u32 mclk_divisor; - u16 width_flags; /* max 10 bits */ - - struct list_head capture; - - spinlock_t lock; - - struct pxa_buffer *active; - struct tasklet_struct task_eof; - - u32 save_cicr[5]; -}; - -struct pxa_cam { - unsigned long flags; -}; - -static const char *pxa_cam_driver_description = "PXA_Camera"; - -static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ - -/* - * Videobuf operations - */ -static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, - unsigned int *size) -{ - struct soc_camera_device *icd = vq->priv_data; - - dev_dbg(icd->parent, "count=%d, size=%d\n", *count, *size); - - *size = icd->sizeimage; - - if (0 == *count) - *count = 32; - if (*size * *count > vid_limit * 1024 * 1024) - *count = (vid_limit * 1024 * 1024) / *size; - - return 0; -} - -static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) -{ - struct soc_camera_device *icd = vq->priv_data; - struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); - int i; - - BUG_ON(in_interrupt()); - - dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__, - &buf->vb, buf->vb.baddr, buf->vb.bsize); - - /* - * This waits until this buffer is out of danger, i.e., until it is no - * longer in STATE_QUEUED or STATE_ACTIVE - */ - videobuf_waiton(vq, &buf->vb, 0, 0); - - for (i = 0; i < 3 && buf->descs[i]; i++) { - dmaengine_desc_free(buf->descs[i]); - kfree(buf->sg[i]); - buf->descs[i] = NULL; - buf->sg[i] = NULL; - buf->sg_len[i] = 0; - } - videobuf_dma_unmap(vq->dev, dma); - videobuf_dma_free(dma); - - buf->vb.state = VIDEOBUF_NEEDS_INIT; - - dev_dbg(icd->parent, "%s end (vb=0x%p) 0x%08lx %d\n", __func__, - &buf->vb, buf->vb.baddr, buf->vb.bsize); -} - -static void pxa_camera_dma_irq(struct pxa_camera_dev *pcdev, - enum pxa_camera_active_dma act_dma); - -static void pxa_camera_dma_irq_y(void *data) -{ - struct pxa_camera_dev *pcdev = data; - - pxa_camera_dma_irq(pcdev, DMA_Y); -} - -static void pxa_camera_dma_irq_u(void *data) -{ - struct pxa_camera_dev *pcdev = data; - - pxa_camera_dma_irq(pcdev, DMA_U); -} - -static void pxa_camera_dma_irq_v(void *data) -{ - struct pxa_camera_dev *pcdev = data; - - pxa_camera_dma_irq(pcdev, DMA_V); -} - -/** - * pxa_init_dma_channel - init dma descriptors - * @pcdev: pxa camera device - * @buf: pxa buffer to find pxa dma channel - * @dma: dma video buffer - * @channel: dma channel (0 => 'Y', 1 => 'U', 2 => 'V') - * @cibr: camera Receive Buffer Register - * @size: bytes to transfer - * @offset: offset in videobuffer of the first byte to transfer - * - * Prepares the pxa dma descriptors to transfer one camera channel. - * - * Returns 0 if success or -ENOMEM if no memory is available - */ -static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev, - struct pxa_buffer *buf, - struct videobuf_dmabuf *dma, int channel, - int cibr, int size, int offset) -{ - struct dma_chan *dma_chan = pcdev->dma_chans[channel]; - struct scatterlist *sg = buf->sg[channel]; - int sglen = buf->sg_len[channel]; - struct dma_async_tx_descriptor *tx; - - tx = dmaengine_prep_slave_sg(dma_chan, sg, sglen, DMA_DEV_TO_MEM, - DMA_PREP_INTERRUPT | DMA_CTRL_REUSE); - if (!tx) { - dev_err(pcdev->soc_host.v4l2_dev.dev, - "dmaengine_prep_slave_sg failed\n"); - goto fail; - } - - tx->callback_param = pcdev; - switch (channel) { - case 0: - tx->callback = pxa_camera_dma_irq_y; - break; - case 1: - tx->callback = pxa_camera_dma_irq_u; - break; - case 2: - tx->callback = pxa_camera_dma_irq_v; - break; - } - - buf->descs[channel] = tx; - return 0; -fail: - kfree(sg); - - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "%s (vb=0x%p) dma_tx=%p\n", - __func__, &buf->vb, tx); - - return -ENOMEM; -} - -static void pxa_videobuf_set_actdma(struct pxa_camera_dev *pcdev, - struct pxa_buffer *buf) -{ - buf->active_dma = DMA_Y; - if (pcdev->channels == 3) - buf->active_dma |= DMA_U | DMA_V; -} - -/* - * Please check the DMA prepared buffer structure in : - * Documentation/video4linux/pxa_camera.txt - * Please check also in pxa_camera_check_link_miss() to understand why DMA chain - * modification while DMA chain is running will work anyway. - */ -static int pxa_videobuf_prepare(struct videobuf_queue *vq, - struct videobuf_buffer *vb, enum v4l2_field field) -{ - struct soc_camera_device *icd = vq->priv_data; - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct pxa_camera_dev *pcdev = ici->priv; - struct device *dev = pcdev->soc_host.v4l2_dev.dev; - struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); - int ret; - int size_y, size_u = 0, size_v = 0; - size_t sizes[3]; - - dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, - vb, vb->baddr, vb->bsize); - - /* Added list head initialization on alloc */ - WARN_ON(!list_empty(&vb->queue)); - -#ifdef DEBUG - /* - * This can be useful if you want to see if we actually fill - * the buffer with something - */ - memset((void *)vb->baddr, 0xaa, vb->bsize); -#endif - - BUG_ON(NULL == icd->current_fmt); - - /* - * I think, in buf_prepare you only have to protect global data, - * the actual buffer is yours - */ - buf->inwork = 1; - - if (buf->code != icd->current_fmt->code || - vb->width != icd->user_width || - vb->height != icd->user_height || - vb->field != field) { - buf->code = icd->current_fmt->code; - vb->width = icd->user_width; - vb->height = icd->user_height; - vb->field = field; - vb->state = VIDEOBUF_NEEDS_INIT; - } - - vb->size = icd->sizeimage; - if (0 != vb->baddr && vb->bsize < vb->size) { - ret = -EINVAL; - goto out; - } - - if (vb->state == VIDEOBUF_NEEDS_INIT) { - int size = vb->size; - struct videobuf_dmabuf *dma = videobuf_to_dma(vb); - - ret = videobuf_iolock(vq, vb, NULL); - if (ret) - goto out; - - if (pcdev->channels == 3) { - size_y = size / 2; - size_u = size_v = size / 4; - } else { - size_y = size; - } - - sizes[0] = size_y; - sizes[1] = size_u; - sizes[2] = size_v; - ret = sg_split(dma->sglist, dma->sglen, 0, pcdev->channels, - sizes, buf->sg, buf->sg_len, GFP_KERNEL); - if (ret < 0) { - dev_err(dev, "sg_split failed: %d\n", ret); - goto fail; - } - - /* init DMA for Y channel */ - ret = pxa_init_dma_channel(pcdev, buf, dma, 0, CIBR0, - size_y, 0); - if (ret) { - dev_err(dev, "DMA initialization for Y/RGB failed\n"); - goto fail; - } - - /* init DMA for U channel */ - if (size_u) - ret = pxa_init_dma_channel(pcdev, buf, dma, 1, CIBR1, - size_u, size_y); - if (ret) { - dev_err(dev, "DMA initialization for U failed\n"); - goto fail; - } - - /* init DMA for V channel */ - if (size_v) - ret = pxa_init_dma_channel(pcdev, buf, dma, 2, CIBR2, - size_v, size_y + size_u); - if (ret) { - dev_err(dev, "DMA initialization for V failed\n"); - goto fail; - } - - vb->state = VIDEOBUF_PREPARED; - } - - buf->inwork = 0; - pxa_videobuf_set_actdma(pcdev, buf); - - return 0; - -fail: - free_buffer(vq, buf); -out: - buf->inwork = 0; - return ret; -} - -/** - * pxa_dma_start_channels - start DMA channel for active buffer - * @pcdev: pxa camera device - * - * Initialize DMA channels to the beginning of the active video buffer, and - * start these channels. - */ -static void pxa_dma_start_channels(struct pxa_camera_dev *pcdev) -{ - int i; - struct pxa_buffer *active; - - active = pcdev->active; - - for (i = 0; i < pcdev->channels; i++) { - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "%s (channel=%d)\n", __func__, i); - dma_async_issue_pending(pcdev->dma_chans[i]); - } -} - -static void pxa_dma_stop_channels(struct pxa_camera_dev *pcdev) -{ - int i; - - for (i = 0; i < pcdev->channels; i++) { - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "%s (channel=%d)\n", __func__, i); - dmaengine_terminate_all(pcdev->dma_chans[i]); - } -} - -static void pxa_dma_add_tail_buf(struct pxa_camera_dev *pcdev, - struct pxa_buffer *buf) -{ - int i; - - for (i = 0; i < pcdev->channels; i++) { - buf->cookie[i] = dmaengine_submit(buf->descs[i]); - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "%s (channel=%d) : submit vb=%p cookie=%d\n", - __func__, i, buf, buf->descs[i]->cookie); - } -} - -/** - * pxa_camera_start_capture - start video capturing - * @pcdev: camera device - * - * Launch capturing. DMA channels should not be active yet. They should get - * activated at the end of frame interrupt, to capture only whole frames, and - * never begin the capture of a partial frame. - */ -static void pxa_camera_start_capture(struct pxa_camera_dev *pcdev) -{ - unsigned long cicr0; - - dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__); - __raw_writel(__raw_readl(pcdev->base + CISR), pcdev->base + CISR); - /* Enable End-Of-Frame Interrupt */ - cicr0 = __raw_readl(pcdev->base + CICR0) | CICR0_ENB; - cicr0 &= ~CICR0_EOFM; - __raw_writel(cicr0, pcdev->base + CICR0); -} - -static void pxa_camera_stop_capture(struct pxa_camera_dev *pcdev) -{ - unsigned long cicr0; - - pxa_dma_stop_channels(pcdev); - - cicr0 = __raw_readl(pcdev->base + CICR0) & ~CICR0_ENB; - __raw_writel(cicr0, pcdev->base + CICR0); - - pcdev->active = NULL; - dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s\n", __func__); -} - -/* Called under spinlock_irqsave(&pcdev->lock, ...) */ -static void pxa_videobuf_queue(struct videobuf_queue *vq, - struct videobuf_buffer *vb) -{ - struct soc_camera_device *icd = vq->priv_data; - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct pxa_camera_dev *pcdev = ici->priv; - struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); - - dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d active=%p\n", - __func__, vb, vb->baddr, vb->bsize, pcdev->active); - - list_add_tail(&vb->queue, &pcdev->capture); - - vb->state = VIDEOBUF_ACTIVE; - pxa_dma_add_tail_buf(pcdev, buf); - - if (!pcdev->active) - pxa_camera_start_capture(pcdev); -} - -static void pxa_videobuf_release(struct videobuf_queue *vq, - struct videobuf_buffer *vb) -{ - struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb); -#ifdef DEBUG - struct soc_camera_device *icd = vq->priv_data; - struct device *dev = icd->parent; - - dev_dbg(dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, - vb, vb->baddr, vb->bsize); - - switch (vb->state) { - case VIDEOBUF_ACTIVE: - dev_dbg(dev, "%s (active)\n", __func__); - break; - case VIDEOBUF_QUEUED: - dev_dbg(dev, "%s (queued)\n", __func__); - break; - case VIDEOBUF_PREPARED: - dev_dbg(dev, "%s (prepared)\n", __func__); - break; - default: - dev_dbg(dev, "%s (unknown)\n", __func__); - break; - } -#endif - - free_buffer(vq, buf); -} - -static void pxa_camera_wakeup(struct pxa_camera_dev *pcdev, - struct videobuf_buffer *vb, - struct pxa_buffer *buf) -{ - /* _init is used to debug races, see comment in pxa_camera_reqbufs() */ - list_del_init(&vb->queue); - vb->state = VIDEOBUF_DONE; - v4l2_get_timestamp(&vb->ts); - vb->field_count++; - wake_up(&vb->done); - dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s dequeud buffer (vb=0x%p)\n", - __func__, vb); - - if (list_empty(&pcdev->capture)) { - pxa_camera_stop_capture(pcdev); - return; - } - - pcdev->active = list_entry(pcdev->capture.next, - struct pxa_buffer, vb.queue); -} - -/** - * pxa_camera_check_link_miss - check missed DMA linking - * @pcdev: camera device - * - * The DMA chaining is done with DMA running. This means a tiny temporal window - * remains, where a buffer is queued on the chain, while the chain is already - * stopped. This means the tailed buffer would never be transferred by DMA. - * This function restarts the capture for this corner case, where : - * - DADR() == DADDR_STOP - * - a videobuffer is queued on the pcdev->capture list - * - * Please check the "DMA hot chaining timeslice issue" in - * Documentation/video4linux/pxa_camera.txt - * - * Context: should only be called within the dma irq handler - */ -static void pxa_camera_check_link_miss(struct pxa_camera_dev *pcdev, - dma_cookie_t last_submitted, - dma_cookie_t last_issued) -{ - bool is_dma_stopped = last_submitted != last_issued; - - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "%s : top queued buffer=%p, is_dma_stopped=%d\n", - __func__, pcdev->active, is_dma_stopped); - - if (pcdev->active && is_dma_stopped) - pxa_camera_start_capture(pcdev); -} - -static void pxa_camera_dma_irq(struct pxa_camera_dev *pcdev, - enum pxa_camera_active_dma act_dma) -{ - struct device *dev = pcdev->soc_host.v4l2_dev.dev; - struct pxa_buffer *buf, *last_buf; - unsigned long flags; - u32 camera_status, overrun; - int chan; - struct videobuf_buffer *vb; - enum dma_status last_status; - dma_cookie_t last_issued; - - spin_lock_irqsave(&pcdev->lock, flags); - - camera_status = __raw_readl(pcdev->base + CISR); - dev_dbg(dev, "camera dma irq, cisr=0x%x dma=%d\n", - camera_status, act_dma); - overrun = CISR_IFO_0; - if (pcdev->channels == 3) - overrun |= CISR_IFO_1 | CISR_IFO_2; - - /* - * pcdev->active should not be NULL in DMA irq handler. - * - * But there is one corner case : if capture was stopped due to an - * overrun of channel 1, and at that same channel 2 was completed. - * - * When handling the overrun in DMA irq for channel 1, we'll stop the - * capture and restart it (and thus set pcdev->active to NULL). But the - * DMA irq handler will already be pending for channel 2. So on entering - * the DMA irq handler for channel 2 there will be no active buffer, yet - * that is normal. - */ - if (!pcdev->active) - goto out; - - vb = &pcdev->active->vb; - buf = container_of(vb, struct pxa_buffer, vb); - WARN_ON(buf->inwork || list_empty(&vb->queue)); - - /* - * It's normal if the last frame creates an overrun, as there - * are no more DMA descriptors to fetch from QCI fifos - */ - switch (act_dma) { - case DMA_U: - chan = 1; - break; - case DMA_V: - chan = 2; - break; - default: - chan = 0; - break; - } - last_buf = list_entry(pcdev->capture.prev, - struct pxa_buffer, vb.queue); - last_status = dma_async_is_tx_complete(pcdev->dma_chans[chan], - last_buf->cookie[chan], - NULL, &last_issued); - if (camera_status & overrun && - last_status != DMA_COMPLETE) { - dev_dbg(dev, "FIFO overrun! CISR: %x\n", - camera_status); - pxa_camera_stop_capture(pcdev); - list_for_each_entry(buf, &pcdev->capture, vb.queue) - pxa_dma_add_tail_buf(pcdev, buf); - pxa_camera_start_capture(pcdev); - goto out; - } - buf->active_dma &= ~act_dma; - if (!buf->active_dma) { - pxa_camera_wakeup(pcdev, vb, buf); - pxa_camera_check_link_miss(pcdev, last_buf->cookie[chan], - last_issued); - } - -out: - spin_unlock_irqrestore(&pcdev->lock, flags); -} - -static struct videobuf_queue_ops pxa_videobuf_ops = { - .buf_setup = pxa_videobuf_setup, - .buf_prepare = pxa_videobuf_prepare, - .buf_queue = pxa_videobuf_queue, - .buf_release = pxa_videobuf_release, -}; - -static void pxa_camera_init_videobuf(struct videobuf_queue *q, - struct soc_camera_device *icd) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct pxa_camera_dev *pcdev = ici->priv; - - /* - * We must pass NULL as dev pointer, then all pci_* dma operations - * transform to normal dma_* ones. - */ - videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock, - V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, - sizeof(struct pxa_buffer), icd, &ici->host_lock); -} - -static u32 mclk_get_divisor(struct platform_device *pdev, - struct pxa_camera_dev *pcdev) -{ - unsigned long mclk = pcdev->mclk; - struct device *dev = &pdev->dev; - u32 div; - unsigned long lcdclk; - - lcdclk = clk_get_rate(pcdev->clk); - pcdev->ciclk = lcdclk; - - /* mclk <= ciclk / 4 (27.4.2) */ - if (mclk > lcdclk / 4) { - mclk = lcdclk / 4; - dev_warn(dev, "Limiting master clock to %lu\n", mclk); - } - - /* We verify mclk != 0, so if anyone breaks it, here comes their Oops */ - div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1; - - /* If we're not supplying MCLK, leave it at 0 */ - if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) - pcdev->mclk = lcdclk / (2 * (div + 1)); - - dev_dbg(dev, "LCD clock %luHz, target freq %luHz, divisor %u\n", - lcdclk, mclk, div); - - return div; -} - -static void recalculate_fifo_timeout(struct pxa_camera_dev *pcdev, - unsigned long pclk) -{ - /* We want a timeout > 1 pixel time, not ">=" */ - u32 ciclk_per_pixel = pcdev->ciclk / pclk + 1; - - __raw_writel(ciclk_per_pixel, pcdev->base + CITOR); -} - -static void pxa_camera_activate(struct pxa_camera_dev *pcdev) -{ - u32 cicr4 = 0; - - /* disable all interrupts */ - __raw_writel(0x3ff, pcdev->base + CICR0); - - if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) - cicr4 |= CICR4_PCLK_EN; - if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) - cicr4 |= CICR4_MCLK_EN; - if (pcdev->platform_flags & PXA_CAMERA_PCP) - cicr4 |= CICR4_PCP; - if (pcdev->platform_flags & PXA_CAMERA_HSP) - cicr4 |= CICR4_HSP; - if (pcdev->platform_flags & PXA_CAMERA_VSP) - cicr4 |= CICR4_VSP; - - __raw_writel(pcdev->mclk_divisor | cicr4, pcdev->base + CICR4); - - if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) - /* Initialise the timeout under the assumption pclk = mclk */ - recalculate_fifo_timeout(pcdev, pcdev->mclk); - else - /* "Safe default" - 13MHz */ - recalculate_fifo_timeout(pcdev, 13000000); - - clk_prepare_enable(pcdev->clk); -} - -static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev) -{ - clk_disable_unprepare(pcdev->clk); -} - -static void pxa_camera_eof(unsigned long arg) -{ - struct pxa_camera_dev *pcdev = (struct pxa_camera_dev *)arg; - unsigned long cifr; - struct pxa_buffer *buf; - struct videobuf_buffer *vb; - - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "Camera interrupt status 0x%x\n", - __raw_readl(pcdev->base + CISR)); - - /* Reset the FIFOs */ - cifr = __raw_readl(pcdev->base + CIFR) | CIFR_RESET_F; - __raw_writel(cifr, pcdev->base + CIFR); - - pcdev->active = list_first_entry(&pcdev->capture, - struct pxa_buffer, vb.queue); - vb = &pcdev->active->vb; - buf = container_of(vb, struct pxa_buffer, vb); - pxa_videobuf_set_actdma(pcdev, buf); - - pxa_dma_start_channels(pcdev); -} - -static irqreturn_t pxa_camera_irq(int irq, void *data) -{ - struct pxa_camera_dev *pcdev = data; - unsigned long status, cicr0; - - status = __raw_readl(pcdev->base + CISR); - dev_dbg(pcdev->soc_host.v4l2_dev.dev, - "Camera interrupt status 0x%lx\n", status); - - if (!status) - return IRQ_NONE; - - __raw_writel(status, pcdev->base + CISR); - - if (status & CISR_EOF) { - cicr0 = __raw_readl(pcdev->base + CICR0) | CICR0_EOFM; - __raw_writel(cicr0, pcdev->base + CICR0); - tasklet_schedule(&pcdev->task_eof); - } - - return IRQ_HANDLED; -} - -static int pxa_camera_add_device(struct soc_camera_device *icd) -{ - dev_info(icd->parent, "PXA Camera driver attached to camera %d\n", - icd->devnum); - - return 0; -} - -static void pxa_camera_remove_device(struct soc_camera_device *icd) -{ - dev_info(icd->parent, "PXA Camera driver detached from camera %d\n", - icd->devnum); -} - -/* - * The following two functions absolutely depend on the fact, that - * there can be only one camera on PXA quick capture interface - * Called with .host_lock held - */ -static int pxa_camera_clock_start(struct soc_camera_host *ici) -{ - struct pxa_camera_dev *pcdev = ici->priv; - - pxa_camera_activate(pcdev); - - return 0; -} - -/* Called with .host_lock held */ -static void pxa_camera_clock_stop(struct soc_camera_host *ici) -{ - struct pxa_camera_dev *pcdev = ici->priv; - - /* disable capture, disable interrupts */ - __raw_writel(0x3ff, pcdev->base + CICR0); - - /* Stop DMA engine */ - pxa_dma_stop_channels(pcdev); - pxa_camera_deactivate(pcdev); -} - -static int test_platform_param(struct pxa_camera_dev *pcdev, - unsigned char buswidth, unsigned long *flags) -{ - /* - * Platform specified synchronization and pixel clock polarities are - * only a recommendation and are only used during probing. The PXA270 - * quick capture interface supports both. - */ - *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ? - V4L2_MBUS_MASTER : V4L2_MBUS_SLAVE) | - V4L2_MBUS_HSYNC_ACTIVE_HIGH | - V4L2_MBUS_HSYNC_ACTIVE_LOW | - V4L2_MBUS_VSYNC_ACTIVE_HIGH | - V4L2_MBUS_VSYNC_ACTIVE_LOW | - V4L2_MBUS_DATA_ACTIVE_HIGH | - V4L2_MBUS_PCLK_SAMPLE_RISING | - V4L2_MBUS_PCLK_SAMPLE_FALLING; - - /* If requested data width is supported by the platform, use it */ - if ((1 << (buswidth - 1)) & pcdev->width_flags) - return 0; - - return -EINVAL; -} - -static void pxa_camera_setup_cicr(struct soc_camera_device *icd, - unsigned long flags, __u32 pixfmt) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct pxa_camera_dev *pcdev = ici->priv; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - unsigned long dw, bpp; - u32 cicr0, cicr1, cicr2, cicr3, cicr4 = 0, y_skip_top; - int ret = v4l2_subdev_call(sd, sensor, g_skip_top_lines, &y_skip_top); - - if (ret < 0) - y_skip_top = 0; - - /* - * Datawidth is now guaranteed to be equal to one of the three values. - * We fix bit-per-pixel equal to data-width... - */ - switch (icd->current_fmt->host_fmt->bits_per_sample) { - case 10: - dw = 4; - bpp = 0x40; - break; - case 9: - dw = 3; - bpp = 0x20; - break; - default: - /* - * Actually it can only be 8 now, - * default is just to silence compiler warnings - */ - case 8: - dw = 2; - bpp = 0; - } - - if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) - cicr4 |= CICR4_PCLK_EN; - if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) - cicr4 |= CICR4_MCLK_EN; - if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) - cicr4 |= CICR4_PCP; - if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) - cicr4 |= CICR4_HSP; - if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) - cicr4 |= CICR4_VSP; - - cicr0 = __raw_readl(pcdev->base + CICR0); - if (cicr0 & CICR0_ENB) - __raw_writel(cicr0 & ~CICR0_ENB, pcdev->base + CICR0); - - cicr1 = CICR1_PPL_VAL(icd->user_width - 1) | bpp | dw; - - switch (pixfmt) { - case V4L2_PIX_FMT_YUV422P: - pcdev->channels = 3; - cicr1 |= CICR1_YCBCR_F; - /* - * Normally, pxa bus wants as input UYVY format. We allow all - * reorderings of the YUV422 format, as no processing is done, - * and the YUV stream is just passed through without any - * transformation. Note that UYVY is the only format that - * should be used if pxa framebuffer Overlay2 is used. - */ - case V4L2_PIX_FMT_UYVY: - case V4L2_PIX_FMT_VYUY: - case V4L2_PIX_FMT_YUYV: - case V4L2_PIX_FMT_YVYU: - cicr1 |= CICR1_COLOR_SP_VAL(2); - break; - case V4L2_PIX_FMT_RGB555: - cicr1 |= CICR1_RGB_BPP_VAL(1) | CICR1_RGBT_CONV_VAL(2) | - CICR1_TBIT | CICR1_COLOR_SP_VAL(1); - break; - case V4L2_PIX_FMT_RGB565: - cicr1 |= CICR1_COLOR_SP_VAL(1) | CICR1_RGB_BPP_VAL(2); - break; - } - - cicr2 = 0; - cicr3 = CICR3_LPF_VAL(icd->user_height - 1) | - CICR3_BFW_VAL(min((u32)255, y_skip_top)); - cicr4 |= pcdev->mclk_divisor; - - __raw_writel(cicr1, pcdev->base + CICR1); - __raw_writel(cicr2, pcdev->base + CICR2); - __raw_writel(cicr3, pcdev->base + CICR3); - __raw_writel(cicr4, pcdev->base + CICR4); - - /* CIF interrupts are not used, only DMA */ - cicr0 = (cicr0 & CICR0_ENB) | (pcdev->platform_flags & PXA_CAMERA_MASTER ? - CICR0_SIM_MP : (CICR0_SL_CAP_EN | CICR0_SIM_SP)); - cicr0 |= CICR0_DMAEN | CICR0_IRQ_MASK; - __raw_writel(cicr0, pcdev->base + CICR0); -} - -static int pxa_camera_set_bus_param(struct soc_camera_device *icd) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct pxa_camera_dev *pcdev = ici->priv; - struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,}; - u32 pixfmt = icd->current_fmt->host_fmt->fourcc; - unsigned long bus_flags, common_flags; - int ret; - struct pxa_cam *cam = icd->host_priv; - - ret = test_platform_param(pcdev, icd->current_fmt->host_fmt->bits_per_sample, - &bus_flags); - if (ret < 0) - return ret; - - ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); - if (!ret) { - common_flags = soc_mbus_config_compatible(&cfg, - bus_flags); - if (!common_flags) { - dev_warn(icd->parent, - "Flags incompatible: camera 0x%x, host 0x%lx\n", - cfg.flags, bus_flags); - return -EINVAL; - } - } else if (ret != -ENOIOCTLCMD) { - return ret; - } else { - common_flags = bus_flags; - } - - pcdev->channels = 1; - - /* Make choises, based on platform preferences */ - if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) && - (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) { - if (pcdev->platform_flags & PXA_CAMERA_HSP) - common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH; - else - common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW; - } - - if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) && - (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) { - if (pcdev->platform_flags & PXA_CAMERA_VSP) - common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH; - else - common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW; - } - - if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) && - (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) { - if (pcdev->platform_flags & PXA_CAMERA_PCP) - common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING; - else - common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING; - } - - cfg.flags = common_flags; - ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg); - if (ret < 0 && ret != -ENOIOCTLCMD) { - dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n", - common_flags, ret); - return ret; - } - - cam->flags = common_flags; - - pxa_camera_setup_cicr(icd, common_flags, pixfmt); - - return 0; -} - -static int pxa_camera_try_bus_param(struct soc_camera_device *icd, - unsigned char buswidth) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct pxa_camera_dev *pcdev = ici->priv; - struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,}; - unsigned long bus_flags, common_flags; - int ret = test_platform_param(pcdev, buswidth, &bus_flags); - - if (ret < 0) - return ret; - - ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); - if (!ret) { - common_flags = soc_mbus_config_compatible(&cfg, - bus_flags); - if (!common_flags) { - dev_warn(icd->parent, - "Flags incompatible: camera 0x%x, host 0x%lx\n", - cfg.flags, bus_flags); - return -EINVAL; - } - } else if (ret == -ENOIOCTLCMD) { - ret = 0; - } - - return ret; -} - -static const struct soc_mbus_pixelfmt pxa_camera_formats[] = { - { - .fourcc = V4L2_PIX_FMT_YUV422P, - .name = "Planar YUV422 16 bit", - .bits_per_sample = 8, - .packing = SOC_MBUS_PACKING_2X8_PADHI, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PLANAR_2Y_U_V, - }, -}; - -/* This will be corrected as we get more formats */ -static bool pxa_camera_packing_supported(const struct soc_mbus_pixelfmt *fmt) -{ - return fmt->packing == SOC_MBUS_PACKING_NONE || - (fmt->bits_per_sample == 8 && - fmt->packing == SOC_MBUS_PACKING_2X8_PADHI) || - (fmt->bits_per_sample > 8 && - fmt->packing == SOC_MBUS_PACKING_EXTEND16); -} - -static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int idx, - struct soc_camera_format_xlate *xlate) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct device *dev = icd->parent; - int formats = 0, ret; - struct pxa_cam *cam; - struct v4l2_subdev_mbus_code_enum code = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - .index = idx, - }; - const struct soc_mbus_pixelfmt *fmt; - - ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code); - if (ret < 0) - /* No more formats */ - return 0; - - fmt = soc_mbus_get_fmtdesc(code.code); - if (!fmt) { - dev_err(dev, "Invalid format code #%u: %d\n", idx, code.code); - return 0; - } - - /* This also checks support for the requested bits-per-sample */ - ret = pxa_camera_try_bus_param(icd, fmt->bits_per_sample); - if (ret < 0) - return 0; - - if (!icd->host_priv) { - cam = kzalloc(sizeof(*cam), GFP_KERNEL); - if (!cam) - return -ENOMEM; - - icd->host_priv = cam; - } else { - cam = icd->host_priv; - } - - switch (code.code) { - case MEDIA_BUS_FMT_UYVY8_2X8: - formats++; - if (xlate) { - xlate->host_fmt = &pxa_camera_formats[0]; - xlate->code = code.code; - xlate++; - dev_dbg(dev, "Providing format %s using code %d\n", - pxa_camera_formats[0].name, code.code); - } - case MEDIA_BUS_FMT_VYUY8_2X8: - case MEDIA_BUS_FMT_YUYV8_2X8: - case MEDIA_BUS_FMT_YVYU8_2X8: - case MEDIA_BUS_FMT_RGB565_2X8_LE: - case MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE: - if (xlate) - dev_dbg(dev, "Providing format %s packed\n", - fmt->name); - break; - default: - if (!pxa_camera_packing_supported(fmt)) - return 0; - if (xlate) - dev_dbg(dev, - "Providing format %s in pass-through mode\n", - fmt->name); - } - - /* Generic pass-through */ - formats++; - if (xlate) { - xlate->host_fmt = fmt; - xlate->code = code.code; - xlate++; - } - - return formats; -} - -static void pxa_camera_put_formats(struct soc_camera_device *icd) -{ - kfree(icd->host_priv); - icd->host_priv = NULL; -} - -static int pxa_camera_check_frame(u32 width, u32 height) -{ - /* limit to pxa hardware capabilities */ - return height < 32 || height > 2048 || width < 48 || width > 2048 || - (width & 0x01); -} - -static int pxa_camera_set_crop(struct soc_camera_device *icd, - const struct v4l2_crop *a) -{ - const struct v4l2_rect *rect = &a->c; - struct device *dev = icd->parent; - struct soc_camera_host *ici = to_soc_camera_host(dev); - struct pxa_camera_dev *pcdev = ici->priv; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct soc_camera_sense sense = { - .master_clock = pcdev->mclk, - .pixel_clock_max = pcdev->ciclk / 4, - }; - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_mbus_framefmt *mf = &fmt.format; - struct pxa_cam *cam = icd->host_priv; - u32 fourcc = icd->current_fmt->host_fmt->fourcc; - int ret; - - /* If PCLK is used to latch data from the sensor, check sense */ - if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) - icd->sense = &sense; - - ret = v4l2_subdev_call(sd, video, s_crop, a); - - icd->sense = NULL; - - if (ret < 0) { - dev_warn(dev, "Failed to crop to %ux%u@%u:%u\n", - rect->width, rect->height, rect->left, rect->top); - return ret; - } - - ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt); - if (ret < 0) - return ret; - - if (pxa_camera_check_frame(mf->width, mf->height)) { - /* - * Camera cropping produced a frame beyond our capabilities. - * FIXME: just extract a subframe, that we can process. - */ - v4l_bound_align_image(&mf->width, 48, 2048, 1, - &mf->height, 32, 2048, 0, - fourcc == V4L2_PIX_FMT_YUV422P ? 4 : 0); - ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &fmt); - if (ret < 0) - return ret; - - if (pxa_camera_check_frame(mf->width, mf->height)) { - dev_warn(icd->parent, - "Inconsistent state. Use S_FMT to repair\n"); - return -EINVAL; - } - } - - if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { - if (sense.pixel_clock > sense.pixel_clock_max) { - dev_err(dev, - "pixel clock %lu set by the camera too high!", - sense.pixel_clock); - return -EIO; - } - recalculate_fifo_timeout(pcdev, sense.pixel_clock); - } - - icd->user_width = mf->width; - icd->user_height = mf->height; - - pxa_camera_setup_cicr(icd, cam->flags, fourcc); - - return ret; -} - -static int pxa_camera_set_fmt(struct soc_camera_device *icd, - struct v4l2_format *f) -{ - struct device *dev = icd->parent; - struct soc_camera_host *ici = to_soc_camera_host(dev); - struct pxa_camera_dev *pcdev = ici->priv; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - const struct soc_camera_format_xlate *xlate = NULL; - struct soc_camera_sense sense = { - .master_clock = pcdev->mclk, - .pixel_clock_max = pcdev->ciclk / 4, - }; - struct v4l2_pix_format *pix = &f->fmt.pix; - struct v4l2_subdev_format format = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_mbus_framefmt *mf = &format.format; - int ret; - - xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); - if (!xlate) { - dev_warn(dev, "Format %x not found\n", pix->pixelformat); - return -EINVAL; - } - - /* If PCLK is used to latch data from the sensor, check sense */ - if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) - /* The caller holds a mutex. */ - icd->sense = &sense; - - mf->width = pix->width; - mf->height = pix->height; - mf->field = pix->field; - mf->colorspace = pix->colorspace; - mf->code = xlate->code; - - ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format); - - if (mf->code != xlate->code) - return -EINVAL; - - icd->sense = NULL; - - if (ret < 0) { - dev_warn(dev, "Failed to configure for format %x\n", - pix->pixelformat); - } else if (pxa_camera_check_frame(mf->width, mf->height)) { - dev_warn(dev, - "Camera driver produced an unsupported frame %dx%d\n", - mf->width, mf->height); - ret = -EINVAL; - } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { - if (sense.pixel_clock > sense.pixel_clock_max) { - dev_err(dev, - "pixel clock %lu set by the camera too high!", - sense.pixel_clock); - return -EIO; - } - recalculate_fifo_timeout(pcdev, sense.pixel_clock); - } - - if (ret < 0) - return ret; - - pix->width = mf->width; - pix->height = mf->height; - pix->field = mf->field; - pix->colorspace = mf->colorspace; - icd->current_fmt = xlate; - - return ret; -} - -static int pxa_camera_try_fmt(struct soc_camera_device *icd, - struct v4l2_format *f) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - const struct soc_camera_format_xlate *xlate; - struct v4l2_pix_format *pix = &f->fmt.pix; - struct v4l2_subdev_pad_config pad_cfg; - struct v4l2_subdev_format format = { - .which = V4L2_SUBDEV_FORMAT_TRY, - }; - struct v4l2_mbus_framefmt *mf = &format.format; - __u32 pixfmt = pix->pixelformat; - int ret; - - xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); - if (!xlate) { - dev_warn(icd->parent, "Format %x not found\n", pixfmt); - return -EINVAL; - } - - /* - * Limit to pxa hardware capabilities. YUV422P planar format requires - * images size to be a multiple of 16 bytes. If not, zeros will be - * inserted between Y and U planes, and U and V planes, which violates - * the YUV422P standard. - */ - v4l_bound_align_image(&pix->width, 48, 2048, 1, - &pix->height, 32, 2048, 0, - pixfmt == V4L2_PIX_FMT_YUV422P ? 4 : 0); - - /* limit to sensor capabilities */ - mf->width = pix->width; - mf->height = pix->height; - /* Only progressive video supported so far */ - mf->field = V4L2_FIELD_NONE; - mf->colorspace = pix->colorspace; - mf->code = xlate->code; - - ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format); - if (ret < 0) - return ret; - - pix->width = mf->width; - pix->height = mf->height; - pix->colorspace = mf->colorspace; - - switch (mf->field) { - case V4L2_FIELD_ANY: - case V4L2_FIELD_NONE: - pix->field = V4L2_FIELD_NONE; - break; - default: - /* TODO: support interlaced at least in pass-through mode */ - dev_err(icd->parent, "Field type %d unsupported.\n", - mf->field); - return -EINVAL; - } - - return ret; -} - -static int pxa_camera_reqbufs(struct soc_camera_device *icd, - struct v4l2_requestbuffers *p) -{ - int i; - - /* - * This is for locking debugging only. I removed spinlocks and now I - * check whether .prepare is ever called on a linked buffer, or whether - * a dma IRQ can occur for an in-work or unlinked buffer. Until now - * it hadn't triggered - */ - for (i = 0; i < p->count; i++) { - struct pxa_buffer *buf = container_of(icd->vb_vidq.bufs[i], - struct pxa_buffer, vb); - buf->inwork = 0; - INIT_LIST_HEAD(&buf->vb.queue); - } - - return 0; -} - -static unsigned int pxa_camera_poll(struct file *file, poll_table *pt) -{ - struct soc_camera_device *icd = file->private_data; - struct pxa_buffer *buf; - - buf = list_entry(icd->vb_vidq.stream.next, struct pxa_buffer, - vb.stream); - - poll_wait(file, &buf->vb.done, pt); - - if (buf->vb.state == VIDEOBUF_DONE || - buf->vb.state == VIDEOBUF_ERROR) - return POLLIN|POLLRDNORM; - - return 0; -} - -static int pxa_camera_querycap(struct soc_camera_host *ici, - struct v4l2_capability *cap) -{ - /* cap->name is set by the firendly caller:-> */ - strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card)); - cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; - cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; - - return 0; -} - -static int pxa_camera_suspend(struct device *dev) -{ - struct soc_camera_host *ici = to_soc_camera_host(dev); - struct pxa_camera_dev *pcdev = ici->priv; - int i = 0, ret = 0; - - pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR0); - pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR1); - pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR2); - pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3); - pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4); - - if (pcdev->soc_host.icd) { - struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->soc_host.icd); - ret = v4l2_subdev_call(sd, core, s_power, 0); - if (ret == -ENOIOCTLCMD) - ret = 0; - } - - return ret; -} - -static int pxa_camera_resume(struct device *dev) -{ - struct soc_camera_host *ici = to_soc_camera_host(dev); - struct pxa_camera_dev *pcdev = ici->priv; - int i = 0, ret = 0; - - __raw_writel(pcdev->save_cicr[i++] & ~CICR0_ENB, pcdev->base + CICR0); - __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR1); - __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR2); - __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3); - __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4); - - if (pcdev->soc_host.icd) { - struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->soc_host.icd); - ret = v4l2_subdev_call(sd, core, s_power, 1); - if (ret == -ENOIOCTLCMD) - ret = 0; - } - - /* Restart frame capture if active buffer exists */ - if (!ret && pcdev->active) - pxa_camera_start_capture(pcdev); - - return ret; -} - -static struct soc_camera_host_ops pxa_soc_camera_host_ops = { - .owner = THIS_MODULE, - .add = pxa_camera_add_device, - .remove = pxa_camera_remove_device, - .clock_start = pxa_camera_clock_start, - .clock_stop = pxa_camera_clock_stop, - .set_crop = pxa_camera_set_crop, - .get_formats = pxa_camera_get_formats, - .put_formats = pxa_camera_put_formats, - .set_fmt = pxa_camera_set_fmt, - .try_fmt = pxa_camera_try_fmt, - .init_videobuf = pxa_camera_init_videobuf, - .reqbufs = pxa_camera_reqbufs, - .poll = pxa_camera_poll, - .querycap = pxa_camera_querycap, - .set_bus_param = pxa_camera_set_bus_param, -}; - -static int pxa_camera_pdata_from_dt(struct device *dev, - struct pxa_camera_dev *pcdev) -{ - u32 mclk_rate; - struct device_node *np = dev->of_node; - struct v4l2_of_endpoint ep; - int err = of_property_read_u32(np, "clock-frequency", - &mclk_rate); - if (!err) { - pcdev->platform_flags |= PXA_CAMERA_MCLK_EN; - pcdev->mclk = mclk_rate; - } - - np = of_graph_get_next_endpoint(np, NULL); - if (!np) { - dev_err(dev, "could not find endpoint\n"); - return -EINVAL; - } - - err = v4l2_of_parse_endpoint(np, &ep); - if (err) { - dev_err(dev, "could not parse endpoint\n"); - goto out; - } - - switch (ep.bus.parallel.bus_width) { - case 4: - pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_4; - break; - case 5: - pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_5; - break; - case 8: - pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_8; - break; - case 9: - pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_9; - break; - case 10: - pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10; - break; - default: - break; - } - - if (ep.bus.parallel.flags & V4L2_MBUS_MASTER) - pcdev->platform_flags |= PXA_CAMERA_MASTER; - if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) - pcdev->platform_flags |= PXA_CAMERA_HSP; - if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) - pcdev->platform_flags |= PXA_CAMERA_VSP; - if (ep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_RISING) - pcdev->platform_flags |= PXA_CAMERA_PCLK_EN | PXA_CAMERA_PCP; - if (ep.bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) - pcdev->platform_flags |= PXA_CAMERA_PCLK_EN; - -out: - of_node_put(np); - - return err; -} - -static int pxa_camera_probe(struct platform_device *pdev) -{ - struct pxa_camera_dev *pcdev; - struct resource *res; - void __iomem *base; - struct dma_slave_config config = { - .src_addr_width = 0, - .src_maxburst = 8, - .direction = DMA_DEV_TO_MEM, - }; - dma_cap_mask_t mask; - struct pxad_param params; - int irq; - int err = 0, i; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - irq = platform_get_irq(pdev, 0); - if (!res || irq < 0) - return -ENODEV; - - pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL); - if (!pcdev) { - dev_err(&pdev->dev, "Could not allocate pcdev\n"); - return -ENOMEM; - } - - pcdev->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(pcdev->clk)) - return PTR_ERR(pcdev->clk); - - pcdev->res = res; - - pcdev->pdata = pdev->dev.platform_data; - if (&pdev->dev.of_node && !pcdev->pdata) { - err = pxa_camera_pdata_from_dt(&pdev->dev, pcdev); - } else { - pcdev->platform_flags = pcdev->pdata->flags; - pcdev->mclk = pcdev->pdata->mclk_10khz * 10000; - } - if (err < 0) - return err; - - if (!(pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 | - PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10))) { - /* - * Platform hasn't set available data widths. This is bad. - * Warn and use a default. - */ - dev_warn(&pdev->dev, "WARNING! Platform hasn't set available " - "data widths, using default 10 bit\n"); - pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10; - } - if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8) - pcdev->width_flags = 1 << 7; - if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9) - pcdev->width_flags |= 1 << 8; - if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10) - pcdev->width_flags |= 1 << 9; - if (!pcdev->mclk) { - dev_warn(&pdev->dev, - "mclk == 0! Please, fix your platform data. " - "Using default 20MHz\n"); - pcdev->mclk = 20000000; - } - - pcdev->mclk_divisor = mclk_get_divisor(pdev, pcdev); - - INIT_LIST_HEAD(&pcdev->capture); - spin_lock_init(&pcdev->lock); - - /* - * Request the regions. - */ - base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(base)) - return PTR_ERR(base); - - pcdev->irq = irq; - pcdev->base = base; - - /* request dma */ - dma_cap_zero(mask); - dma_cap_set(DMA_SLAVE, mask); - dma_cap_set(DMA_PRIVATE, mask); - - params.prio = 0; - params.drcmr = 68; - pcdev->dma_chans[0] = - dma_request_slave_channel_compat(mask, pxad_filter_fn, - ¶ms, &pdev->dev, "CI_Y"); - if (!pcdev->dma_chans[0]) { - dev_err(&pdev->dev, "Can't request DMA for Y\n"); - return -ENODEV; - } - - params.drcmr = 69; - pcdev->dma_chans[1] = - dma_request_slave_channel_compat(mask, pxad_filter_fn, - ¶ms, &pdev->dev, "CI_U"); - if (!pcdev->dma_chans[1]) { - dev_err(&pdev->dev, "Can't request DMA for Y\n"); - goto exit_free_dma_y; - } - - params.drcmr = 70; - pcdev->dma_chans[2] = - dma_request_slave_channel_compat(mask, pxad_filter_fn, - ¶ms, &pdev->dev, "CI_V"); - if (!pcdev->dma_chans[2]) { - dev_err(&pdev->dev, "Can't request DMA for V\n"); - goto exit_free_dma_u; - } - - for (i = 0; i < 3; i++) { - config.src_addr = pcdev->res->start + CIBR0 + i * 8; - err = dmaengine_slave_config(pcdev->dma_chans[i], &config); - if (err < 0) { - dev_err(&pdev->dev, "dma slave config failed: %d\n", - err); - goto exit_free_dma; - } - } - - /* request irq */ - err = devm_request_irq(&pdev->dev, pcdev->irq, pxa_camera_irq, 0, - PXA_CAM_DRV_NAME, pcdev); - if (err) { - dev_err(&pdev->dev, "Camera interrupt register failed\n"); - goto exit_free_dma; - } - - pcdev->soc_host.drv_name = PXA_CAM_DRV_NAME; - pcdev->soc_host.ops = &pxa_soc_camera_host_ops; - pcdev->soc_host.priv = pcdev; - pcdev->soc_host.v4l2_dev.dev = &pdev->dev; - pcdev->soc_host.nr = pdev->id; - tasklet_init(&pcdev->task_eof, pxa_camera_eof, (unsigned long)pcdev); - - err = soc_camera_host_register(&pcdev->soc_host); - if (err) - goto exit_free_dma; - - return 0; - -exit_free_dma: - dma_release_channel(pcdev->dma_chans[2]); -exit_free_dma_u: - dma_release_channel(pcdev->dma_chans[1]); -exit_free_dma_y: - dma_release_channel(pcdev->dma_chans[0]); - return err; -} - -static int pxa_camera_remove(struct platform_device *pdev) -{ - struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); - struct pxa_camera_dev *pcdev = container_of(soc_host, - struct pxa_camera_dev, soc_host); - - dma_release_channel(pcdev->dma_chans[0]); - dma_release_channel(pcdev->dma_chans[1]); - dma_release_channel(pcdev->dma_chans[2]); - - soc_camera_host_unregister(soc_host); - - dev_info(&pdev->dev, "PXA Camera driver unloaded\n"); - - return 0; -} - -static const struct dev_pm_ops pxa_camera_pm = { - .suspend = pxa_camera_suspend, - .resume = pxa_camera_resume, -}; - -static const struct of_device_id pxa_camera_of_match[] = { - { .compatible = "marvell,pxa270-qci", }, - {}, -}; -MODULE_DEVICE_TABLE(of, pxa_camera_of_match); - -static struct platform_driver pxa_camera_driver = { - .driver = { - .name = PXA_CAM_DRV_NAME, - .pm = &pxa_camera_pm, - .of_match_table = of_match_ptr(pxa_camera_of_match), - }, - .probe = pxa_camera_probe, - .remove = pxa_camera_remove, -}; - -module_platform_driver(pxa_camera_driver); - -MODULE_DESCRIPTION("PXA27x SoC Camera Host driver"); -MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>"); -MODULE_LICENSE("GPL"); -MODULE_VERSION(PXA_CAM_VERSION); -MODULE_ALIAS("platform:" PXA_CAM_DRV_NAME); diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c deleted file mode 100644 index 9c137522c660..000000000000 --- a/drivers/media/platform/soc_camera/rcar_vin.c +++ /dev/null @@ -1,1970 +0,0 @@ -/* - * SoC-camera host driver for Renesas R-Car VIN unit - * - * Copyright (C) 2011-2013 Renesas Solutions Corp. - * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com> - * - * Based on V4L2 Driver for SuperH Mobile CEU interface "sh_mobile_ceu_camera.c" - * - * Copyright (C) 2008 Magnus Damm - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - */ - -#include <linux/delay.h> -#include <linux/interrupt.h> -#include <linux/io.h> -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/of.h> -#include <linux/of_device.h> -#include <linux/platform_device.h> -#include <linux/pm_runtime.h> -#include <linux/slab.h> -#include <linux/videodev2.h> - -#include <media/soc_camera.h> -#include <media/drv-intf/soc_mediabus.h> -#include <media/v4l2-common.h> -#include <media/v4l2-dev.h> -#include <media/v4l2-device.h> -#include <media/v4l2-mediabus.h> -#include <media/v4l2-of.h> -#include <media/v4l2-subdev.h> -#include <media/videobuf2-dma-contig.h> - -#include "soc_scale_crop.h" - -#define DRV_NAME "rcar_vin" - -/* Register offsets for R-Car VIN */ -#define VNMC_REG 0x00 /* Video n Main Control Register */ -#define VNMS_REG 0x04 /* Video n Module Status Register */ -#define VNFC_REG 0x08 /* Video n Frame Capture Register */ -#define VNSLPRC_REG 0x0C /* Video n Start Line Pre-Clip Register */ -#define VNELPRC_REG 0x10 /* Video n End Line Pre-Clip Register */ -#define VNSPPRC_REG 0x14 /* Video n Start Pixel Pre-Clip Register */ -#define VNEPPRC_REG 0x18 /* Video n End Pixel Pre-Clip Register */ -#define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */ -#define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */ -#define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */ -#define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */ -#define VNIS_REG 0x2C /* Video n Image Stride Register */ -#define VNMB_REG(m) (0x30 + ((m) << 2)) /* Video n Memory Base m Register */ -#define VNIE_REG 0x40 /* Video n Interrupt Enable Register */ -#define VNINTS_REG 0x44 /* Video n Interrupt Status Register */ -#define VNSI_REG 0x48 /* Video n Scanline Interrupt Register */ -#define VNMTC_REG 0x4C /* Video n Memory Transfer Control Register */ -#define VNYS_REG 0x50 /* Video n Y Scale Register */ -#define VNXS_REG 0x54 /* Video n X Scale Register */ -#define VNDMR_REG 0x58 /* Video n Data Mode Register */ -#define VNDMR2_REG 0x5C /* Video n Data Mode Register 2 */ -#define VNUVAOF_REG 0x60 /* Video n UV Address Offset Register */ -#define VNC1A_REG 0x80 /* Video n Coefficient Set C1A Register */ -#define VNC1B_REG 0x84 /* Video n Coefficient Set C1B Register */ -#define VNC1C_REG 0x88 /* Video n Coefficient Set C1C Register */ -#define VNC2A_REG 0x90 /* Video n Coefficient Set C2A Register */ -#define VNC2B_REG 0x94 /* Video n Coefficient Set C2B Register */ -#define VNC2C_REG 0x98 /* Video n Coefficient Set C2C Register */ -#define VNC3A_REG 0xA0 /* Video n Coefficient Set C3A Register */ -#define VNC3B_REG 0xA4 /* Video n Coefficient Set C3B Register */ -#define VNC3C_REG 0xA8 /* Video n Coefficient Set C3C Register */ -#define VNC4A_REG 0xB0 /* Video n Coefficient Set C4A Register */ -#define VNC4B_REG 0xB4 /* Video n Coefficient Set C4B Register */ -#define VNC4C_REG 0xB8 /* Video n Coefficient Set C4C Register */ -#define VNC5A_REG 0xC0 /* Video n Coefficient Set C5A Register */ -#define VNC5B_REG 0xC4 /* Video n Coefficient Set C5B Register */ -#define VNC5C_REG 0xC8 /* Video n Coefficient Set C5C Register */ -#define VNC6A_REG 0xD0 /* Video n Coefficient Set C6A Register */ -#define VNC6B_REG 0xD4 /* Video n Coefficient Set C6B Register */ -#define VNC6C_REG 0xD8 /* Video n Coefficient Set C6C Register */ -#define VNC7A_REG 0xE0 /* Video n Coefficient Set C7A Register */ -#define VNC7B_REG 0xE4 /* Video n Coefficient Set C7B Register */ -#define VNC7C_REG 0xE8 /* Video n Coefficient Set C7C Register */ -#define VNC8A_REG 0xF0 /* Video n Coefficient Set C8A Register */ -#define VNC8B_REG 0xF4 /* Video n Coefficient Set C8B Register */ -#define VNC8C_REG 0xF8 /* Video n Coefficient Set C8C Register */ - -/* Register bit fields for R-Car VIN */ -/* Video n Main Control Register bits */ -#define VNMC_FOC (1 << 21) -#define VNMC_YCAL (1 << 19) -#define VNMC_INF_YUV8_BT656 (0 << 16) -#define VNMC_INF_YUV8_BT601 (1 << 16) -#define VNMC_INF_YUV10_BT656 (2 << 16) -#define VNMC_INF_YUV10_BT601 (3 << 16) -#define VNMC_INF_YUV16 (5 << 16) -#define VNMC_INF_RGB888 (6 << 16) -#define VNMC_VUP (1 << 10) -#define VNMC_IM_ODD (0 << 3) -#define VNMC_IM_ODD_EVEN (1 << 3) -#define VNMC_IM_EVEN (2 << 3) -#define VNMC_IM_FULL (3 << 3) -#define VNMC_BPS (1 << 1) -#define VNMC_ME (1 << 0) - -/* Video n Module Status Register bits */ -#define VNMS_FBS_MASK (3 << 3) -#define VNMS_FBS_SHIFT 3 -#define VNMS_AV (1 << 1) -#define VNMS_CA (1 << 0) - -/* Video n Frame Capture Register bits */ -#define VNFC_C_FRAME (1 << 1) -#define VNFC_S_FRAME (1 << 0) - -/* Video n Interrupt Enable Register bits */ -#define VNIE_FIE (1 << 4) -#define VNIE_EFE (1 << 1) - -/* Video n Data Mode Register bits */ -#define VNDMR_EXRGB (1 << 8) -#define VNDMR_BPSM (1 << 4) -#define VNDMR_DTMD_YCSEP (1 << 1) -#define VNDMR_DTMD_ARGB (1 << 0) - -/* Video n Data Mode Register 2 bits */ -#define VNDMR2_VPS (1 << 30) -#define VNDMR2_HPS (1 << 29) -#define VNDMR2_FTEV (1 << 17) -#define VNDMR2_VLV(n) ((n & 0xf) << 12) - -#define VIN_MAX_WIDTH 2048 -#define VIN_MAX_HEIGHT 2048 - -#define TIMEOUT_MS 100 - -#define RCAR_VIN_HSYNC_ACTIVE_LOW (1 << 0) -#define RCAR_VIN_VSYNC_ACTIVE_LOW (1 << 1) -#define RCAR_VIN_BT601 (1 << 2) -#define RCAR_VIN_BT656 (1 << 3) - -enum chip_id { - RCAR_GEN3, - RCAR_GEN2, - RCAR_H1, - RCAR_M1, - RCAR_E1, -}; - -struct vin_coeff { - unsigned short xs_value; - u32 coeff_set[24]; -}; - -static const struct vin_coeff vin_coeff_set[] = { - { 0x0000, { - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000 }, - }, - { 0x1000, { - 0x000fa400, 0x000fa400, 0x09625902, - 0x000003f8, 0x00000403, 0x3de0d9f0, - 0x001fffed, 0x00000804, 0x3cc1f9c3, - 0x001003de, 0x00000c01, 0x3cb34d7f, - 0x002003d2, 0x00000c00, 0x3d24a92d, - 0x00200bca, 0x00000bff, 0x3df600d2, - 0x002013cc, 0x000007ff, 0x3ed70c7e, - 0x00100fde, 0x00000000, 0x3f87c036 }, - }, - { 0x1200, { - 0x002ffff1, 0x002ffff1, 0x02a0a9c8, - 0x002003e7, 0x001ffffa, 0x000185bc, - 0x002007dc, 0x000003ff, 0x3e52859c, - 0x00200bd4, 0x00000002, 0x3d53996b, - 0x00100fd0, 0x00000403, 0x3d04ad2d, - 0x00000bd5, 0x00000403, 0x3d35ace7, - 0x3ff003e4, 0x00000801, 0x3dc674a1, - 0x3fffe800, 0x00000800, 0x3e76f461 }, - }, - { 0x1400, { - 0x00100be3, 0x00100be3, 0x04d1359a, - 0x00000fdb, 0x002003ed, 0x0211fd93, - 0x00000fd6, 0x002003f4, 0x0002d97b, - 0x000007d6, 0x002ffffb, 0x3e93b956, - 0x3ff003da, 0x001003ff, 0x3db49926, - 0x3fffefe9, 0x00100001, 0x3d655cee, - 0x3fffd400, 0x00000003, 0x3d65f4b6, - 0x000fb421, 0x00000402, 0x3dc6547e }, - }, - { 0x1600, { - 0x00000bdd, 0x00000bdd, 0x06519578, - 0x3ff007da, 0x00000be3, 0x03c24973, - 0x3ff003d9, 0x00000be9, 0x01b30d5f, - 0x3ffff7df, 0x001003f1, 0x0003c542, - 0x000fdfec, 0x001003f7, 0x3ec4711d, - 0x000fc400, 0x002ffffd, 0x3df504f1, - 0x001fa81a, 0x002ffc00, 0x3d957cc2, - 0x002f8c3c, 0x00100000, 0x3db5c891 }, - }, - { 0x1800, { - 0x3ff003dc, 0x3ff003dc, 0x0791e558, - 0x000ff7dd, 0x3ff007de, 0x05328554, - 0x000fe7e3, 0x3ff00be2, 0x03232546, - 0x000fd7ee, 0x000007e9, 0x0143bd30, - 0x001fb800, 0x000007ee, 0x00044511, - 0x002fa015, 0x000007f4, 0x3ef4bcee, - 0x002f8832, 0x001003f9, 0x3e4514c7, - 0x001f7853, 0x001003fd, 0x3de54c9f }, - }, - { 0x1a00, { - 0x000fefe0, 0x000fefe0, 0x08721d3c, - 0x001fdbe7, 0x000ffbde, 0x0652a139, - 0x001fcbf0, 0x000003df, 0x0463292e, - 0x002fb3ff, 0x3ff007e3, 0x0293a91d, - 0x002f9c12, 0x3ff00be7, 0x01241905, - 0x001f8c29, 0x000007ed, 0x3fe470eb, - 0x000f7c46, 0x000007f2, 0x3f04b8ca, - 0x3fef7865, 0x000007f6, 0x3e74e4a8 }, - }, - { 0x1c00, { - 0x001fd3e9, 0x001fd3e9, 0x08f23d26, - 0x002fbff3, 0x001fe3e4, 0x0712ad23, - 0x002fa800, 0x000ff3e0, 0x05631d1b, - 0x001f9810, 0x000ffbe1, 0x03b3890d, - 0x000f8c23, 0x000003e3, 0x0233e8fa, - 0x3fef843b, 0x000003e7, 0x00f430e4, - 0x3fbf8456, 0x3ff00bea, 0x00046cc8, - 0x3f8f8c72, 0x3ff00bef, 0x3f3490ac }, - }, - { 0x1e00, { - 0x001fbbf4, 0x001fbbf4, 0x09425112, - 0x001fa800, 0x002fc7ed, 0x0792b110, - 0x000f980e, 0x001fdbe6, 0x0613110a, - 0x3fff8c20, 0x001fe7e3, 0x04a368fd, - 0x3fcf8c33, 0x000ff7e2, 0x0343b8ed, - 0x3f9f8c4a, 0x000fffe3, 0x0203f8da, - 0x3f5f9c61, 0x000003e6, 0x00e428c5, - 0x3f1fb07b, 0x000003eb, 0x3fe440af }, - }, - { 0x2000, { - 0x000fa400, 0x000fa400, 0x09625902, - 0x3fff980c, 0x001fb7f5, 0x0812b0ff, - 0x3fdf901c, 0x001fc7ed, 0x06b2fcfa, - 0x3faf902d, 0x001fd3e8, 0x055348f1, - 0x3f7f983f, 0x001fe3e5, 0x04038ce3, - 0x3f3fa454, 0x001fefe3, 0x02e3c8d1, - 0x3f0fb86a, 0x001ff7e4, 0x01c3e8c0, - 0x3ecfd880, 0x000fffe6, 0x00c404ac }, - }, - { 0x2200, { - 0x3fdf9c0b, 0x3fdf9c0b, 0x09725cf4, - 0x3fbf9818, 0x3fffa400, 0x0842a8f1, - 0x3f8f9827, 0x000fb3f7, 0x0702f0ec, - 0x3f5fa037, 0x000fc3ef, 0x05d330e4, - 0x3f2fac49, 0x001fcfea, 0x04a364d9, - 0x3effc05c, 0x001fdbe7, 0x038394ca, - 0x3ecfdc6f, 0x001fe7e6, 0x0273b0bb, - 0x3ea00083, 0x001fefe6, 0x0183c0a9 }, - }, - { 0x2400, { - 0x3f9fa014, 0x3f9fa014, 0x098260e6, - 0x3f7f9c23, 0x3fcf9c0a, 0x08629ce5, - 0x3f4fa431, 0x3fefa400, 0x0742d8e1, - 0x3f1fb440, 0x3fffb3f8, 0x062310d9, - 0x3eefc850, 0x000fbbf2, 0x050340d0, - 0x3ecfe062, 0x000fcbec, 0x041364c2, - 0x3ea00073, 0x001fd3ea, 0x03037cb5, - 0x3e902086, 0x001fdfe8, 0x022388a5 }, - }, - { 0x2600, { - 0x3f5fa81e, 0x3f5fa81e, 0x096258da, - 0x3f3fac2b, 0x3f8fa412, 0x088290d8, - 0x3f0fbc38, 0x3fafa408, 0x0772c8d5, - 0x3eefcc47, 0x3fcfa800, 0x0672f4ce, - 0x3ecfe456, 0x3fefaffa, 0x05531cc6, - 0x3eb00066, 0x3fffbbf3, 0x047334bb, - 0x3ea01c77, 0x000fc7ee, 0x039348ae, - 0x3ea04486, 0x000fd3eb, 0x02b350a1 }, - }, - { 0x2800, { - 0x3f2fb426, 0x3f2fb426, 0x094250ce, - 0x3f0fc032, 0x3f4fac1b, 0x086284cd, - 0x3eefd040, 0x3f7fa811, 0x0782acc9, - 0x3ecfe84c, 0x3f9fa807, 0x06a2d8c4, - 0x3eb0005b, 0x3fbfac00, 0x05b2f4bc, - 0x3eb0186a, 0x3fdfb3fa, 0x04c308b4, - 0x3eb04077, 0x3fefbbf4, 0x03f31ca8, - 0x3ec06884, 0x000fbff2, 0x03031c9e }, - }, - { 0x2a00, { - 0x3f0fc42d, 0x3f0fc42d, 0x090240c4, - 0x3eefd439, 0x3f2fb822, 0x08526cc2, - 0x3edfe845, 0x3f4fb018, 0x078294bf, - 0x3ec00051, 0x3f6fac0f, 0x06b2b4bb, - 0x3ec0185f, 0x3f8fac07, 0x05e2ccb4, - 0x3ec0386b, 0x3fafac00, 0x0502e8ac, - 0x3ed05c77, 0x3fcfb3fb, 0x0432f0a3, - 0x3ef08482, 0x3fdfbbf6, 0x0372f898 }, - }, - { 0x2c00, { - 0x3eefdc31, 0x3eefdc31, 0x08e238b8, - 0x3edfec3d, 0x3f0fc828, 0x082258b9, - 0x3ed00049, 0x3f1fc01e, 0x077278b6, - 0x3ed01455, 0x3f3fb815, 0x06c294b2, - 0x3ed03460, 0x3f5fb40d, 0x0602acac, - 0x3ef0506c, 0x3f7fb006, 0x0542c0a4, - 0x3f107476, 0x3f9fb400, 0x0472c89d, - 0x3f309c80, 0x3fbfb7fc, 0x03b2cc94 }, - }, - { 0x2e00, { - 0x3eefec37, 0x3eefec37, 0x088220b0, - 0x3ee00041, 0x3effdc2d, 0x07f244ae, - 0x3ee0144c, 0x3f0fd023, 0x07625cad, - 0x3ef02c57, 0x3f1fc81a, 0x06c274a9, - 0x3f004861, 0x3f3fbc13, 0x060288a6, - 0x3f20686b, 0x3f5fb80c, 0x05529c9e, - 0x3f408c74, 0x3f6fb805, 0x04b2ac96, - 0x3f80ac7e, 0x3f8fb800, 0x0402ac8e }, - }, - { 0x3000, { - 0x3ef0003a, 0x3ef0003a, 0x084210a6, - 0x3ef01045, 0x3effec32, 0x07b228a7, - 0x3f00284e, 0x3f0fdc29, 0x073244a4, - 0x3f104058, 0x3f0fd420, 0x06a258a2, - 0x3f305c62, 0x3f2fc818, 0x0612689d, - 0x3f508069, 0x3f3fc011, 0x05728496, - 0x3f80a072, 0x3f4fc00a, 0x04d28c90, - 0x3fc0c07b, 0x3f6fbc04, 0x04429088 }, - }, - { 0x3200, { - 0x3f00103e, 0x3f00103e, 0x07f1fc9e, - 0x3f102447, 0x3f000035, 0x0782149d, - 0x3f203c4f, 0x3f0ff02c, 0x07122c9c, - 0x3f405458, 0x3f0fe424, 0x06924099, - 0x3f607061, 0x3f1fd41d, 0x06024c97, - 0x3f909068, 0x3f2fcc16, 0x05726490, - 0x3fc0b070, 0x3f3fc80f, 0x04f26c8a, - 0x0000d077, 0x3f4fc409, 0x04627484 }, - }, - { 0x3400, { - 0x3f202040, 0x3f202040, 0x07a1e898, - 0x3f303449, 0x3f100c38, 0x0741fc98, - 0x3f504c50, 0x3f10002f, 0x06e21495, - 0x3f706459, 0x3f1ff028, 0x06722492, - 0x3fa08060, 0x3f1fe421, 0x05f2348f, - 0x3fd09c67, 0x3f1fdc19, 0x05824c89, - 0x0000bc6e, 0x3f2fd014, 0x04f25086, - 0x0040dc74, 0x3f3fcc0d, 0x04825c7f }, - }, - { 0x3600, { - 0x3f403042, 0x3f403042, 0x0761d890, - 0x3f504848, 0x3f301c3b, 0x0701f090, - 0x3f805c50, 0x3f200c33, 0x06a2008f, - 0x3fa07458, 0x3f10002b, 0x06520c8d, - 0x3fd0905e, 0x3f1ff424, 0x05e22089, - 0x0000ac65, 0x3f1fe81d, 0x05823483, - 0x0030cc6a, 0x3f2fdc18, 0x04f23c81, - 0x0080e871, 0x3f2fd412, 0x0482407c }, - }, - { 0x3800, { - 0x3f604043, 0x3f604043, 0x0721c88a, - 0x3f80544a, 0x3f502c3c, 0x06d1d88a, - 0x3fb06851, 0x3f301c35, 0x0681e889, - 0x3fd08456, 0x3f30082f, 0x0611fc88, - 0x00009c5d, 0x3f200027, 0x05d20884, - 0x0030b863, 0x3f2ff421, 0x05621880, - 0x0070d468, 0x3f2fe81b, 0x0502247c, - 0x00c0ec6f, 0x3f2fe015, 0x04a22877 }, - }, - { 0x3a00, { - 0x3f904c44, 0x3f904c44, 0x06e1b884, - 0x3fb0604a, 0x3f70383e, 0x0691c885, - 0x3fe07451, 0x3f502c36, 0x0661d483, - 0x00009055, 0x3f401831, 0x0601ec81, - 0x0030a85b, 0x3f300c2a, 0x05b1f480, - 0x0070c061, 0x3f300024, 0x0562047a, - 0x00b0d867, 0x3f3ff41e, 0x05020c77, - 0x00f0f46b, 0x3f2fec19, 0x04a21474 }, - }, - { 0x3c00, { - 0x3fb05c43, 0x3fb05c43, 0x06c1b07e, - 0x3fe06c4b, 0x3f902c3f, 0x0681c081, - 0x0000844f, 0x3f703838, 0x0631cc7d, - 0x00309855, 0x3f602433, 0x05d1d47e, - 0x0060b459, 0x3f50142e, 0x0581e47b, - 0x00a0c85f, 0x3f400828, 0x0531f078, - 0x00e0e064, 0x3f300021, 0x0501fc73, - 0x00b0fc6a, 0x3f3ff41d, 0x04a20873 }, - }, - { 0x3e00, { - 0x3fe06444, 0x3fe06444, 0x0681a07a, - 0x00007849, 0x3fc0503f, 0x0641b07a, - 0x0020904d, 0x3fa0403a, 0x05f1c07a, - 0x0060a453, 0x3f803034, 0x05c1c878, - 0x0090b858, 0x3f70202f, 0x0571d477, - 0x00d0d05d, 0x3f501829, 0x0531e073, - 0x0110e462, 0x3f500825, 0x04e1e471, - 0x01510065, 0x3f40001f, 0x04a1f06d }, - }, - { 0x4000, { - 0x00007044, 0x00007044, 0x06519476, - 0x00208448, 0x3fe05c3f, 0x0621a476, - 0x0050984d, 0x3fc04c3a, 0x05e1b075, - 0x0080ac52, 0x3fa03c35, 0x05a1b875, - 0x00c0c056, 0x3f803030, 0x0561c473, - 0x0100d45b, 0x3f70202b, 0x0521d46f, - 0x0140e860, 0x3f601427, 0x04d1d46e, - 0x01810064, 0x3f500822, 0x0491dc6b }, - }, - { 0x5000, { - 0x0110a442, 0x0110a442, 0x0551545e, - 0x0140b045, 0x00e0983f, 0x0531585f, - 0x0160c047, 0x00c08c3c, 0x0511645e, - 0x0190cc4a, 0x00908039, 0x04f1685f, - 0x01c0dc4c, 0x00707436, 0x04d1705e, - 0x0200e850, 0x00506833, 0x04b1785b, - 0x0230f453, 0x00305c30, 0x0491805a, - 0x02710056, 0x0010542d, 0x04718059 }, - }, - { 0x6000, { - 0x01c0bc40, 0x01c0bc40, 0x04c13052, - 0x01e0c841, 0x01a0b43d, 0x04c13851, - 0x0210cc44, 0x0180a83c, 0x04a13453, - 0x0230d845, 0x0160a03a, 0x04913c52, - 0x0260e047, 0x01409838, 0x04714052, - 0x0280ec49, 0x01208c37, 0x04514c50, - 0x02b0f44b, 0x01008435, 0x04414c50, - 0x02d1004c, 0x00e07c33, 0x0431544f }, - }, - { 0x7000, { - 0x0230c83e, 0x0230c83e, 0x04711c4c, - 0x0250d03f, 0x0210c43c, 0x0471204b, - 0x0270d840, 0x0200b83c, 0x0451244b, - 0x0290dc42, 0x01e0b43a, 0x0441244c, - 0x02b0e443, 0x01c0b038, 0x0441284b, - 0x02d0ec44, 0x01b0a438, 0x0421304a, - 0x02f0f445, 0x0190a036, 0x04213449, - 0x0310f847, 0x01709c34, 0x04213848 }, - }, - { 0x8000, { - 0x0280d03d, 0x0280d03d, 0x04310c48, - 0x02a0d43e, 0x0270c83c, 0x04311047, - 0x02b0dc3e, 0x0250c83a, 0x04311447, - 0x02d0e040, 0x0240c03a, 0x04211446, - 0x02e0e840, 0x0220bc39, 0x04111847, - 0x0300e842, 0x0210b438, 0x04012445, - 0x0310f043, 0x0200b037, 0x04012045, - 0x0330f444, 0x01e0ac36, 0x03f12445 }, - }, - { 0xefff, { - 0x0340dc3a, 0x0340dc3a, 0x03b0ec40, - 0x0340e03a, 0x0330e039, 0x03c0f03e, - 0x0350e03b, 0x0330dc39, 0x03c0ec3e, - 0x0350e43a, 0x0320dc38, 0x03c0f43e, - 0x0360e43b, 0x0320d839, 0x03b0f03e, - 0x0360e83b, 0x0310d838, 0x03c0fc3b, - 0x0370e83b, 0x0310d439, 0x03a0f83d, - 0x0370e83c, 0x0300d438, 0x03b0fc3c }, - } -}; - -enum rcar_vin_state { - STOPPED = 0, - RUNNING, - STOPPING, -}; - -struct rcar_vin_priv { - void __iomem *base; - spinlock_t lock; - int sequence; - /* State of the VIN module in capturing mode */ - enum rcar_vin_state state; - struct soc_camera_host ici; - struct list_head capture; -#define MAX_BUFFER_NUM 3 - struct vb2_v4l2_buffer *queue_buf[MAX_BUFFER_NUM]; - enum v4l2_field field; - unsigned int pdata_flags; - unsigned int vb_count; - unsigned int nr_hw_slots; - bool request_to_stop; - struct completion capture_stop; - enum chip_id chip; -}; - -#define is_continuous_transfer(priv) (priv->vb_count > MAX_BUFFER_NUM) - -struct rcar_vin_buffer { - struct vb2_v4l2_buffer vb; - struct list_head list; -}; - -#define to_buf_list(vb2_buffer) (&container_of(vb2_buffer, \ - struct rcar_vin_buffer, \ - vb)->list) - -struct rcar_vin_cam { - /* VIN offsets within the camera output, before the VIN scaler */ - unsigned int vin_left; - unsigned int vin_top; - /* Client output, as seen by the VIN */ - unsigned int width; - unsigned int height; - /* User window from S_FMT */ - unsigned int out_width; - unsigned int out_height; - /* - * User window from S_CROP / G_CROP, produced by client cropping and - * scaling, VIN scaling and VIN cropping, mapped back onto the client - * input window - */ - struct v4l2_rect subrect; - /* Camera cropping rectangle */ - struct v4l2_rect rect; - const struct soc_mbus_pixelfmt *extra_fmt; -}; - -/* - * .queue_setup() is called to check whether the driver can accept the requested - * number of buffers and to fill in plane sizes for the current frame format if - * required - */ -static int rcar_vin_videobuf_setup(struct vb2_queue *vq, - unsigned int *count, - unsigned int *num_planes, - unsigned int sizes[], struct device *alloc_devs[]) -{ - struct soc_camera_device *icd = soc_camera_from_vb2q(vq); - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - - if (!vq->num_buffers) - priv->sequence = 0; - - if (!*count) - *count = 2; - priv->vb_count = *count; - - /* Number of hardware slots */ - if (is_continuous_transfer(priv)) - priv->nr_hw_slots = MAX_BUFFER_NUM; - else - priv->nr_hw_slots = 1; - - if (*num_planes) - return sizes[0] < icd->sizeimage ? -EINVAL : 0; - - sizes[0] = icd->sizeimage; - *num_planes = 1; - - dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]); - - return 0; -} - -static int rcar_vin_setup(struct rcar_vin_priv *priv) -{ - struct soc_camera_device *icd = priv->ici.icd; - struct rcar_vin_cam *cam = icd->host_priv; - u32 vnmc, dmr, interrupts; - bool progressive = false, output_is_yuv = false, input_is_yuv = false; - - switch (priv->field) { - case V4L2_FIELD_TOP: - vnmc = VNMC_IM_ODD; - break; - case V4L2_FIELD_BOTTOM: - vnmc = VNMC_IM_EVEN; - break; - case V4L2_FIELD_INTERLACED: - case V4L2_FIELD_INTERLACED_TB: - vnmc = VNMC_IM_FULL; - break; - case V4L2_FIELD_INTERLACED_BT: - vnmc = VNMC_IM_FULL | VNMC_FOC; - break; - case V4L2_FIELD_NONE: - if (is_continuous_transfer(priv)) { - vnmc = VNMC_IM_ODD_EVEN; - progressive = true; - } else { - vnmc = VNMC_IM_ODD; - } - break; - default: - vnmc = VNMC_IM_ODD; - break; - } - - /* input interface */ - switch (icd->current_fmt->code) { - case MEDIA_BUS_FMT_YUYV8_1X16: - /* BT.601/BT.1358 16bit YCbCr422 */ - vnmc |= VNMC_INF_YUV16; - input_is_yuv = true; - break; - case MEDIA_BUS_FMT_YUYV8_2X8: - /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ - vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? - VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601; - input_is_yuv = true; - break; - case MEDIA_BUS_FMT_RGB888_1X24: - vnmc |= VNMC_INF_RGB888; - break; - case MEDIA_BUS_FMT_YUYV10_2X10: - /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ - vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? - VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601; - input_is_yuv = true; - break; - default: - break; - } - - /* output format */ - switch (icd->current_fmt->host_fmt->fourcc) { - case V4L2_PIX_FMT_NV16: - iowrite32(ALIGN(cam->width * cam->height, 0x80), - priv->base + VNUVAOF_REG); - dmr = VNDMR_DTMD_YCSEP; - output_is_yuv = true; - break; - case V4L2_PIX_FMT_YUYV: - dmr = VNDMR_BPSM; - output_is_yuv = true; - break; - case V4L2_PIX_FMT_UYVY: - dmr = 0; - output_is_yuv = true; - break; - case V4L2_PIX_FMT_RGB555X: - dmr = VNDMR_DTMD_ARGB; - break; - case V4L2_PIX_FMT_RGB565: - dmr = 0; - break; - case V4L2_PIX_FMT_RGB32: - if (priv->chip != RCAR_GEN2 && priv->chip != RCAR_H1 && - priv->chip != RCAR_E1) - goto e_format; - - dmr = VNDMR_EXRGB; - break; - case V4L2_PIX_FMT_ARGB32: - if (priv->chip != RCAR_GEN3) - goto e_format; - - dmr = VNDMR_EXRGB | VNDMR_DTMD_ARGB; - break; - default: - goto e_format; - } - - /* Always update on field change */ - vnmc |= VNMC_VUP; - - /* If input and output use the same colorspace, use bypass mode */ - if (input_is_yuv == output_is_yuv) - vnmc |= VNMC_BPS; - - /* progressive or interlaced mode */ - interrupts = progressive ? VNIE_FIE : VNIE_EFE; - - /* ack interrupts */ - iowrite32(interrupts, priv->base + VNINTS_REG); - /* enable interrupts */ - iowrite32(interrupts, priv->base + VNIE_REG); - /* start capturing */ - iowrite32(dmr, priv->base + VNDMR_REG); - iowrite32(vnmc | VNMC_ME, priv->base + VNMC_REG); - - return 0; - -e_format: - dev_warn(icd->parent, "Invalid fourcc format (0x%x)\n", - icd->current_fmt->host_fmt->fourcc); - return -EINVAL; -} - -static void rcar_vin_capture(struct rcar_vin_priv *priv) -{ - if (is_continuous_transfer(priv)) - /* Continuous Frame Capture Mode */ - iowrite32(VNFC_C_FRAME, priv->base + VNFC_REG); - else - /* Single Frame Capture Mode */ - iowrite32(VNFC_S_FRAME, priv->base + VNFC_REG); -} - -static void rcar_vin_request_capture_stop(struct rcar_vin_priv *priv) -{ - priv->state = STOPPING; - - /* set continuous & single transfer off */ - iowrite32(0, priv->base + VNFC_REG); - /* disable capture (release DMA buffer), reset */ - iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME, - priv->base + VNMC_REG); - - /* update the status if stopped already */ - if (!(ioread32(priv->base + VNMS_REG) & VNMS_CA)) - priv->state = STOPPED; -} - -static int rcar_vin_get_free_hw_slot(struct rcar_vin_priv *priv) -{ - int slot; - - for (slot = 0; slot < priv->nr_hw_slots; slot++) - if (priv->queue_buf[slot] == NULL) - return slot; - - return -1; -} - -static int rcar_vin_hw_ready(struct rcar_vin_priv *priv) -{ - /* Ensure all HW slots are filled */ - return rcar_vin_get_free_hw_slot(priv) < 0 ? 1 : 0; -} - -/* Moves a buffer from the queue to the HW slots */ -static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv) -{ - struct vb2_v4l2_buffer *vbuf; - dma_addr_t phys_addr_top; - int slot; - - if (list_empty(&priv->capture)) - return 0; - - /* Find a free HW slot */ - slot = rcar_vin_get_free_hw_slot(priv); - if (slot < 0) - return 0; - - vbuf = &list_entry(priv->capture.next, - struct rcar_vin_buffer, list)->vb; - list_del_init(to_buf_list(vbuf)); - priv->queue_buf[slot] = vbuf; - phys_addr_top = vb2_dma_contig_plane_dma_addr(&vbuf->vb2_buf, 0); - iowrite32(phys_addr_top, priv->base + VNMB_REG(slot)); - - return 1; -} - -static void rcar_vin_videobuf_queue(struct vb2_buffer *vb) -{ - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); - struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - unsigned long size; - - size = icd->sizeimage; - - if (vb2_plane_size(vb, 0) < size) { - dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n", - vb->index, vb2_plane_size(vb, 0), size); - goto error; - } - - vb2_set_plane_payload(vb, 0, size); - - dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__, - vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0)); - - spin_lock_irq(&priv->lock); - - list_add_tail(to_buf_list(vbuf), &priv->capture); - rcar_vin_fill_hw_slot(priv); - - /* If we weren't running, and have enough buffers, start capturing! */ - if (priv->state != RUNNING && rcar_vin_hw_ready(priv)) { - if (rcar_vin_setup(priv)) { - /* Submit error */ - list_del_init(to_buf_list(vbuf)); - spin_unlock_irq(&priv->lock); - goto error; - } - priv->request_to_stop = false; - init_completion(&priv->capture_stop); - priv->state = RUNNING; - rcar_vin_capture(priv); - } - - spin_unlock_irq(&priv->lock); - - return; - -error: - vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); -} - -/* - * Wait for capture to stop and all in-flight buffers to be finished with by - * the video hardware. This must be called under &priv->lock - * - */ -static void rcar_vin_wait_stop_streaming(struct rcar_vin_priv *priv) -{ - while (priv->state != STOPPED) { - /* issue stop if running */ - if (priv->state == RUNNING) - rcar_vin_request_capture_stop(priv); - - /* wait until capturing has been stopped */ - if (priv->state == STOPPING) { - priv->request_to_stop = true; - spin_unlock_irq(&priv->lock); - if (!wait_for_completion_timeout( - &priv->capture_stop, - msecs_to_jiffies(TIMEOUT_MS))) - priv->state = STOPPED; - spin_lock_irq(&priv->lock); - } - } -} - -static void rcar_vin_stop_streaming(struct vb2_queue *vq) -{ - struct soc_camera_device *icd = soc_camera_from_vb2q(vq); - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - struct list_head *buf_head, *tmp; - int i; - - spin_lock_irq(&priv->lock); - rcar_vin_wait_stop_streaming(priv); - - for (i = 0; i < MAX_BUFFER_NUM; i++) { - if (priv->queue_buf[i]) { - vb2_buffer_done(&priv->queue_buf[i]->vb2_buf, - VB2_BUF_STATE_ERROR); - priv->queue_buf[i] = NULL; - } - } - - list_for_each_safe(buf_head, tmp, &priv->capture) { - vb2_buffer_done(&list_entry(buf_head, - struct rcar_vin_buffer, list)->vb.vb2_buf, - VB2_BUF_STATE_ERROR); - list_del_init(buf_head); - } - spin_unlock_irq(&priv->lock); -} - -static struct vb2_ops rcar_vin_vb2_ops = { - .queue_setup = rcar_vin_videobuf_setup, - .buf_queue = rcar_vin_videobuf_queue, - .stop_streaming = rcar_vin_stop_streaming, - .wait_prepare = vb2_ops_wait_prepare, - .wait_finish = vb2_ops_wait_finish, -}; - -static irqreturn_t rcar_vin_irq(int irq, void *data) -{ - struct rcar_vin_priv *priv = data; - u32 int_status; - bool can_run = false, hw_stopped; - int slot; - unsigned int handled = 0; - - spin_lock(&priv->lock); - - int_status = ioread32(priv->base + VNINTS_REG); - if (!int_status) - goto done; - /* ack interrupts */ - iowrite32(int_status, priv->base + VNINTS_REG); - handled = 1; - - /* nothing to do if capture status is 'STOPPED' */ - if (priv->state == STOPPED) - goto done; - - hw_stopped = !(ioread32(priv->base + VNMS_REG) & VNMS_CA); - - if (!priv->request_to_stop) { - if (is_continuous_transfer(priv)) - slot = (ioread32(priv->base + VNMS_REG) & - VNMS_FBS_MASK) >> VNMS_FBS_SHIFT; - else - slot = 0; - - priv->queue_buf[slot]->field = priv->field; - priv->queue_buf[slot]->sequence = priv->sequence++; - priv->queue_buf[slot]->vb2_buf.timestamp = ktime_get_ns(); - vb2_buffer_done(&priv->queue_buf[slot]->vb2_buf, - VB2_BUF_STATE_DONE); - priv->queue_buf[slot] = NULL; - - if (priv->state != STOPPING) - can_run = rcar_vin_fill_hw_slot(priv); - - if (hw_stopped || !can_run) { - priv->state = STOPPED; - } else if (is_continuous_transfer(priv) && - list_empty(&priv->capture) && - priv->state == RUNNING) { - /* - * The continuous capturing requires an explicit stop - * operation when there is no buffer to be set into - * the VnMBm registers. - */ - rcar_vin_request_capture_stop(priv); - } else { - rcar_vin_capture(priv); - } - - } else if (hw_stopped) { - priv->state = STOPPED; - priv->request_to_stop = false; - complete(&priv->capture_stop); - } - -done: - spin_unlock(&priv->lock); - - return IRQ_RETVAL(handled); -} - -static int rcar_vin_add_device(struct soc_camera_device *icd) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - int i; - - for (i = 0; i < MAX_BUFFER_NUM; i++) - priv->queue_buf[i] = NULL; - - pm_runtime_get_sync(ici->v4l2_dev.dev); - - dev_dbg(icd->parent, "R-Car VIN driver attached to camera %d\n", - icd->devnum); - - return 0; -} - -static void rcar_vin_remove_device(struct soc_camera_device *icd) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - struct vb2_v4l2_buffer *vbuf; - int i; - - /* disable capture, disable interrupts */ - iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME, - priv->base + VNMC_REG); - iowrite32(0, priv->base + VNIE_REG); - - priv->state = STOPPED; - priv->request_to_stop = false; - - /* make sure active buffer is cancelled */ - spin_lock_irq(&priv->lock); - for (i = 0; i < MAX_BUFFER_NUM; i++) { - vbuf = priv->queue_buf[i]; - if (vbuf) { - list_del_init(to_buf_list(vbuf)); - vb2_buffer_done(&vbuf->vb2_buf, VB2_BUF_STATE_ERROR); - } - } - spin_unlock_irq(&priv->lock); - - pm_runtime_put(ici->v4l2_dev.dev); - - dev_dbg(icd->parent, "R-Car VIN driver detached from camera %d\n", - icd->devnum); -} - -static void set_coeff(struct rcar_vin_priv *priv, unsigned short xs) -{ - int i; - const struct vin_coeff *p_prev_set = NULL; - const struct vin_coeff *p_set = NULL; - - /* Look for suitable coefficient values */ - for (i = 0; i < ARRAY_SIZE(vin_coeff_set); i++) { - p_prev_set = p_set; - p_set = &vin_coeff_set[i]; - - if (xs < p_set->xs_value) - break; - } - - /* Use previous value if its XS value is closer */ - if (p_prev_set && p_set && - xs - p_prev_set->xs_value < p_set->xs_value - xs) - p_set = p_prev_set; - - /* Set coefficient registers */ - iowrite32(p_set->coeff_set[0], priv->base + VNC1A_REG); - iowrite32(p_set->coeff_set[1], priv->base + VNC1B_REG); - iowrite32(p_set->coeff_set[2], priv->base + VNC1C_REG); - - iowrite32(p_set->coeff_set[3], priv->base + VNC2A_REG); - iowrite32(p_set->coeff_set[4], priv->base + VNC2B_REG); - iowrite32(p_set->coeff_set[5], priv->base + VNC2C_REG); - - iowrite32(p_set->coeff_set[6], priv->base + VNC3A_REG); - iowrite32(p_set->coeff_set[7], priv->base + VNC3B_REG); - iowrite32(p_set->coeff_set[8], priv->base + VNC3C_REG); - - iowrite32(p_set->coeff_set[9], priv->base + VNC4A_REG); - iowrite32(p_set->coeff_set[10], priv->base + VNC4B_REG); - iowrite32(p_set->coeff_set[11], priv->base + VNC4C_REG); - - iowrite32(p_set->coeff_set[12], priv->base + VNC5A_REG); - iowrite32(p_set->coeff_set[13], priv->base + VNC5B_REG); - iowrite32(p_set->coeff_set[14], priv->base + VNC5C_REG); - - iowrite32(p_set->coeff_set[15], priv->base + VNC6A_REG); - iowrite32(p_set->coeff_set[16], priv->base + VNC6B_REG); - iowrite32(p_set->coeff_set[17], priv->base + VNC6C_REG); - - iowrite32(p_set->coeff_set[18], priv->base + VNC7A_REG); - iowrite32(p_set->coeff_set[19], priv->base + VNC7B_REG); - iowrite32(p_set->coeff_set[20], priv->base + VNC7C_REG); - - iowrite32(p_set->coeff_set[21], priv->base + VNC8A_REG); - iowrite32(p_set->coeff_set[22], priv->base + VNC8B_REG); - iowrite32(p_set->coeff_set[23], priv->base + VNC8C_REG); -} - -/* rect is guaranteed to not exceed the scaled camera rectangle */ -static int rcar_vin_set_rect(struct soc_camera_device *icd) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_cam *cam = icd->host_priv; - struct rcar_vin_priv *priv = ici->priv; - unsigned int left_offset, top_offset; - unsigned char dsize = 0; - struct v4l2_rect *cam_subrect = &cam->subrect; - u32 value; - - dev_dbg(icd->parent, "Crop %ux%u@%u:%u\n", - icd->user_width, icd->user_height, cam->vin_left, cam->vin_top); - - left_offset = cam->vin_left; - top_offset = cam->vin_top; - - if (icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_RGB32 && - priv->chip == RCAR_E1) - dsize = 1; - - dev_dbg(icd->parent, "Cam %ux%u@%u:%u\n", - cam->width, cam->height, cam->vin_left, cam->vin_top); - dev_dbg(icd->parent, "Cam subrect %ux%u@%u:%u\n", - cam_subrect->width, cam_subrect->height, - cam_subrect->left, cam_subrect->top); - - /* Set Start/End Pixel/Line Pre-Clip */ - iowrite32(left_offset << dsize, priv->base + VNSPPRC_REG); - iowrite32((left_offset + cam_subrect->width - 1) << dsize, - priv->base + VNEPPRC_REG); - switch (priv->field) { - case V4L2_FIELD_INTERLACED: - case V4L2_FIELD_INTERLACED_TB: - case V4L2_FIELD_INTERLACED_BT: - iowrite32(top_offset / 2, priv->base + VNSLPRC_REG); - iowrite32((top_offset + cam_subrect->height) / 2 - 1, - priv->base + VNELPRC_REG); - break; - default: - iowrite32(top_offset, priv->base + VNSLPRC_REG); - iowrite32(top_offset + cam_subrect->height - 1, - priv->base + VNELPRC_REG); - break; - } - - /* Set scaling coefficient */ - value = 0; - if (cam_subrect->height != cam->out_height) - value = (4096 * cam_subrect->height) / cam->out_height; - dev_dbg(icd->parent, "YS Value: %x\n", value); - iowrite32(value, priv->base + VNYS_REG); - - value = 0; - if (cam_subrect->width != cam->out_width) - value = (4096 * cam_subrect->width) / cam->out_width; - - /* Horizontal upscaling is up to double size */ - if (0 < value && value < 2048) - value = 2048; - - dev_dbg(icd->parent, "XS Value: %x\n", value); - iowrite32(value, priv->base + VNXS_REG); - - /* Horizontal upscaling is carried out by scaling down from double size */ - if (value < 4096) - value *= 2; - - set_coeff(priv, value); - - /* Set Start/End Pixel/Line Post-Clip */ - iowrite32(0, priv->base + VNSPPOC_REG); - iowrite32(0, priv->base + VNSLPOC_REG); - iowrite32((cam->out_width - 1) << dsize, priv->base + VNEPPOC_REG); - switch (priv->field) { - case V4L2_FIELD_INTERLACED: - case V4L2_FIELD_INTERLACED_TB: - case V4L2_FIELD_INTERLACED_BT: - iowrite32(cam->out_height / 2 - 1, - priv->base + VNELPOC_REG); - break; - default: - iowrite32(cam->out_height - 1, priv->base + VNELPOC_REG); - break; - } - - iowrite32(ALIGN(cam->out_width, 0x10), priv->base + VNIS_REG); - - return 0; -} - -static void capture_stop_preserve(struct rcar_vin_priv *priv, u32 *vnmc) -{ - *vnmc = ioread32(priv->base + VNMC_REG); - /* module disable */ - iowrite32(*vnmc & ~VNMC_ME, priv->base + VNMC_REG); -} - -static void capture_restore(struct rcar_vin_priv *priv, u32 vnmc) -{ - unsigned long timeout = jiffies + 10 * HZ; - - /* - * Wait until the end of the current frame. It can take a long time, - * but if it has been aborted by a MRST1 reset, it should exit sooner. - */ - while ((ioread32(priv->base + VNMS_REG) & VNMS_AV) && - time_before(jiffies, timeout)) - msleep(1); - - if (time_after(jiffies, timeout)) { - dev_err(priv->ici.v4l2_dev.dev, - "Timeout waiting for frame end! Interface problem?\n"); - return; - } - - iowrite32(vnmc, priv->base + VNMC_REG); -} - -#define VIN_MBUS_FLAGS (V4L2_MBUS_MASTER | \ - V4L2_MBUS_PCLK_SAMPLE_RISING | \ - V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ - V4L2_MBUS_HSYNC_ACTIVE_LOW | \ - V4L2_MBUS_VSYNC_ACTIVE_HIGH | \ - V4L2_MBUS_VSYNC_ACTIVE_LOW | \ - V4L2_MBUS_DATA_ACTIVE_HIGH) - -static int rcar_vin_set_bus_param(struct soc_camera_device *icd) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct v4l2_mbus_config cfg; - unsigned long common_flags; - u32 vnmc; - u32 val; - int ret; - - capture_stop_preserve(priv, &vnmc); - - ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); - if (!ret) { - common_flags = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS); - if (!common_flags) { - dev_warn(icd->parent, - "MBUS flags incompatible: camera 0x%x, host 0x%x\n", - cfg.flags, VIN_MBUS_FLAGS); - return -EINVAL; - } - } else if (ret != -ENOIOCTLCMD) { - return ret; - } else { - common_flags = VIN_MBUS_FLAGS; - } - - /* Make choises, based on platform preferences */ - if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) && - (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) { - if (priv->pdata_flags & RCAR_VIN_HSYNC_ACTIVE_LOW) - common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH; - else - common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW; - } - - if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) && - (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) { - if (priv->pdata_flags & RCAR_VIN_VSYNC_ACTIVE_LOW) - common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH; - else - common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW; - } - - cfg.flags = common_flags; - ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg); - if (ret < 0 && ret != -ENOIOCTLCMD) - return ret; - - val = VNDMR2_FTEV | VNDMR2_VLV(1); - if (!(common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) - val |= VNDMR2_VPS; - if (!(common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) - val |= VNDMR2_HPS; - iowrite32(val, priv->base + VNDMR2_REG); - - ret = rcar_vin_set_rect(icd); - if (ret < 0) - return ret; - - capture_restore(priv, vnmc); - - return 0; -} - -static int rcar_vin_try_bus_param(struct soc_camera_device *icd, - unsigned char buswidth) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct v4l2_mbus_config cfg; - int ret; - - ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); - if (ret == -ENOIOCTLCMD) - return 0; - else if (ret) - return ret; - - if (buswidth > 24) - return -EINVAL; - - /* check is there common mbus flags */ - ret = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS); - if (ret) - return 0; - - dev_warn(icd->parent, - "MBUS flags incompatible: camera 0x%x, host 0x%x\n", - cfg.flags, VIN_MBUS_FLAGS); - - return -EINVAL; -} - -static bool rcar_vin_packing_supported(const struct soc_mbus_pixelfmt *fmt) -{ - return fmt->packing == SOC_MBUS_PACKING_NONE || - (fmt->bits_per_sample > 8 && - fmt->packing == SOC_MBUS_PACKING_EXTEND16); -} - -static const struct soc_mbus_pixelfmt rcar_vin_formats[] = { - { - .fourcc = V4L2_PIX_FMT_NV16, - .name = "NV16", - .bits_per_sample = 8, - .packing = SOC_MBUS_PACKING_2X8_PADHI, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PLANAR_Y_C, - }, - { - .fourcc = V4L2_PIX_FMT_YUYV, - .name = "YUYV", - .bits_per_sample = 16, - .packing = SOC_MBUS_PACKING_NONE, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PACKED, - }, - { - .fourcc = V4L2_PIX_FMT_UYVY, - .name = "UYVY", - .bits_per_sample = 16, - .packing = SOC_MBUS_PACKING_NONE, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PACKED, - }, - { - .fourcc = V4L2_PIX_FMT_RGB565, - .name = "RGB565", - .bits_per_sample = 16, - .packing = SOC_MBUS_PACKING_NONE, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PACKED, - }, - { - .fourcc = V4L2_PIX_FMT_RGB555X, - .name = "ARGB1555", - .bits_per_sample = 16, - .packing = SOC_MBUS_PACKING_NONE, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PACKED, - }, - { - .fourcc = V4L2_PIX_FMT_RGB32, - .name = "RGB888", - .bits_per_sample = 32, - .packing = SOC_MBUS_PACKING_NONE, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PACKED, - }, - { - .fourcc = V4L2_PIX_FMT_ARGB32, - .name = "ARGB8888", - .bits_per_sample = 32, - .packing = SOC_MBUS_PACKING_NONE, - .order = SOC_MBUS_ORDER_LE, - .layout = SOC_MBUS_LAYOUT_PACKED, - }, -}; - -static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx, - struct soc_camera_format_xlate *xlate) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct device *dev = icd->parent; - int ret, k, n; - int formats = 0; - struct rcar_vin_cam *cam; - struct v4l2_subdev_mbus_code_enum code = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - .index = idx, - }; - const struct soc_mbus_pixelfmt *fmt; - - ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code); - if (ret < 0) - return 0; - - fmt = soc_mbus_get_fmtdesc(code.code); - if (!fmt) { - dev_warn(dev, "unsupported format code #%u: %d\n", idx, code.code); - return 0; - } - - ret = rcar_vin_try_bus_param(icd, fmt->bits_per_sample); - if (ret < 0) - return 0; - - if (!icd->host_priv) { - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_mbus_framefmt *mf = &fmt.format; - struct v4l2_rect rect; - struct device *dev = icd->parent; - int shift; - - ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt); - if (ret < 0) - return ret; - - /* Cache current client geometry */ - ret = soc_camera_client_g_rect(sd, &rect); - if (ret == -ENOIOCTLCMD) { - /* Sensor driver doesn't support cropping */ - rect.left = 0; - rect.top = 0; - rect.width = mf->width; - rect.height = mf->height; - } else if (ret < 0) { - return ret; - } - - /* - * If sensor proposes too large format then try smaller ones: - * 1280x960, 640x480, 320x240 - */ - for (shift = 0; shift < 3; shift++) { - if (mf->width <= VIN_MAX_WIDTH && - mf->height <= VIN_MAX_HEIGHT) - break; - - mf->width = 1280 >> shift; - mf->height = 960 >> shift; - ret = v4l2_device_call_until_err(sd->v4l2_dev, - soc_camera_grp_id(icd), - pad, set_fmt, NULL, - &fmt); - if (ret < 0) - return ret; - } - - if (shift == 3) { - dev_err(dev, - "Failed to configure the client below %ux%u\n", - mf->width, mf->height); - return -EIO; - } - - dev_dbg(dev, "camera fmt %ux%u\n", mf->width, mf->height); - - cam = kzalloc(sizeof(*cam), GFP_KERNEL); - if (!cam) - return -ENOMEM; - /* - * We are called with current camera crop, - * initialise subrect with it - */ - cam->rect = rect; - cam->subrect = rect; - cam->width = mf->width; - cam->height = mf->height; - cam->out_width = mf->width; - cam->out_height = mf->height; - - icd->host_priv = cam; - } else { - cam = icd->host_priv; - } - - /* Beginning of a pass */ - if (!idx) - cam->extra_fmt = NULL; - - switch (code.code) { - case MEDIA_BUS_FMT_YUYV8_1X16: - case MEDIA_BUS_FMT_YUYV8_2X8: - case MEDIA_BUS_FMT_YUYV10_2X10: - case MEDIA_BUS_FMT_RGB888_1X24: - if (cam->extra_fmt) - break; - - /* Add all our formats that can be generated by VIN */ - cam->extra_fmt = rcar_vin_formats; - - n = ARRAY_SIZE(rcar_vin_formats); - formats += n; - for (k = 0; xlate && k < n; k++, xlate++) { - xlate->host_fmt = &rcar_vin_formats[k]; - xlate->code = code.code; - dev_dbg(dev, "Providing format %s using code %d\n", - rcar_vin_formats[k].name, code.code); - } - break; - default: - if (!rcar_vin_packing_supported(fmt)) - return 0; - - dev_dbg(dev, "Providing format %s in pass-through mode\n", - fmt->name); - break; - } - - /* Generic pass-through */ - formats++; - if (xlate) { - xlate->host_fmt = fmt; - xlate->code = code.code; - xlate++; - } - - return formats; -} - -static void rcar_vin_put_formats(struct soc_camera_device *icd) -{ - kfree(icd->host_priv); - icd->host_priv = NULL; -} - -static int rcar_vin_set_crop(struct soc_camera_device *icd, - const struct v4l2_crop *a) -{ - struct v4l2_crop a_writable = *a; - const struct v4l2_rect *rect = &a_writable.c; - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - struct v4l2_crop cam_crop; - struct rcar_vin_cam *cam = icd->host_priv; - struct v4l2_rect *cam_rect = &cam_crop.c; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct device *dev = icd->parent; - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_mbus_framefmt *mf = &fmt.format; - u32 vnmc; - int ret, i; - - dev_dbg(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height, - rect->left, rect->top); - - /* During camera cropping its output window can change too, stop VIN */ - capture_stop_preserve(priv, &vnmc); - dev_dbg(dev, "VNMC_REG 0x%x\n", vnmc); - - /* Apply iterative camera S_CROP for new input window. */ - ret = soc_camera_client_s_crop(sd, &a_writable, &cam_crop, - &cam->rect, &cam->subrect); - if (ret < 0) - return ret; - - dev_dbg(dev, "camera cropped to %ux%u@%u:%u\n", - cam_rect->width, cam_rect->height, - cam_rect->left, cam_rect->top); - - /* On success cam_crop contains current camera crop */ - - /* Retrieve camera output window */ - ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt); - if (ret < 0) - return ret; - - if (mf->width > VIN_MAX_WIDTH || mf->height > VIN_MAX_HEIGHT) - return -EINVAL; - - /* Cache camera output window */ - cam->width = mf->width; - cam->height = mf->height; - - icd->user_width = cam->width; - icd->user_height = cam->height; - - cam->vin_left = rect->left & ~1; - cam->vin_top = rect->top & ~1; - - /* Use VIN cropping to crop to the new window. */ - ret = rcar_vin_set_rect(icd); - if (ret < 0) - return ret; - - cam->subrect = *rect; - - dev_dbg(dev, "VIN cropped to %ux%u@%u:%u\n", - icd->user_width, icd->user_height, - cam->vin_left, cam->vin_top); - - /* Restore capture */ - for (i = 0; i < MAX_BUFFER_NUM; i++) { - if (priv->queue_buf[i] && priv->state == STOPPED) { - vnmc |= VNMC_ME; - break; - } - } - capture_restore(priv, vnmc); - - /* Even if only camera cropping succeeded */ - return ret; -} - -static int rcar_vin_get_crop(struct soc_camera_device *icd, - struct v4l2_crop *a) -{ - struct rcar_vin_cam *cam = icd->host_priv; - - a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - a->c = cam->subrect; - - return 0; -} - -/* Similar to set_crop multistage iterative algorithm */ -static int rcar_vin_set_fmt(struct soc_camera_device *icd, - struct v4l2_format *f) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct rcar_vin_priv *priv = ici->priv; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct rcar_vin_cam *cam = icd->host_priv; - struct v4l2_pix_format *pix = &f->fmt.pix; - struct v4l2_mbus_framefmt mf; - struct device *dev = icd->parent; - __u32 pixfmt = pix->pixelformat; - const struct soc_camera_format_xlate *xlate; - unsigned int vin_sub_width = 0, vin_sub_height = 0; - int ret; - bool can_scale; - enum v4l2_field field; - v4l2_std_id std; - - dev_dbg(dev, "S_FMT(pix=0x%x, %ux%u)\n", - pixfmt, pix->width, pix->height); - - switch (pix->field) { - default: - pix->field = V4L2_FIELD_NONE; - /* fall-through */ - case V4L2_FIELD_NONE: - case V4L2_FIELD_TOP: - case V4L2_FIELD_BOTTOM: - case V4L2_FIELD_INTERLACED_TB: - case V4L2_FIELD_INTERLACED_BT: - field = pix->field; - break; - case V4L2_FIELD_INTERLACED: - /* Query for standard if not explicitly mentioned _TB/_BT */ - ret = v4l2_subdev_call(sd, video, querystd, &std); - if (ret == -ENOIOCTLCMD) { - field = V4L2_FIELD_NONE; - } else if (ret < 0) { - return ret; - } else { - field = std & V4L2_STD_625_50 ? - V4L2_FIELD_INTERLACED_TB : - V4L2_FIELD_INTERLACED_BT; - } - break; - } - - xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); - if (!xlate) { - dev_warn(dev, "Format %x not found\n", pixfmt); - return -EINVAL; - } - /* Calculate client output geometry */ - soc_camera_calc_client_output(icd, &cam->rect, &cam->subrect, pix, &mf, - 12); - mf.field = pix->field; - mf.colorspace = pix->colorspace; - mf.code = xlate->code; - - switch (pixfmt) { - case V4L2_PIX_FMT_RGB32: - can_scale = priv->chip != RCAR_E1; - break; - case V4L2_PIX_FMT_ARGB32: - case V4L2_PIX_FMT_UYVY: - case V4L2_PIX_FMT_YUYV: - case V4L2_PIX_FMT_RGB565: - case V4L2_PIX_FMT_RGB555X: - can_scale = true; - break; - default: - can_scale = false; - break; - } - - dev_dbg(dev, "request camera output %ux%u\n", mf.width, mf.height); - - ret = soc_camera_client_scale(icd, &cam->rect, &cam->subrect, - &mf, &vin_sub_width, &vin_sub_height, - can_scale, 12); - - /* Done with the camera. Now see if we can improve the result */ - dev_dbg(dev, "Camera %d fmt %ux%u, requested %ux%u\n", - ret, mf.width, mf.height, pix->width, pix->height); - - if (ret == -ENOIOCTLCMD) - dev_dbg(dev, "Sensor doesn't support scaling\n"); - else if (ret < 0) - return ret; - - if (mf.code != xlate->code) - return -EINVAL; - - /* Prepare VIN crop */ - cam->width = mf.width; - cam->height = mf.height; - - /* Use VIN scaling to scale to the requested user window. */ - - /* We cannot scale up */ - if (pix->width > vin_sub_width) - vin_sub_width = pix->width; - - if (pix->height > vin_sub_height) - vin_sub_height = pix->height; - - pix->colorspace = mf.colorspace; - - if (!can_scale) { - pix->width = vin_sub_width; - pix->height = vin_sub_height; - } - - /* - * We have calculated CFLCR, the actual configuration will be performed - * in rcar_vin_set_bus_param() - */ - - dev_dbg(dev, "W: %u : %u, H: %u : %u\n", - vin_sub_width, pix->width, vin_sub_height, pix->height); - - cam->out_width = pix->width; - cam->out_height = pix->height; - - icd->current_fmt = xlate; - - priv->field = field; - - return 0; -} - -static int rcar_vin_try_fmt(struct soc_camera_device *icd, - struct v4l2_format *f) -{ - const struct soc_camera_format_xlate *xlate; - struct v4l2_pix_format *pix = &f->fmt.pix; - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - struct v4l2_subdev_pad_config pad_cfg; - struct v4l2_subdev_format format = { - .which = V4L2_SUBDEV_FORMAT_TRY, - }; - struct v4l2_mbus_framefmt *mf = &format.format; - __u32 pixfmt = pix->pixelformat; - int width, height; - int ret; - - xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); - if (!xlate) { - xlate = icd->current_fmt; - dev_dbg(icd->parent, "Format %x not found, keeping %x\n", - pixfmt, xlate->host_fmt->fourcc); - pixfmt = xlate->host_fmt->fourcc; - pix->pixelformat = pixfmt; - pix->colorspace = icd->colorspace; - } - - /* FIXME: calculate using depth and bus width */ - v4l_bound_align_image(&pix->width, 2, VIN_MAX_WIDTH, 1, - &pix->height, 4, VIN_MAX_HEIGHT, 2, 0); - - width = pix->width; - height = pix->height; - - /* let soc-camera calculate these values */ - pix->bytesperline = 0; - pix->sizeimage = 0; - - /* limit to sensor capabilities */ - mf->width = pix->width; - mf->height = pix->height; - mf->field = pix->field; - mf->code = xlate->code; - mf->colorspace = pix->colorspace; - - ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd), - pad, set_fmt, &pad_cfg, &format); - if (ret < 0) - return ret; - - /* Adjust only if VIN cannot scale */ - if (pix->width > mf->width * 2) - pix->width = mf->width * 2; - if (pix->height > mf->height * 3) - pix->height = mf->height * 3; - - pix->field = mf->field; - pix->colorspace = mf->colorspace; - - if (pixfmt == V4L2_PIX_FMT_NV16) { - /* FIXME: check against rect_max after converting soc-camera */ - /* We can scale precisely, need a bigger image from camera */ - if (pix->width < width || pix->height < height) { - /* - * We presume, the sensor behaves sanely, i.e. if - * requested a bigger rectangle, it will not return a - * smaller one. - */ - mf->width = VIN_MAX_WIDTH; - mf->height = VIN_MAX_HEIGHT; - ret = v4l2_device_call_until_err(sd->v4l2_dev, - soc_camera_grp_id(icd), - pad, set_fmt, &pad_cfg, - &format); - if (ret < 0) { - dev_err(icd->parent, - "client try_fmt() = %d\n", ret); - return ret; - } - } - /* We will scale exactly */ - if (mf->width > width) - pix->width = width; - if (mf->height > height) - pix->height = height; - } - - return ret; -} - -static unsigned int rcar_vin_poll(struct file *file, poll_table *pt) -{ - struct soc_camera_device *icd = file->private_data; - - return vb2_poll(&icd->vb2_vidq, file, pt); -} - -static int rcar_vin_querycap(struct soc_camera_host *ici, - struct v4l2_capability *cap) -{ - strlcpy(cap->card, "R_Car_VIN", sizeof(cap->card)); - cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; - cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; - snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s%d", DRV_NAME, ici->nr); - - return 0; -} - -static int rcar_vin_init_videobuf2(struct vb2_queue *vq, - struct soc_camera_device *icd) -{ - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - - vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - vq->io_modes = VB2_MMAP | VB2_USERPTR; - vq->drv_priv = icd; - vq->ops = &rcar_vin_vb2_ops; - vq->mem_ops = &vb2_dma_contig_memops; - vq->buf_struct_size = sizeof(struct rcar_vin_buffer); - vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; - vq->lock = &ici->host_lock; - vq->dev = ici->v4l2_dev.dev; - - return vb2_queue_init(vq); -} - -static struct soc_camera_host_ops rcar_vin_host_ops = { - .owner = THIS_MODULE, - .add = rcar_vin_add_device, - .remove = rcar_vin_remove_device, - .get_formats = rcar_vin_get_formats, - .put_formats = rcar_vin_put_formats, - .get_crop = rcar_vin_get_crop, - .set_crop = rcar_vin_set_crop, - .try_fmt = rcar_vin_try_fmt, - .set_fmt = rcar_vin_set_fmt, - .poll = rcar_vin_poll, - .querycap = rcar_vin_querycap, - .set_bus_param = rcar_vin_set_bus_param, - .init_videobuf2 = rcar_vin_init_videobuf2, -}; - -#ifdef CONFIG_OF -static const struct of_device_id rcar_vin_of_table[] = { - { .compatible = "renesas,vin-r8a7795", .data = (void *)RCAR_GEN3 }, - { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 }, - { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 }, - { .compatible = "renesas,rcar-gen3-vin", .data = (void *)RCAR_GEN3 }, - { .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 }, - { }, -}; -MODULE_DEVICE_TABLE(of, rcar_vin_of_table); -#endif - -static int rcar_vin_probe(struct platform_device *pdev) -{ - const struct of_device_id *match = NULL; - struct rcar_vin_priv *priv; - struct v4l2_of_endpoint ep; - struct device_node *np; - struct resource *mem; - unsigned int pdata_flags; - int irq, ret; - - match = of_match_device(of_match_ptr(rcar_vin_of_table), &pdev->dev); - - np = of_graph_get_next_endpoint(pdev->dev.of_node, NULL); - if (!np) { - dev_err(&pdev->dev, "could not find endpoint\n"); - return -EINVAL; - } - - ret = v4l2_of_parse_endpoint(np, &ep); - if (ret) { - dev_err(&pdev->dev, "could not parse endpoint\n"); - return ret; - } - - if (ep.bus_type == V4L2_MBUS_BT656) - pdata_flags = RCAR_VIN_BT656; - else { - pdata_flags = 0; - if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) - pdata_flags |= RCAR_VIN_HSYNC_ACTIVE_LOW; - if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) - pdata_flags |= RCAR_VIN_VSYNC_ACTIVE_LOW; - } - - of_node_put(np); - - dev_dbg(&pdev->dev, "pdata_flags = %08x\n", pdata_flags); - - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (mem == NULL) - return -EINVAL; - - irq = platform_get_irq(pdev, 0); - if (irq <= 0) - return -EINVAL; - - priv = devm_kzalloc(&pdev->dev, sizeof(struct rcar_vin_priv), - GFP_KERNEL); - if (!priv) - return -ENOMEM; - - priv->base = devm_ioremap_resource(&pdev->dev, mem); - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); - - ret = devm_request_irq(&pdev->dev, irq, rcar_vin_irq, IRQF_SHARED, - dev_name(&pdev->dev), priv); - if (ret) - return ret; - - priv->ici.priv = priv; - priv->ici.v4l2_dev.dev = &pdev->dev; - priv->ici.drv_name = dev_name(&pdev->dev); - priv->ici.ops = &rcar_vin_host_ops; - - priv->pdata_flags = pdata_flags; - if (!match) { - priv->ici.nr = pdev->id; - priv->chip = pdev->id_entry->driver_data; - } else { - priv->ici.nr = of_alias_get_id(pdev->dev.of_node, "vin"); - priv->chip = (enum chip_id)match->data; - } - - spin_lock_init(&priv->lock); - INIT_LIST_HEAD(&priv->capture); - - priv->state = STOPPED; - - pm_suspend_ignore_children(&pdev->dev, true); - pm_runtime_enable(&pdev->dev); - - ret = soc_camera_host_register(&priv->ici); - if (ret) - goto cleanup; - - return 0; - -cleanup: - pm_runtime_disable(&pdev->dev); - - return ret; -} - -static int rcar_vin_remove(struct platform_device *pdev) -{ - struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); - - soc_camera_host_unregister(soc_host); - pm_runtime_disable(&pdev->dev); - - return 0; -} - -static struct platform_driver rcar_vin_driver = { - .probe = rcar_vin_probe, - .remove = rcar_vin_remove, - .driver = { - .name = DRV_NAME, - .of_match_table = of_match_ptr(rcar_vin_of_table), - }, -}; - -module_platform_driver(rcar_vin_driver); - -MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:rcar_vin"); -MODULE_DESCRIPTION("Renesas R-Car VIN camera host driver"); diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c index 02b519dde42a..a15bfb5aea47 100644 --- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c +++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c @@ -41,7 +41,6 @@ #include <media/v4l2-dev.h> #include <media/soc_camera.h> #include <media/drv-intf/sh_mobile_ceu.h> -#include <media/drv-intf/sh_mobile_csi2.h> #include <media/videobuf2-dma-contig.h> #include <media/v4l2-mediabus.h> #include <media/drv-intf/soc_mediabus.h> @@ -99,11 +98,6 @@ struct sh_mobile_ceu_buffer { struct sh_mobile_ceu_dev { struct soc_camera_host ici; - /* Asynchronous CSI2 linking */ - struct v4l2_async_subdev *csi2_asd; - struct v4l2_subdev *csi2_sd; - /* Synchronous probing compatibility */ - struct platform_device *csi2_pdev; unsigned int irq; void __iomem *base; @@ -140,7 +134,7 @@ struct sh_mobile_ceu_cam { unsigned int width; unsigned int height; /* - * User window from S_CROP / G_CROP, produced by client cropping and + * User window from S_SELECTION / G_SELECTION, produced by client cropping and * scaling, CEU scaling and CEU cropping, mapped back onto the client * input window */ @@ -470,7 +464,7 @@ static void sh_mobile_ceu_stop_streaming(struct vb2_queue *q) sh_mobile_ceu_soft_reset(pcdev); } -static struct vb2_ops sh_mobile_ceu_videobuf_ops = { +static const struct vb2_ops sh_mobile_ceu_videobuf_ops = { .queue_setup = sh_mobile_ceu_videobuf_setup, .buf_prepare = sh_mobile_ceu_videobuf_prepare, .buf_queue = sh_mobile_ceu_videobuf_queue, @@ -517,74 +511,20 @@ out: return IRQ_HANDLED; } -static struct v4l2_subdev *find_csi2(struct sh_mobile_ceu_dev *pcdev) -{ - struct v4l2_subdev *sd; - - if (pcdev->csi2_sd) - return pcdev->csi2_sd; - - if (pcdev->csi2_asd) { - char name[] = "sh-mobile-csi2"; - v4l2_device_for_each_subdev(sd, &pcdev->ici.v4l2_dev) - if (!strncmp(name, sd->name, sizeof(name) - 1)) { - pcdev->csi2_sd = sd; - return sd; - } - } - - return NULL; -} - -static struct v4l2_subdev *csi2_subdev(struct sh_mobile_ceu_dev *pcdev, - struct soc_camera_device *icd) -{ - struct v4l2_subdev *sd = pcdev->csi2_sd; - - return sd && sd->grp_id == soc_camera_grp_id(icd) ? sd : NULL; -} - static int sh_mobile_ceu_add_device(struct soc_camera_device *icd) { - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct sh_mobile_ceu_dev *pcdev = ici->priv; - struct v4l2_subdev *csi2_sd = find_csi2(pcdev); - int ret; - - if (csi2_sd) { - csi2_sd->grp_id = soc_camera_grp_id(icd); - v4l2_set_subdev_hostdata(csi2_sd, icd); - } - - ret = v4l2_subdev_call(csi2_sd, core, s_power, 1); - if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) - return ret; - - /* - * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver - * has not found this soc-camera device among its clients - */ - if (csi2_sd && ret == -ENODEV) - csi2_sd->grp_id = 0; - dev_info(icd->parent, - "SuperH Mobile CEU%s driver attached to camera %d\n", - csi2_sd && csi2_sd->grp_id ? "/CSI-2" : "", icd->devnum); + "SuperH Mobile CEU driver attached to camera %d\n", + icd->devnum); return 0; } static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd) { - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct sh_mobile_ceu_dev *pcdev = ici->priv; - struct v4l2_subdev *csi2_sd = find_csi2(pcdev); - dev_info(icd->parent, "SuperH Mobile CEU driver detached from camera %d\n", icd->devnum); - - v4l2_subdev_call(csi2_sd, core, s_power, 0); } /* Called with .host_lock held */ @@ -704,12 +644,6 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd) cdwdr_width *= 2; } - /* CSI2 special configuration */ - if (csi2_subdev(pcdev, icd)) { - in_width = ((in_width - 2) * 2); - left_offset *= 2; - } - /* Set CAMOR, CAPWR, CFSZR, take care of CDWDR */ camor = left_offset | (top_offset << 16); @@ -758,13 +692,6 @@ static void capture_restore(struct sh_mobile_ceu_dev *pcdev, u32 capsr) ceu_write(pcdev, CAPSR, capsr); } -/* Find the bus subdevice driver, e.g., CSI2 */ -static struct v4l2_subdev *find_bus_subdev(struct sh_mobile_ceu_dev *pcdev, - struct soc_camera_device *icd) -{ - return csi2_subdev(pcdev, icd) ? : soc_camera_to_subdev(icd); -} - #define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \ V4L2_MBUS_PCLK_SAMPLE_RISING | \ V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ @@ -778,7 +705,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd) { struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct sh_mobile_ceu_dev *pcdev = ici->priv; - struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd); + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); struct sh_mobile_ceu_cam *cam = icd->host_priv; struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,}; unsigned long value, common_flags = CEU_BUS_FLAGS; @@ -866,9 +793,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd) value |= common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0; value |= common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0; - if (csi2_subdev(pcdev, icd)) /* CSI2 mode */ - value |= 3 << 12; - else if (pcdev->is_16bit) + if (pcdev->is_16bit) value |= 1 << 12; else if (pcdev->flags & SH_CEU_FLAG_LOWER_8BIT) value |= 2 << 12; @@ -923,9 +848,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd) static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd, unsigned char buswidth) { - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - struct sh_mobile_ceu_dev *pcdev = ici->priv; - struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd); + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); unsigned long common_flags = CEU_BUS_FLAGS; struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,}; int ret; @@ -1046,12 +969,9 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int return 0; } - if (!csi2_subdev(pcdev, icd)) { - /* Are there any restrictions in the CSI-2 case? */ - ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample); - if (ret < 0) - return 0; - } + ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample); + if (ret < 0) + return 0; if (!icd->host_priv) { struct v4l2_subdev_format fmt = { @@ -1189,17 +1109,16 @@ static void sh_mobile_ceu_put_formats(struct soc_camera_device *icd) * Documentation/video4linux/sh_mobile_ceu_camera.txt for a description of * scaling and cropping algorithms and for the meaning of referenced here steps. */ -static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, - const struct v4l2_crop *a) +static int sh_mobile_ceu_set_selection(struct soc_camera_device *icd, + struct v4l2_selection *sel) { - struct v4l2_crop a_writable = *a; - const struct v4l2_rect *rect = &a_writable.c; + struct v4l2_rect *rect = &sel->r; struct device *dev = icd->parent; struct soc_camera_host *ici = to_soc_camera_host(dev); struct sh_mobile_ceu_dev *pcdev = ici->priv; - struct v4l2_crop cam_crop; + struct v4l2_selection cam_sel; struct sh_mobile_ceu_cam *cam = icd->host_priv; - struct v4l2_rect *cam_rect = &cam_crop.c; + struct v4l2_rect *cam_rect = &cam_sel.r; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); struct v4l2_subdev_format fmt = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, @@ -1211,7 +1130,7 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, u32 capsr, cflcr; int ret; - dev_geo(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height, + dev_geo(dev, "S_SELECTION(%ux%u@%u:%u)\n", rect->width, rect->height, rect->left, rect->top); /* During camera cropping its output window can change too, stop CEU */ @@ -1219,10 +1138,10 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr); /* - * 1. - 2. Apply iterative camera S_CROP for new input window, read back + * 1. - 2. Apply iterative camera S_SELECTION for new input window, read back * actual camera rectangle. */ - ret = soc_camera_client_s_crop(sd, &a_writable, &cam_crop, + ret = soc_camera_client_s_selection(sd, sel, &cam_sel, &cam->rect, &cam->subrect); if (ret < 0) return ret; @@ -1331,13 +1250,12 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, return ret; } -static int sh_mobile_ceu_get_crop(struct soc_camera_device *icd, - struct v4l2_crop *a) +static int sh_mobile_ceu_get_selection(struct soc_camera_device *icd, + struct v4l2_selection *sel) { struct sh_mobile_ceu_cam *cam = icd->host_priv; - a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - a->c = cam->subrect; + sel->r = cam->subrect; return 0; } @@ -1579,8 +1497,8 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd, return ret; } -static int sh_mobile_ceu_set_livecrop(struct soc_camera_device *icd, - const struct v4l2_crop *a) +static int sh_mobile_ceu_set_liveselection(struct soc_camera_device *icd, + struct v4l2_selection *sel) { struct v4l2_subdev *sd = soc_camera_to_subdev(icd); struct soc_camera_host *ici = to_soc_camera_host(icd->parent); @@ -1599,7 +1517,7 @@ static int sh_mobile_ceu_set_livecrop(struct soc_camera_device *icd, "Client failed to stop the stream: %d\n", ret); else /* Do the crop, if it fails, there's nothing more we can do */ - sh_mobile_ceu_set_crop(icd, a); + sh_mobile_ceu_set_selection(icd, sel); dev_geo(icd->parent, "Output after crop: %ux%u\n", icd->user_width, icd->user_height); @@ -1680,9 +1598,9 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = { .clock_stop = sh_mobile_ceu_clock_stop, .get_formats = sh_mobile_ceu_get_formats, .put_formats = sh_mobile_ceu_put_formats, - .get_crop = sh_mobile_ceu_get_crop, - .set_crop = sh_mobile_ceu_set_crop, - .set_livecrop = sh_mobile_ceu_set_livecrop, + .get_selection = sh_mobile_ceu_get_selection, + .set_selection = sh_mobile_ceu_set_selection, + .set_liveselection = sh_mobile_ceu_set_liveselection, .set_fmt = sh_mobile_ceu_set_fmt, .try_fmt = sh_mobile_ceu_try_fmt, .poll = sh_mobile_ceu_poll, @@ -1721,12 +1639,11 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev) struct resource *res; void __iomem *base; unsigned int irq; - int err, i; + int err; struct bus_wait wait = { .completion = COMPLETION_INITIALIZER_ONSTACK(wait.completion), .notifier.notifier_call = bus_notify, }; - struct sh_mobile_ceu_companion *csi2; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); irq = platform_get_irq(pdev, 0); @@ -1821,132 +1738,16 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev) pcdev->ici.capabilities = SOCAM_HOST_CAP_STRIDE; if (pcdev->pdata && pcdev->pdata->asd_sizes) { - struct v4l2_async_subdev **asd; - char name[] = "sh-mobile-csi2"; - int j; - - /* - * CSI2 interfacing: several groups can use CSI2, pick up the - * first one - */ - asd = pcdev->pdata->asd; - for (j = 0; pcdev->pdata->asd_sizes[j]; j++) { - for (i = 0; i < pcdev->pdata->asd_sizes[j]; i++, asd++) { - dev_dbg(&pdev->dev, "%s(): subdev #%d, type %u\n", - __func__, i, (*asd)->match_type); - if ((*asd)->match_type == V4L2_ASYNC_MATCH_DEVNAME && - !strncmp(name, (*asd)->match.device_name.name, - sizeof(name) - 1)) { - pcdev->csi2_asd = *asd; - break; - } - } - if (pcdev->csi2_asd) - break; - } - pcdev->ici.asd = pcdev->pdata->asd; pcdev->ici.asd_sizes = pcdev->pdata->asd_sizes; } - /* Legacy CSI2 interfacing */ - csi2 = pcdev->pdata ? pcdev->pdata->csi2 : NULL; - if (csi2) { - /* - * TODO: remove this once all users are converted to - * asynchronous CSI2 probing. If it has to be kept, csi2 - * platform device resources have to be added, using - * platform_device_add_resources() - */ - struct platform_device *csi2_pdev = - platform_device_alloc("sh-mobile-csi2", csi2->id); - struct sh_csi2_pdata *csi2_pdata = csi2->platform_data; - - if (!csi2_pdev) { - err = -ENOMEM; - goto exit_free_clk; - } - - pcdev->csi2_pdev = csi2_pdev; - - err = platform_device_add_data(csi2_pdev, csi2_pdata, - sizeof(*csi2_pdata)); - if (err < 0) - goto exit_pdev_put; - - csi2_pdev->resource = csi2->resource; - csi2_pdev->num_resources = csi2->num_resources; - - err = platform_device_add(csi2_pdev); - if (err < 0) - goto exit_pdev_put; - - wait.dev = &csi2_pdev->dev; - - err = bus_register_notifier(&platform_bus_type, &wait.notifier); - if (err < 0) - goto exit_pdev_unregister; - - /* - * From this point the driver module will not unload, until - * we complete the completion. - */ - - if (!csi2_pdev->dev.driver) { - complete(&wait.completion); - /* Either too late, or probing failed */ - bus_unregister_notifier(&platform_bus_type, &wait.notifier); - err = -ENXIO; - goto exit_pdev_unregister; - } - - /* - * The module is still loaded, in the worst case it is hanging - * in device release on our completion. So, _now_ dereferencing - * the "owner" is safe! - */ - - err = try_module_get(csi2_pdev->dev.driver->owner); - - /* Let notifier complete, if it has been locked */ - complete(&wait.completion); - bus_unregister_notifier(&platform_bus_type, &wait.notifier); - if (!err) { - err = -ENODEV; - goto exit_pdev_unregister; - } - - pcdev->csi2_sd = platform_get_drvdata(csi2_pdev); - } - err = soc_camera_host_register(&pcdev->ici); if (err) - goto exit_csi2_unregister; - - if (csi2) { - err = v4l2_device_register_subdev(&pcdev->ici.v4l2_dev, - pcdev->csi2_sd); - dev_dbg(&pdev->dev, "%s(): ret(register_subdev) = %d\n", - __func__, err); - if (err < 0) - goto exit_host_unregister; - /* v4l2_device_register_subdev() took a reference too */ - module_put(pcdev->csi2_sd->owner); - } + goto exit_free_clk; return 0; -exit_host_unregister: - soc_camera_host_unregister(&pcdev->ici); -exit_csi2_unregister: - if (csi2) { - module_put(pcdev->csi2_pdev->dev.driver->owner); -exit_pdev_unregister: - platform_device_del(pcdev->csi2_pdev); -exit_pdev_put: - pcdev->csi2_pdev->resource = NULL; - platform_device_put(pcdev->csi2_pdev); - } exit_free_clk: pm_runtime_disable(&pdev->dev); exit_release_mem: @@ -1958,21 +1759,11 @@ exit_release_mem: static int sh_mobile_ceu_remove(struct platform_device *pdev) { struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); - struct sh_mobile_ceu_dev *pcdev = container_of(soc_host, - struct sh_mobile_ceu_dev, ici); - struct platform_device *csi2_pdev = pcdev->csi2_pdev; soc_camera_host_unregister(soc_host); pm_runtime_disable(&pdev->dev); if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) dma_release_declared_memory(&pdev->dev); - if (csi2_pdev && csi2_pdev->dev.driver) { - struct module *csi2_drv = csi2_pdev->dev.driver->owner; - platform_device_del(csi2_pdev); - csi2_pdev->resource = NULL; - platform_device_put(csi2_pdev); - module_put(csi2_drv); - } return 0; } @@ -2012,8 +1803,6 @@ static struct platform_driver sh_mobile_ceu_driver = { static int __init sh_mobile_ceu_init(void) { - /* Whatever return code */ - request_module("sh_mobile_csi2"); return platform_driver_register(&sh_mobile_ceu_driver); } diff --git a/drivers/media/platform/soc_camera/sh_mobile_csi2.c b/drivers/media/platform/soc_camera/sh_mobile_csi2.c deleted file mode 100644 index 09b18365a4b1..000000000000 --- a/drivers/media/platform/soc_camera/sh_mobile_csi2.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Driver for the SH-Mobile MIPI CSI-2 unit - * - * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include <linux/delay.h> -#include <linux/err.h> -#include <linux/i2c.h> -#include <linux/io.h> -#include <linux/platform_device.h> -#include <linux/pm_runtime.h> -#include <linux/slab.h> -#include <linux/videodev2.h> -#include <linux/module.h> - -#include <media/drv-intf/sh_mobile_ceu.h> -#include <media/drv-intf/sh_mobile_csi2.h> -#include <media/soc_camera.h> -#include <media/drv-intf/soc_mediabus.h> -#include <media/v4l2-common.h> -#include <media/v4l2-dev.h> -#include <media/v4l2-device.h> -#include <media/v4l2-mediabus.h> -#include <media/v4l2-subdev.h> - -#define SH_CSI2_TREF 0x00 -#define SH_CSI2_SRST 0x04 -#define SH_CSI2_PHYCNT 0x08 -#define SH_CSI2_CHKSUM 0x0C -#define SH_CSI2_VCDT 0x10 - -struct sh_csi2 { - struct v4l2_subdev subdev; - unsigned int irq; - unsigned long mipi_flags; - void __iomem *base; - struct platform_device *pdev; - struct sh_csi2_client_config *client; -}; - -static void sh_csi2_hwinit(struct sh_csi2 *priv); - -static int sh_csi2_set_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *format) -{ - struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev); - struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data; - struct v4l2_mbus_framefmt *mf = &format->format; - u32 tmp = (priv->client->channel & 3) << 8; - - if (format->pad) - return -EINVAL; - - if (mf->width > 8188) - mf->width = 8188; - else if (mf->width & 1) - mf->width &= ~1; - - switch (pdata->type) { - case SH_CSI2C: - switch (mf->code) { - case MEDIA_BUS_FMT_UYVY8_2X8: /* YUV422 */ - case MEDIA_BUS_FMT_YUYV8_1_5X8: /* YUV420 */ - case MEDIA_BUS_FMT_Y8_1X8: /* RAW8 */ - case MEDIA_BUS_FMT_SBGGR8_1X8: - case MEDIA_BUS_FMT_SGRBG8_1X8: - break; - default: - /* All MIPI CSI-2 devices must support one of primary formats */ - mf->code = MEDIA_BUS_FMT_YUYV8_2X8; - } - break; - case SH_CSI2I: - switch (mf->code) { - case MEDIA_BUS_FMT_Y8_1X8: /* RAW8 */ - case MEDIA_BUS_FMT_SBGGR8_1X8: - case MEDIA_BUS_FMT_SGRBG8_1X8: - case MEDIA_BUS_FMT_SBGGR10_1X10: /* RAW10 */ - case MEDIA_BUS_FMT_SBGGR12_1X12: /* RAW12 */ - break; - default: - /* All MIPI CSI-2 devices must support one of primary formats */ - mf->code = MEDIA_BUS_FMT_SBGGR8_1X8; - } - break; - } - - if (format->which == V4L2_SUBDEV_FORMAT_TRY) { - cfg->try_fmt = *mf; - return 0; - } - - if (mf->width > 8188 || mf->width & 1) - return -EINVAL; - - switch (mf->code) { - case MEDIA_BUS_FMT_UYVY8_2X8: - tmp |= 0x1e; /* YUV422 8 bit */ - break; - case MEDIA_BUS_FMT_YUYV8_1_5X8: - tmp |= 0x18; /* YUV420 8 bit */ - break; - case MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE: - tmp |= 0x21; /* RGB555 */ - break; - case MEDIA_BUS_FMT_RGB565_2X8_BE: - tmp |= 0x22; /* RGB565 */ - break; - case MEDIA_BUS_FMT_Y8_1X8: - case MEDIA_BUS_FMT_SBGGR8_1X8: - case MEDIA_BUS_FMT_SGRBG8_1X8: - tmp |= 0x2a; /* RAW8 */ - break; - default: - return -EINVAL; - } - - iowrite32(tmp, priv->base + SH_CSI2_VCDT); - - return 0; -} - -static int sh_csi2_g_mbus_config(struct v4l2_subdev *sd, - struct v4l2_mbus_config *cfg) -{ - struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev); - - if (!priv->mipi_flags) { - struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd); - struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd); - struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data; - unsigned long common_flags, csi2_flags; - struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2,}; - int ret; - - /* Check if we can support this camera */ - csi2_flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK | - V4L2_MBUS_CSI2_1_LANE; - - switch (pdata->type) { - case SH_CSI2C: - if (priv->client->lanes != 1) - csi2_flags |= V4L2_MBUS_CSI2_2_LANE; - break; - case SH_CSI2I: - switch (priv->client->lanes) { - default: - csi2_flags |= V4L2_MBUS_CSI2_4_LANE; - case 3: - csi2_flags |= V4L2_MBUS_CSI2_3_LANE; - case 2: - csi2_flags |= V4L2_MBUS_CSI2_2_LANE; - } - } - - ret = v4l2_subdev_call(client_sd, video, g_mbus_config, &client_cfg); - if (ret == -ENOIOCTLCMD) - common_flags = csi2_flags; - else if (!ret) - common_flags = soc_mbus_config_compatible(&client_cfg, - csi2_flags); - else - common_flags = 0; - - if (!common_flags) - return -EINVAL; - - /* All good: camera MIPI configuration supported */ - priv->mipi_flags = common_flags; - } - - if (cfg) { - cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | - V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | - V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH; - cfg->type = V4L2_MBUS_PARALLEL; - } - - return 0; -} - -static int sh_csi2_s_mbus_config(struct v4l2_subdev *sd, - const struct v4l2_mbus_config *cfg) -{ - struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev); - struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd); - struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd); - struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2,}; - int ret = sh_csi2_g_mbus_config(sd, NULL); - - if (ret < 0) - return ret; - - pm_runtime_get_sync(&priv->pdev->dev); - - sh_csi2_hwinit(priv); - - client_cfg.flags = priv->mipi_flags; - - return v4l2_subdev_call(client_sd, video, s_mbus_config, &client_cfg); -} - -static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = { - .g_mbus_config = sh_csi2_g_mbus_config, - .s_mbus_config = sh_csi2_s_mbus_config, -}; - -static struct v4l2_subdev_pad_ops sh_csi2_subdev_pad_ops = { - .set_fmt = sh_csi2_set_fmt, -}; - -static void sh_csi2_hwinit(struct sh_csi2 *priv) -{ - struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data; - __u32 tmp = 0x10; /* Enable MIPI CSI clock lane */ - - /* Reflect registers immediately */ - iowrite32(0x00000001, priv->base + SH_CSI2_TREF); - /* reset CSI2 harware */ - iowrite32(0x00000001, priv->base + SH_CSI2_SRST); - udelay(5); - iowrite32(0x00000000, priv->base + SH_CSI2_SRST); - - switch (pdata->type) { - case SH_CSI2C: - if (priv->client->lanes == 1) - tmp |= 1; - else - /* Default - both lanes */ - tmp |= 3; - break; - case SH_CSI2I: - if (!priv->client->lanes || priv->client->lanes > 4) - /* Default - all 4 lanes */ - tmp |= 0xf; - else - tmp |= (1 << priv->client->lanes) - 1; - } - - if (priv->client->phy == SH_CSI2_PHY_MAIN) - tmp |= 0x8000; - - iowrite32(tmp, priv->base + SH_CSI2_PHYCNT); - - tmp = 0; - if (pdata->flags & SH_CSI2_ECC) - tmp |= 2; - if (pdata->flags & SH_CSI2_CRC) - tmp |= 1; - iowrite32(tmp, priv->base + SH_CSI2_CHKSUM); -} - -static int sh_csi2_client_connect(struct sh_csi2 *priv) -{ - struct device *dev = v4l2_get_subdevdata(&priv->subdev); - struct sh_csi2_pdata *pdata = dev->platform_data; - struct soc_camera_device *icd = v4l2_get_subdev_hostdata(&priv->subdev); - int i; - - if (priv->client) - return -EBUSY; - - for (i = 0; i < pdata->num_clients; i++) - if ((pdata->clients[i].pdev && - &pdata->clients[i].pdev->dev == icd->pdev) || - (icd->control && - strcmp(pdata->clients[i].name, dev_name(icd->control)))) - break; - - dev_dbg(dev, "%s(%p): found #%d\n", __func__, dev, i); - - if (i == pdata->num_clients) - return -ENODEV; - - priv->client = pdata->clients + i; - - return 0; -} - -static void sh_csi2_client_disconnect(struct sh_csi2 *priv) -{ - if (!priv->client) - return; - - priv->client = NULL; - - pm_runtime_put(v4l2_get_subdevdata(&priv->subdev)); -} - -static int sh_csi2_s_power(struct v4l2_subdev *sd, int on) -{ - struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev); - - if (on) - return sh_csi2_client_connect(priv); - - sh_csi2_client_disconnect(priv); - return 0; -} - -static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops = { - .s_power = sh_csi2_s_power, -}; - -static struct v4l2_subdev_ops sh_csi2_subdev_ops = { - .core = &sh_csi2_subdev_core_ops, - .video = &sh_csi2_subdev_video_ops, - .pad = &sh_csi2_subdev_pad_ops, -}; - -static int sh_csi2_probe(struct platform_device *pdev) -{ - struct resource *res; - unsigned int irq; - int ret; - struct sh_csi2 *priv; - /* Platform data specify the PHY, lanes, ECC, CRC */ - struct sh_csi2_pdata *pdata = pdev->dev.platform_data; - - if (!pdata) - return -EINVAL; - - priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_csi2), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - /* Interrupt unused so far */ - irq = platform_get_irq(pdev, 0); - - if (!res || (int)irq <= 0) { - dev_err(&pdev->dev, "Not enough CSI2 platform resources.\n"); - return -ENODEV; - } - - /* TODO: Add support for CSI2I. Careful: different register layout! */ - if (pdata->type != SH_CSI2C) { - dev_err(&pdev->dev, "Only CSI2C supported ATM.\n"); - return -EINVAL; - } - - priv->irq = irq; - - priv->base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(priv->base)) - return PTR_ERR(priv->base); - - priv->pdev = pdev; - priv->subdev.owner = THIS_MODULE; - priv->subdev.dev = &pdev->dev; - platform_set_drvdata(pdev, &priv->subdev); - - v4l2_subdev_init(&priv->subdev, &sh_csi2_subdev_ops); - v4l2_set_subdevdata(&priv->subdev, &pdev->dev); - - snprintf(priv->subdev.name, V4L2_SUBDEV_NAME_SIZE, "%s.mipi-csi", - dev_name(&pdev->dev)); - - ret = v4l2_async_register_subdev(&priv->subdev); - if (ret < 0) - return ret; - - pm_runtime_enable(&pdev->dev); - - dev_dbg(&pdev->dev, "CSI2 probed.\n"); - - return 0; -} - -static int sh_csi2_remove(struct platform_device *pdev) -{ - struct v4l2_subdev *subdev = platform_get_drvdata(pdev); - struct sh_csi2 *priv = container_of(subdev, struct sh_csi2, subdev); - - v4l2_async_unregister_subdev(&priv->subdev); - pm_runtime_disable(&pdev->dev); - - return 0; -} - -static struct platform_driver __refdata sh_csi2_pdrv = { - .remove = sh_csi2_remove, - .probe = sh_csi2_probe, - .driver = { - .name = "sh-mobile-csi2", - }, -}; - -module_platform_driver(sh_csi2_pdrv); - -MODULE_DESCRIPTION("SH-Mobile MIPI CSI-2 driver"); -MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>"); -MODULE_LICENSE("GPL v2"); -MODULE_ALIAS("platform:sh-mobile-csi2"); diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c index 46c7186f7867..edd1c1de4e33 100644 --- a/drivers/media/platform/soc_camera/soc_camera.c +++ b/drivers/media/platform/soc_camera/soc_camera.c @@ -581,7 +581,7 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd, dev_dbg(icd->pdev, "S_FMT(%c%c%c%c, %ux%u)\n", pixfmtstr(pix->pixelformat), pix->width, pix->height); - /* We always call try_fmt() before set_fmt() or set_crop() */ + /* We always call try_fmt() before set_fmt() or set_selection() */ ret = soc_camera_try_fmt(icd, f); if (ret < 0) return ret; @@ -1025,72 +1025,6 @@ static int soc_camera_streamoff(struct file *file, void *priv, return ret; } -static int soc_camera_cropcap(struct file *file, void *fh, - struct v4l2_cropcap *a) -{ - struct soc_camera_device *icd = file->private_data; - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - - return ici->ops->cropcap(icd, a); -} - -static int soc_camera_g_crop(struct file *file, void *fh, - struct v4l2_crop *a) -{ - struct soc_camera_device *icd = file->private_data; - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - int ret; - - ret = ici->ops->get_crop(icd, a); - - return ret; -} - -/* - * According to the V4L2 API, drivers shall not update the struct v4l2_crop - * argument with the actual geometry, instead, the user shall use G_CROP to - * retrieve it. - */ -static int soc_camera_s_crop(struct file *file, void *fh, - const struct v4l2_crop *a) -{ - struct soc_camera_device *icd = file->private_data; - struct soc_camera_host *ici = to_soc_camera_host(icd->parent); - const struct v4l2_rect *rect = &a->c; - struct v4l2_crop current_crop; - int ret; - - if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) - return -EINVAL; - - dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n", - rect->width, rect->height, rect->left, rect->top); - - current_crop.type = a->type; - - /* If get_crop fails, we'll let host and / or client drivers decide */ - ret = ici->ops->get_crop(icd, ¤t_crop); - - /* Prohibit window size change with initialised buffers */ - if (ret < 0) { - dev_err(icd->pdev, - "S_CROP denied: getting current crop failed\n"); - } else if ((a->c.width == current_crop.c.width && - a->c.height == current_crop.c.height) || - !is_streaming(ici, icd)) { - /* same size or not streaming - use .set_crop() */ - ret = ici->ops->set_crop(icd, a); - } else if (ici->ops->set_livecrop) { - ret = ici->ops->set_livecrop(icd, a); - } else { - dev_err(icd->pdev, - "S_CROP denied: queue initialised and sizes differ\n"); - ret = -EBUSY; - } - - return ret; -} - static int soc_camera_g_selection(struct file *file, void *fh, struct v4l2_selection *s) { @@ -1101,9 +1035,6 @@ static int soc_camera_g_selection(struct file *file, void *fh, if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; - if (!ici->ops->get_selection) - return -ENOTTY; - return ici->ops->get_selection(icd, s); } @@ -1135,10 +1066,11 @@ static int soc_camera_s_selection(struct file *file, void *fh, return -EBUSY; } - if (!ici->ops->set_selection) - return -ENOTTY; - - ret = ici->ops->set_selection(icd, s); + if (s->target == V4L2_SEL_TGT_CROP && is_streaming(ici, icd) && + ici->ops->set_liveselection) + ret = ici->ops->set_liveselection(icd, s); + else + ret = ici->ops->set_selection(icd, s); if (!ret && s->target == V4L2_SEL_TGT_COMPOSE) { icd->user_width = s->r.width; @@ -1881,23 +1813,40 @@ static int soc_camera_remove(struct soc_camera_device *icd) return 0; } -static int default_cropcap(struct soc_camera_device *icd, - struct v4l2_cropcap *a) +static int default_g_selection(struct soc_camera_device *icd, + struct v4l2_selection *sel) { struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - return v4l2_subdev_call(sd, video, cropcap, a); -} + struct v4l2_subdev_selection sdsel = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .target = sel->target, + }; + int ret; -static int default_g_crop(struct soc_camera_device *icd, struct v4l2_crop *a) -{ - struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - return v4l2_subdev_call(sd, video, g_crop, a); + ret = v4l2_subdev_call(sd, pad, get_selection, NULL, &sdsel); + if (ret) + return ret; + sel->r = sdsel.r; + return 0; } -static int default_s_crop(struct soc_camera_device *icd, const struct v4l2_crop *a) +static int default_s_selection(struct soc_camera_device *icd, + struct v4l2_selection *sel) { struct v4l2_subdev *sd = soc_camera_to_subdev(icd); - return v4l2_subdev_call(sd, video, s_crop, a); + struct v4l2_subdev_selection sdsel = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .target = sel->target, + .flags = sel->flags, + .r = sel->r, + }; + int ret; + + ret = v4l2_subdev_call(sd, pad, set_selection, NULL, &sdsel); + if (ret) + return ret; + sel->r = sdsel.r; + return 0; } static int default_g_parm(struct soc_camera_device *icd, @@ -1968,12 +1917,10 @@ int soc_camera_host_register(struct soc_camera_host *ici) !ici->v4l2_dev.dev) return -EINVAL; - if (!ici->ops->set_crop) - ici->ops->set_crop = default_s_crop; - if (!ici->ops->get_crop) - ici->ops->get_crop = default_g_crop; - if (!ici->ops->cropcap) - ici->ops->cropcap = default_cropcap; + if (!ici->ops->set_selection) + ici->ops->set_selection = default_s_selection; + if (!ici->ops->get_selection) + ici->ops->get_selection = default_g_selection; if (!ici->ops->set_parm) ici->ops->set_parm = default_s_parm; if (!ici->ops->get_parm) @@ -2126,9 +2073,6 @@ static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = { .vidioc_expbuf = soc_camera_expbuf, .vidioc_streamon = soc_camera_streamon, .vidioc_streamoff = soc_camera_streamoff, - .vidioc_cropcap = soc_camera_cropcap, - .vidioc_g_crop = soc_camera_g_crop, - .vidioc_s_crop = soc_camera_s_crop, .vidioc_g_selection = soc_camera_g_selection, .vidioc_s_selection = soc_camera_s_selection, .vidioc_g_parm = soc_camera_g_parm, diff --git a/drivers/media/platform/soc_camera/soc_camera_platform.c b/drivers/media/platform/soc_camera/soc_camera_platform.c index a51d2a42998c..534d6c3c6d60 100644 --- a/drivers/media/platform/soc_camera/soc_camera_platform.c +++ b/drivers/media/platform/soc_camera/soc_camera_platform.c @@ -76,35 +76,27 @@ static int soc_camera_platform_enum_mbus_code(struct v4l2_subdev *sd, return 0; } -static int soc_camera_platform_g_crop(struct v4l2_subdev *sd, - struct v4l2_crop *a) -{ - struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); - - a->c.left = 0; - a->c.top = 0; - a->c.width = p->format.width; - a->c.height = p->format.height; - a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - return 0; -} - -static int soc_camera_platform_cropcap(struct v4l2_subdev *sd, - struct v4l2_cropcap *a) +static int soc_camera_platform_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) { struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); - a->bounds.left = 0; - a->bounds.top = 0; - a->bounds.width = p->format.width; - a->bounds.height = p->format.height; - a->defrect = a->bounds; - a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - a->pixelaspect.numerator = 1; - a->pixelaspect.denominator = 1; + if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) + return -EINVAL; - return 0; + switch (sel->target) { + case V4L2_SEL_TGT_CROP_BOUNDS: + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP: + sel->r.left = 0; + sel->r.top = 0; + sel->r.width = p->format.width; + sel->r.height = p->format.height; + return 0; + default: + return -EINVAL; + } } static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd, @@ -120,13 +112,12 @@ static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd, static struct v4l2_subdev_video_ops platform_subdev_video_ops = { .s_stream = soc_camera_platform_s_stream, - .cropcap = soc_camera_platform_cropcap, - .g_crop = soc_camera_platform_g_crop, .g_mbus_config = soc_camera_platform_g_mbus_config, }; static const struct v4l2_subdev_pad_ops platform_subdev_pad_ops = { .enum_mbus_code = soc_camera_platform_enum_mbus_code, + .get_selection = soc_camera_platform_get_selection, .get_fmt = soc_camera_platform_fill_fmt, .set_fmt = soc_camera_platform_fill_fmt, }; diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.c b/drivers/media/platform/soc_camera/soc_scale_crop.c index bda29bc1b933..f77252d6ccd3 100644 --- a/drivers/media/platform/soc_camera/soc_scale_crop.c +++ b/drivers/media/platform/soc_camera/soc_scale_crop.c @@ -40,24 +40,22 @@ static bool is_inside(const struct v4l2_rect *r1, const struct v4l2_rect *r2) /* Get and store current client crop */ int soc_camera_client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect) { - struct v4l2_crop crop; - struct v4l2_cropcap cap; + struct v4l2_subdev_selection sdsel = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .target = V4L2_SEL_TGT_CROP, + }; int ret; - crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - ret = v4l2_subdev_call(sd, video, g_crop, &crop); + ret = v4l2_subdev_call(sd, pad, get_selection, NULL, &sdsel); if (!ret) { - *rect = crop.c; + *rect = sdsel.r; return ret; } - /* Camera driver doesn't support .g_crop(), assume default rectangle */ - cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - ret = v4l2_subdev_call(sd, video, cropcap, &cap); + sdsel.target = V4L2_SEL_TGT_CROP_DEFAULT; + ret = v4l2_subdev_call(sd, pad, get_selection, NULL, &sdsel); if (!ret) - *rect = cap.defrect; + *rect = sdsel.r; return ret; } @@ -93,17 +91,27 @@ static void update_subrect(struct v4l2_rect *rect, struct v4l2_rect *subrect) * 2. if (1) failed, try to double the client image until we get one big enough * 3. if (2) failed, try to request the maximum image */ -int soc_camera_client_s_crop(struct v4l2_subdev *sd, - struct v4l2_crop *crop, struct v4l2_crop *cam_crop, +int soc_camera_client_s_selection(struct v4l2_subdev *sd, + struct v4l2_selection *sel, struct v4l2_selection *cam_sel, struct v4l2_rect *target_rect, struct v4l2_rect *subrect) { - struct v4l2_rect *rect = &crop->c, *cam_rect = &cam_crop->c; + struct v4l2_subdev_selection sdsel = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .target = sel->target, + .flags = sel->flags, + .r = sel->r, + }; + struct v4l2_subdev_selection bounds = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .target = V4L2_SEL_TGT_CROP_BOUNDS, + }; + struct v4l2_rect *rect = &sel->r, *cam_rect = &cam_sel->r; struct device *dev = sd->v4l2_dev->dev; - struct v4l2_cropcap cap; int ret; unsigned int width, height; - v4l2_subdev_call(sd, video, s_crop, crop); + v4l2_subdev_call(sd, pad, set_selection, NULL, &sdsel); + sel->r = sdsel.r; ret = soc_camera_client_g_rect(sd, cam_rect); if (ret < 0) return ret; @@ -113,29 +121,29 @@ int soc_camera_client_s_crop(struct v4l2_subdev *sd, * be within camera cropcap bounds */ if (!memcmp(rect, cam_rect, sizeof(*rect))) { - /* Even if camera S_CROP failed, but camera rectangle matches */ - dev_dbg(dev, "Camera S_CROP successful for %dx%d@%d:%d\n", + /* Even if camera S_SELECTION failed, but camera rectangle matches */ + dev_dbg(dev, "Camera S_SELECTION successful for %dx%d@%d:%d\n", rect->width, rect->height, rect->left, rect->top); *target_rect = *cam_rect; return 0; } /* Try to fix cropping, that camera hasn't managed to set */ - dev_geo(dev, "Fix camera S_CROP for %dx%d@%d:%d to %dx%d@%d:%d\n", + dev_geo(dev, "Fix camera S_SELECTION for %dx%d@%d:%d to %dx%d@%d:%d\n", cam_rect->width, cam_rect->height, cam_rect->left, cam_rect->top, rect->width, rect->height, rect->left, rect->top); /* We need sensor maximum rectangle */ - ret = v4l2_subdev_call(sd, video, cropcap, &cap); + ret = v4l2_subdev_call(sd, pad, get_selection, NULL, &bounds); if (ret < 0) return ret; /* Put user requested rectangle within sensor bounds */ - soc_camera_limit_side(&rect->left, &rect->width, cap.bounds.left, 2, - cap.bounds.width); - soc_camera_limit_side(&rect->top, &rect->height, cap.bounds.top, 4, - cap.bounds.height); + soc_camera_limit_side(&rect->left, &rect->width, sdsel.r.left, 2, + bounds.r.width); + soc_camera_limit_side(&rect->top, &rect->height, sdsel.r.top, 4, + bounds.r.height); /* * Popular special case - some cameras can only handle fixed sizes like @@ -150,7 +158,7 @@ int soc_camera_client_s_crop(struct v4l2_subdev *sd, */ while (!ret && (is_smaller(cam_rect, rect) || is_inside(cam_rect, rect)) && - (cap.bounds.width > width || cap.bounds.height > height)) { + (bounds.r.width > width || bounds.r.height > height)) { width *= 2; height *= 2; @@ -168,36 +176,40 @@ int soc_camera_client_s_crop(struct v4l2_subdev *sd, * Instead we just drop to the left and top bounds. */ if (cam_rect->left > rect->left) - cam_rect->left = cap.bounds.left; + cam_rect->left = bounds.r.left; if (cam_rect->left + cam_rect->width < rect->left + rect->width) cam_rect->width = rect->left + rect->width - cam_rect->left; if (cam_rect->top > rect->top) - cam_rect->top = cap.bounds.top; + cam_rect->top = bounds.r.top; if (cam_rect->top + cam_rect->height < rect->top + rect->height) cam_rect->height = rect->top + rect->height - cam_rect->top; - v4l2_subdev_call(sd, video, s_crop, cam_crop); + sdsel.r = *cam_rect; + v4l2_subdev_call(sd, pad, set_selection, NULL, &sdsel); + *cam_rect = sdsel.r; ret = soc_camera_client_g_rect(sd, cam_rect); - dev_geo(dev, "Camera S_CROP %d for %dx%d@%d:%d\n", ret, + dev_geo(dev, "Camera S_SELECTION %d for %dx%d@%d:%d\n", ret, cam_rect->width, cam_rect->height, cam_rect->left, cam_rect->top); } - /* S_CROP must not modify the rectangle */ + /* S_SELECTION must not modify the rectangle */ if (is_smaller(cam_rect, rect) || is_inside(cam_rect, rect)) { /* * The camera failed to configure a suitable cropping, * we cannot use the current rectangle, set to max */ - *cam_rect = cap.bounds; - v4l2_subdev_call(sd, video, s_crop, cam_crop); + sdsel.r = bounds.r; + v4l2_subdev_call(sd, pad, set_selection, NULL, &sdsel); + *cam_rect = sdsel.r; + ret = soc_camera_client_g_rect(sd, cam_rect); - dev_geo(dev, "Camera S_CROP %d for max %dx%d@%d:%d\n", ret, + dev_geo(dev, "Camera S_SELECTION %d for max %dx%d@%d:%d\n", ret, cam_rect->width, cam_rect->height, cam_rect->left, cam_rect->top); } @@ -209,7 +221,7 @@ int soc_camera_client_s_crop(struct v4l2_subdev *sd, return ret; } -EXPORT_SYMBOL(soc_camera_client_s_crop); +EXPORT_SYMBOL(soc_camera_client_s_selection); /* Iterative set_fmt, also updates cached client crop on success */ static int client_set_fmt(struct soc_camera_device *icd, @@ -221,7 +233,10 @@ static int client_set_fmt(struct soc_camera_device *icd, struct device *dev = icd->parent; struct v4l2_mbus_framefmt *mf = &format->format; unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h; - struct v4l2_cropcap cap; + struct v4l2_subdev_selection sdsel = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .target = V4L2_SEL_TGT_CROP_BOUNDS, + }; bool host_1to1; int ret; @@ -243,16 +258,14 @@ static int client_set_fmt(struct soc_camera_device *icd, if (!host_can_scale) goto update_cache; - cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - ret = v4l2_subdev_call(sd, video, cropcap, &cap); + ret = v4l2_subdev_call(sd, pad, get_selection, NULL, &sdsel); if (ret < 0) return ret; - if (max_width > cap.bounds.width) - max_width = cap.bounds.width; - if (max_height > cap.bounds.height) - max_height = cap.bounds.height; + if (max_width > sdsel.r.width) + max_width = sdsel.r.width; + if (max_height > sdsel.r.height) + max_height = sdsel.r.height; /* Camera set a format, but geometry is not precise, try to improve */ tmp_w = mf->width; diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.h b/drivers/media/platform/soc_camera/soc_scale_crop.h index 184a30dff541..9ca469312a1f 100644 --- a/drivers/media/platform/soc_camera/soc_scale_crop.h +++ b/drivers/media/platform/soc_camera/soc_scale_crop.h @@ -16,7 +16,7 @@ struct soc_camera_device; -struct v4l2_crop; +struct v4l2_selection; struct v4l2_mbus_framefmt; struct v4l2_pix_format; struct v4l2_rect; @@ -31,8 +31,8 @@ static inline unsigned int soc_camera_shift_scale(unsigned int size, #define soc_camera_calc_scale(in, shift, out) soc_camera_shift_scale(in, shift, out) int soc_camera_client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect); -int soc_camera_client_s_crop(struct v4l2_subdev *sd, - struct v4l2_crop *crop, struct v4l2_crop *cam_crop, +int soc_camera_client_s_selection(struct v4l2_subdev *sd, + struct v4l2_selection *sel, struct v4l2_selection *cam_sel, struct v4l2_rect *target_rect, struct v4l2_rect *subrect); int soc_camera_client_scale(struct soc_camera_device *icd, struct v4l2_rect *rect, struct v4l2_rect *subrect, |