/*
* V4L2 Driver for i.MX3x camera host
*
* Copyright (C) 2008
* Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.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/init.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/videodev2.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/vmalloc.h>
#include <linux/interrupt.h>
#include <media/v4l2-common.h>
#include <media/v4l2-dev.h>
#include <media/videobuf-dma-contig.h>
#include <media/soc_camera.h>
#include <mach/ipu.h>
#include <mach/mx3_camera.h>
#define MX3_CAM_DRV_NAME "mx3-camera"
/* CMOS Sensor Interface Registers */
#define CSI_REG_START 0x60
#define CSI_SENS_CONF (0x60 - CSI_REG_START)
#define CSI_SENS_FRM_SIZE (0x64 - CSI_REG_START)
#define CSI_ACT_FRM_SIZE (0x68 - CSI_REG_START)
#define CSI_OUT_FRM_CTRL (0x6C - CSI_REG_START)
#define CSI_TST_CTRL (0x70 - CSI_REG_START)
#define CSI_CCIR_CODE_1 (0x74 - CSI_REG_START)
#define CSI_CCIR_CODE_2 (0x78 - CSI_REG_START)
#define CSI_CCIR_CODE_3 (0x7C - CSI_REG_START)
#define CSI_FLASH_STROBE_1 (0x80 - CSI_REG_START)
#define CSI_FLASH_STROBE_2 (0x84 - CSI_REG_START)
#define CSI_SENS_CONF_VSYNC_POL_SHIFT 0
#define CSI_SENS_CONF_HSYNC_POL_SHIFT 1
#define CSI_SENS_CONF_DATA_POL_SHIFT 2
#define CSI_SENS_CONF_PIX_CLK_POL_SHIFT 3
#define CSI_SENS_CONF_SENS_PRTCL_SHIFT 4
#define CSI_SENS_CONF_SENS_CLKSRC_SHIFT 7
#define CSI_SENS_CONF_DATA_FMT_SHIFT 8
#define CSI_SENS_CONF_DATA_WIDTH_SHIFT 10
#define CSI_SENS_CONF_EXT_VSYNC_SHIFT 15
#define CSI_SENS_CONF_DIVRATIO_SHIFT 16
#define CSI_SENS_CONF_DATA_FMT_RGB_YUV444 (0UL << CSI_SENS_CONF_DATA_FMT_SHIFT)
#define CSI_SENS_CONF_DATA_FMT_YUV422 (2UL << CSI_SENS_CONF_DATA_FMT_SHIFT)
#define CSI_SENS_CONF_DATA_FMT_BAYER (3UL << CSI_SENS_CONF_DATA_FMT_SHIFT)
#define MAX_VIDEO_MEM 16
struct mx3_camera_buffer {
/* common v4l buffer stuff -- must be first */
struct videobuf_buffer vb;
const struct soc_camera_data_format *fmt;
/* One descriptot per scatterlist (per frame) */
struct dma_async_tx_descriptor *txd;
/* We have to "build" a scatterlist ourselves - one element per frame */
struct scatterlist sg;
};
/**
* struct mx3_camera_dev - i.MX3x camera (CSI) object
* @dev: camera device, to which the coherent buffer is attached
* @icd: currently attached camera sensor
* @clk: pointer to clock
* @base: remapped register base address
* @pdata: platform data
* @platform_flags: platform flags
* @mclk: master clock frequency in Hz
* @capture: list of capture videobuffers
* @lock: protects video buffer lists
* @active: active video buffer
* @idmac_channel: array of pointers to IPU DMAC DMA channels
* @soc_host: embedded soc_host object
*/
struct mx3_camera_dev {
/*
* i.MX3x is only supposed to handle one camera on its Camera Sensor
* Interface. If anyone ever builds hardware to enable more than one
* camera _simultaneously_, they will have to modify this driver too
*/
struct soc_camera_device *icd;
struct clk *clk;
void __iomem *base;
struct mx3_camera_pdata *pdata;
unsigned long platform_flags;
unsigned long mclk;
struct list_head capture;
spinlock_t lock; /* Protects video buffer lists */
struct mx3_camera_buffer *active;
/* IDMAC / dmaengine interface */
struct idmac_channel *idmac_channel[1]; /* We need one channel */
struct soc_camera_host soc_host;
};
struct dma_chan_request {
struct mx3_camera_dev *mx3_cam;
enum ipu_channel id;
};
static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt);
static u32 csi_reg_read(struct mx3_camera_dev *mx3, off_t reg)
{
return __raw_readl(mx3->base + reg);
}
static void csi_reg_write(struct mx3_camera_dev *mx3, u32 value, off_t reg)
{
__raw_writel(value, mx3->base + reg);
}
/* Called from the IPU IDMAC ISR */
static void mx3_cam_dma_done(void *arg)
{
struct idmac_tx_desc *desc = to_tx_desc(arg);
struct dma_chan *chan = desc->txd.chan;
struct idmac_channel *ichannel = to_idmac_chan(chan);
struct mx3_camera_dev *mx3_cam = ichannel->client;
struct videobuf_buffer *vb;
dev_dbg(chan->device->dev, "callback cookie %d, active DMA 0x%08x