* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
-#if defined(CONFIG_ARCH_RK2928) || defined(CONFIG_ARCH_RK30)
+#if (defined(CONFIG_ARCH_RK2928) ||\
+ defined(CONFIG_ARCH_RK30) ||\
+ defined(CONFIG_ARCH_RK3188) ||\
+ defined(CONFIG_ARCH_RK3026))
+
#include <linux/init.h>
#include <linux/module.h>
#include <linux/io.h>
#include <plat/ipp.h>
#include <plat/vpu_service.h>
#include "../../video/rockchip/rga/rga.h"
-#if defined(CONFIG_ARCH_RK30)
+#if defined(CONFIG_ARCH_RK30)||defined(CONFIG_ARCH_RK3188)
#include <mach/rk30_camera.h>
#include <mach/cru.h>
#include <mach/pmu.h>
#endif
-
-#if defined(CONFIG_ARCH_RK2928)
+#include <plat/efuse.h>
+#if (defined(CONFIG_ARCH_RK2928) || defined(CONFIG_ARCH_RK3026))
#include <mach/rk2928_camera.h>
+#include <mach/cru.h>
+#include <mach/pmu.h>
+#define SOFT_RST_CIF1 (SOFT_RST_MAX+1)
#endif
#include <asm/cacheflush.h>
+
static int debug;
module_param(debug, int, S_IRUGO|S_IWUSR);
+#define CAMMODULE_NAME "rk_cam_cif"
+
+#define wprintk(level, fmt, arg...) do { \
+ if (debug >= level) \
+ printk(KERN_WARNING "%s(%d): " fmt,CAMMODULE_NAME,__LINE__,## arg); } while (0)
+
#define dprintk(level, fmt, arg...) do { \
if (debug >= level) \
- printk(KERN_WARNING"rk_camera: " fmt , ## arg); } while (0)
+ printk(KERN_DEBUG "%s(%d): " fmt,CAMMODULE_NAME,__LINE__,## arg); } while (0)
+
+#define RKCAMERA_TR(format, ...) printk(KERN_ERR "%s(%d):" format,CAMMODULE_NAME,__LINE__,## __VA_ARGS__)
+#define RKCAMERA_DG1(format, ...) wprintk(1, format, ## __VA_ARGS__)
+#define RKCAMERA_DG2(format, ...) dprintk(2, format, ## __VA_ARGS__)
-#define RKCAMERA_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
-#define RKCAMERA_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
-#define CIF_DO_CROP 1
// CIF Reg Offset
#define CIF_CIF_CTRL 0x00
#define CIF_CIF_INTEN 0x04
#define ENABLE_32BIT_BYPASS (0x01<<6)
#define DISABLE_32BIT_BYPASS (0x00<<6)
-#if defined(CONFIG_ARCH_RK30)
+
+#define MIN(x,y) ((x<y) ? x: y)
+#define MAX(x,y) ((x>y) ? x: y)
+#define RK_SENSOR_24MHZ 24*1000*1000 /* MHz */
+#define RK_SENSOR_48MHZ 48
+
+#define write_cif_reg(base,addr, val) __raw_writel(val, addr+(base))
+#define read_cif_reg(base,addr) __raw_readl(addr+(base))
+#define mask_cif_reg(addr, msk, val) write_cif_reg(addr, (val)|((~(msk))&read_cif_reg(addr)))
+
+#if defined(CONFIG_ARCH_RK30) || defined(CONFIG_ARCH_RK3188)
//CRU,PIXCLOCK
#define CRU_PCLK_REG30 0xbc
#define ENANABLE_INVERT_PCLK_CIF0 ((0x1<<24)|(0x1<<8))
#define MASK_RST_CIF1 (0x01 << 31)
#define RQUEST_RST_CIF0 (0x01 << 14)
#define RQUEST_RST_CIF1 (0x01 << 15)
-#endif
-
-#define MIN(x,y) ((x<y) ? x: y)
-#define MAX(x,y) ((x>y) ? x: y)
-#define RK_SENSOR_24MHZ 24*1000*1000 /* MHz */
-#define RK_SENSOR_48MHZ 48
-#define write_cif_reg(base,addr, val) __raw_writel(val, addr+(base))
-#define read_cif_reg(base,addr) __raw_readl(addr+(base))
-#define mask_cif_reg(addr, msk, val) write_cif_reg(addr, (val)|((~(msk))&read_cif_reg(addr)))
+#define write_cru_reg(addr, val) __raw_writel(val, addr+RK30_CRU_BASE)
+#define read_cru_reg(addr) __raw_readl(addr+RK30_CRU_BASE)
+#define mask_cru_reg(addr, msk, val) write_cru_reg(addr,(val)|((~(msk))&read_cru_reg(addr)))
+#endif
-#if defined(CONFIG_ARCH_RK30)
-#define write_cru_reg(addr, val) __raw_writel(val, addr+RK30_CRU_BASE)
-#define read_cru_reg(addr) __raw_readl(addr+RK30_CRU_BASE)
-#define mask_cru_reg(addr, msk, val) write_cru_reg(addr,(val)|((~(msk))&read_cru_reg(addr)))
+#if defined(CONFIG_ARCH_RK3026)
+//CRU,PIXCLOCK
+#define CRU_PCLK_REG30 0xbc
+#define ENANABLE_INVERT_PCLK_CIF0 ((0x1<<23)|(0x1<<7))
+#define DISABLE_INVERT_PCLK_CIF0 ((0x1<<23)|(0x0<<7))
+#define ENANABLE_INVERT_PCLK_CIF1 ENANABLE_INVERT_PCLK_CIF0
+#define DISABLE_INVERT_PCLK_CIF1 DISABLE_INVERT_PCLK_CIF0
+
+#define write_cru_reg(addr, val) __raw_writel(val, addr+RK30_CRU_BASE)
+#define read_cru_reg(addr) __raw_readl(addr+RK30_CRU_BASE)
+#define mask_cru_reg(addr, msk, val) write_cru_reg(addr,(val)|((~(msk))&read_cru_reg(addr)))
#endif
#if defined(CONFIG_ARCH_RK2928)
#endif
-//when work_with_ipp is not enabled,CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_OFF is not defined.something wrong with it
-#ifdef CONFIG_VIDEO_RK29_WORK_IPP//CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_OFF
-#ifdef CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_OFF
-#define CAM_WORKQUEUE_IS_EN() ((pcdev->host_width != pcdev->icd->user_width) || (pcdev->host_height != pcdev->icd->user_height)\
- || (pcdev->icd_cb.sensor_cb))
-#define CAM_IPPWORK_IS_EN() ((pcdev->host_width != pcdev->icd->user_width) || (pcdev->host_height != pcdev->icd->user_height))
+#if defined(CONFIG_ARCH_RK3066B) || defined(CONFIG_ARCH_RK3188)
+//GRF_IO_CON3 0x100
+#define CIF_DRIVER_STRENGTH_2MA (0x00 << 12)
+#define CIF_DRIVER_STRENGTH_4MA (0x01 << 12)
+#define CIF_DRIVER_STRENGTH_8MA (0x02 << 12)
+#define CIF_DRIVER_STRENGTH_12MA (0x03 << 12)
+#define CIF_DRIVER_STRENGTH_MASK (0x03 << 28)
+
+//GRF_IO_CON4 0x104
+#define CIF_CLKOUT_AMP_3V3 (0x00 << 10)
+#define CIF_CLKOUT_AMP_1V8 (0x01 << 10)
+#define CIF_CLKOUT_AMP_MASK (0x01 << 26)
+
+#define write_grf_reg(addr, val) __raw_writel(val, addr+RK30_GRF_BASE)
+#define read_grf_reg(addr) __raw_readl(addr+RK30_GRF_BASE)
+#define mask_grf_reg(addr, msk, val) write_grf_reg(addr,(val)|((~(msk))&read_grf_reg(addr)))
#else
+#define write_grf_reg(addr, val)
+#define read_grf_reg(addr) 0
+#define mask_grf_reg(addr, msk, val)
+#endif
+
#define CAM_WORKQUEUE_IS_EN() (true)
#define CAM_IPPWORK_IS_EN() ((pcdev->zoominfo.a.c.width != pcdev->icd->user_width) || (pcdev->zoominfo.a.c.height != pcdev->icd->user_height))
-#endif
-#else //CONFIG_VIDEO_RK29_WORK_IPP
-#define CAM_WORKQUEUE_IS_EN() (false)
-#define CAM_IPPWORK_IS_EN() (false)
-#endif
#define IS_CIF0() (pcdev->hostid == RK_CAM_PLATFORM_DEV_ID_0)
#if (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_IPP)
#define CROP_ALIGN_BYTES (0x03)
+#define CIF_DO_CROP 0
#elif (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_ARM)
-#define CROP_ALIGN_BYTES (0x03)
+#define CROP_ALIGN_BYTES (0x0f)
+#define CIF_DO_CROP 0
#elif (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_RGA)
#define CROP_ALIGN_BYTES (0x03)
+#define CIF_DO_CROP 0
#elif(CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_PP)
#define CROP_ALIGN_BYTES (0x0F)
+#define CIF_DO_CROP 1
#endif
//Configure Macro
/*
*v0.x.11: fix struct rk_camera_work may be reentrant
*v0.x.13: 1.add scale by arm,rga and pp.
2.CIF do the crop when digital zoom.
- 3.fix bug in prob func:request mem twice.
-
+ 3.fix bug in prob func:request mem twice.
+ 4.video_vq may be null when reinit work,fix it
+ 5.arm scale algorithm has something wrong(may exceed the bound of width or height) ,fix it.
+*v0.x.15:
+* 1. support rk3066b;
+*v0.x.17:
+* 1. support 8Mega picture;
+*v0.x.19:
+* 1. invalidate the limit which scale is invalidat when scale ratio > 2;
+*v0.x.1b: 1. fix oops bug when using arm to do scale_crop if preview buffer is not allocated correctly
+ 2. rk_camera_set_fmt will called twice, optimize the procedure. at the first time call ,just to do the sensor init.
+
+*v0.x.1c:
+* 1. fix query resolution error;
+*v0.x.1d:
+* 1. add mv9335+ov5650 driver;
+* 2. fix 2928 digitzoom erro(arm crop scale) of selected zone;
+*v0.x.1f:
+* 1. support rk3188; Must soft reset cif controller after each frame irq;
+*v0.2.21:
+* 1. fix ctrl register capture bit may be turn on in rk_videobuf_capture function
+*
+*v0.3.1 :
+* 1. compatible with generic_sensor;
+*
+*v0.3.3 / v0.3.5:
+* 1. fix use v4l2_mbus_framefmt.reserved array overflow in generic_sensor_s_fmt;
+*
+*v0.3.7:
+* 1. support rk3028 , read 3028 chip id by efuse for check cif controller is normal or not;
+*v0.3.9:
+* 1. return real sensor output size in rk_camera_enum_frameintervals;
+* 2. wake up vb after add camera work to list in rk_camera_capture_process;
+*v0.3.b:
+* 1. this verison is support for 3188M, the version has been revert in v0.3.d;
+*v0.3.d:
+* 1. this version is support for rk3028a;
+*
+*v0.3.f:
+* 1. this version is support query fov orientation;
+*v0.3.0x11:
+* 1. fix vb struct may be used again which have been free after stream off, some code modify in soc_camera.c,
+* version is v0.1.1;
+* 1. fix cif clk out can't be turn off;
+*
+*v0.3.0x12:
+* 1. modify cif irq ,remove judge reg_lastpixel==host_width.
+*
*/
-#define RK_CAM_VERSION_CODE KERNEL_VERSION(0, 2, 0x13)
+
+#define RK_CAM_VERSION_CODE KERNEL_VERSION(0, 3, 0x12)
+static int version = RK_CAM_VERSION_CODE;
+module_param(version, int, S_IRUGO);
/* limit to rk29 hardware capabilities */
#define RK_CAM_BUS_PARAM (SOCAM_MASTER |\
#define RK_CAM_W_MIN 48
#define RK_CAM_H_MIN 32
-#define RK_CAM_W_MAX 3856 /* ddl@rock-chips.com : 10M Pixel */
+#define RK_CAM_W_MAX 3856 /* ddl@rock-chips.com : 10M Pixel */
#define RK_CAM_H_MAX 2764
-#define RK_CAM_FRAME_INVAL_INIT 3
-#define RK_CAM_FRAME_INVAL_DC 3 /* ddl@rock-chips.com : */
-#define RK30_CAM_FRAME_MEASURE 5
+#define RK_CAM_FRAME_INVAL_INIT 3
+#define RK_CAM_FRAME_INVAL_DC 3 /* ddl@rock-chips.com : */
+#define RK30_CAM_FRAME_MEASURE 5
+
+
extern void videobuf_dma_contig_free(struct videobuf_queue *q, struct videobuf_buffer *buf);
extern dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf);
-
/* buffer for one video frame */
struct rk_camera_buffer
{
struct semaphore sem;
struct v4l2_crop a;
int vir_width;
- int vir_height;
+ int vir_height;
int zoom_rate;
};
#if CAMERA_VIDEOBUF_ARM_ACCESS
struct rk_camera_dev *pcdev;
struct hrtimer timer;
bool istarted;
- };
-struct rk_camera_dev
+};
+struct rk_cif_clk
{
- struct soc_camera_host soc_host;
- struct device *dev;
- /* RK2827x 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 soc_camera_device *icd;
-
- //************must modify start************/
+ //************must modify start************/
struct clk *pd_cif;
struct clk *aclk_cif;
struct clk *hclk_cif;
struct clk *cif_clk_in;
struct clk *cif_clk_out;
//************must modify end************/
- void __iomem *base;
- int frame_inval; /* ddl@rock-chips.com : The first frames is invalidate */
- unsigned int irq;
- unsigned int fps;
+
+ spinlock_t lock;
+ bool on;
+};
+
+struct rk_cif_crop
+{
+ spinlock_t lock;
+ struct v4l2_rect c;
+ struct v4l2_rect bounds;
+};
+
+struct rk_cif_irqinfo
+{
+ unsigned int irq;
+ unsigned long cifirq_idx;
+ unsigned long cifirq_normal_idx;
+ unsigned long cifirq_abnormal_idx;
+
+ unsigned long dmairq_idx;
+ spinlock_t lock;
+};
+
+struct rk_camera_dev
+{
+ struct soc_camera_host soc_host;
+ struct device *dev;
+ /* RK2827x 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 soc_camera_device *icd;
+ void __iomem *base;
+ int frame_inval; /* ddl@rock-chips.com : The first frames is invalidate */
+
+ unsigned int fps;
unsigned int last_fps;
unsigned long frame_interval;
- unsigned int pixfmt;
- //for ipp
- unsigned int vipmem_phybase;
+ unsigned int pixfmt;
+ //for ipp
+ unsigned int vipmem_phybase;
void __iomem *vipmem_virbase;
- unsigned int vipmem_size;
- unsigned int vipmem_bsize;
+ unsigned int vipmem_size;
+ unsigned int vipmem_bsize;
#if CAMERA_VIDEOBUF_ARM_ACCESS
struct rk29_camera_vbinfo *vbinfo;
unsigned int vbinfo_count;
#endif
- int host_width;
- int host_height;
- int host_left; //sensor output size ?
- int host_top;
- int hostid;
+ int host_width;
+ int host_height;
+ int host_left; //sensor output size ?
+ int host_top;
+ int hostid;
int icd_width;
int icd_height;
- struct rk29camera_platform_data *pdata;
- struct resource *res;
- struct list_head capture;
- struct rk_camera_zoominfo zoominfo;
+ struct rk_cif_crop cropinfo;
+ struct rk_cif_irqinfo irqinfo;
+
+ struct rk29camera_platform_data *pdata;
+ struct resource *res;
+ struct list_head capture;
+ struct rk_camera_zoominfo zoominfo;
- spinlock_t lock;
+ spinlock_t lock;
- struct videobuf_buffer *active;
- struct rk_camera_reg reginfo_suspend;
- struct workqueue_struct *camera_wq;
- struct rk_camera_work *camera_work;
+ struct videobuf_buffer *active;
+ struct rk_camera_reg reginfo_suspend;
+ struct workqueue_struct *camera_wq;
+ struct rk_camera_work *camera_work;
struct list_head camera_work_queue;
spinlock_t camera_work_lock;
- unsigned int camera_work_count;
- struct rk_camera_timer fps_timer;
- struct rk_camera_work camera_reinit_work;
- int icd_init;
- rk29_camera_sensor_cb_s icd_cb;
- struct rk_camera_frmivalinfo icd_frmival[2];
- // atomic_t to_process_frames;
+ unsigned int camera_work_count;
+ struct rk_camera_timer fps_timer;
+ struct rk_camera_work camera_reinit_work;
+ int icd_init;
+ rk29_camera_sensor_cb_s icd_cb;
+ struct rk_camera_frmivalinfo icd_frmival[2];
bool timer_get_fps;
unsigned int reinit_times;
struct videobuf_queue *video_vq;
- bool stop_cif;
+ atomic_t stop_cif;
struct timeval first_tv;
+
+ int chip_id;
};
static const struct v4l2_queryctrl rk_camera_controls[] =
{
- #ifdef CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_ON
{
.id = V4L2_CID_ZOOM_ABSOLUTE,
.type = V4L2_CTRL_TYPE_INTEGER,
.maximum = 300,
.step = 5,
.default_value = 100,
- },
- #endif
+ }
};
+static struct rk_cif_clk cif_clk[2];
+
static DEFINE_MUTEX(camera_lock);
static const char *rk_cam_driver_description = "RK_Camera";
static int rk_camera_s_stream(struct soc_camera_device *icd, int enable);
static void rk_camera_capture_process(struct work_struct *work);
+static int rk_camera_scale_crop_arm(struct work_struct *work);
+
+static void rk_camera_cif_reset(struct rk_camera_dev *pcdev, int only_rst)
+{
+ int ctrl_reg,inten_reg,crop_reg,set_size_reg,for_reg,vir_line_width_reg,scl_reg;
+ enum cru_soft_reset cif_reset_index = SOFT_RST_CIF0;
+
+ if (IS_CIF0() == false) {
+#if RK_SUPPORT_CIF1
+ cif_reset_index = SOFT_RST_CIF1;
+#else
+ RKCAMERA_TR("%s: CIF1 is invalidate\n",__FUNCTION__);
+ BUG();
+#endif
+ }
+
+ if (only_rst == true) {
+ cru_set_soft_reset(cif_reset_index, true);
+ udelay(5);
+ cru_set_soft_reset(cif_reset_index, false);
+ } else {
+ ctrl_reg = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
+ crop_reg = read_cif_reg(pcdev->base,CIF_CIF_CROP);
+ set_size_reg = read_cif_reg(pcdev->base,CIF_CIF_SET_SIZE);
+ inten_reg = read_cif_reg(pcdev->base,CIF_CIF_INTEN);
+ for_reg = read_cif_reg(pcdev->base,CIF_CIF_FOR);
+ vir_line_width_reg = read_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH);
+ scl_reg = read_cif_reg(pcdev->base,CIF_CIF_SCL_CTRL);
+
+ cru_set_soft_reset(cif_reset_index, true);
+ udelay(5);
+ cru_set_soft_reset(cif_reset_index, false);
+
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, ctrl_reg&~ENABLE_CAPTURE);
+ write_cif_reg(pcdev->base,CIF_CIF_INTEN, inten_reg);
+ write_cif_reg(pcdev->base,CIF_CIF_CROP, crop_reg);
+ write_cif_reg(pcdev->base,CIF_CIF_SET_SIZE, set_size_reg);
+ write_cif_reg(pcdev->base,CIF_CIF_FOR, for_reg);
+ write_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH,vir_line_width_reg);
+ write_cif_reg(pcdev->base,CIF_CIF_SCL_CTRL,scl_reg);
+ }
+ return;
+}
/*
else
bytes_per_line_host = soc_mbus_bytes_per_line(pcdev->host_width,
icd->current_fmt->host_fmt);
- printk("user code = %d,packing = %d",icd->current_fmt->code,fmt.packing);
dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
if (bytes_per_line_host < 0)
pcdev->vipmem_bsize = PAGE_ALIGN(bytes_per_line_host * pcdev->host_height);
if (CAM_WORKQUEUE_IS_EN()) {
- #ifdef CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_OFF
- if (CAM_IPPWORK_IS_EN())
- #endif
- {
+
+ if (CAM_IPPWORK_IS_EN()) {
BUG_ON(pcdev->vipmem_size<pcdev->vipmem_bsize);
if (*count > pcdev->vipmem_size/pcdev->vipmem_bsize) { /* Buffers must be limited, when this resolution is genered by IPP */
*count = pcdev->vipmem_size/pcdev->vipmem_bsize;
}
}
+
if ((pcdev->camera_work_count != *count) && pcdev->camera_work) {
kfree(pcdev->camera_work);
pcdev->camera_work = NULL;
if (pcdev->camera_work == NULL) {
pcdev->camera_work = wk = kzalloc(sizeof(struct rk_camera_work)*(*count), GFP_KERNEL);
if (pcdev->camera_work == NULL) {
- RKCAMERA_TR("\n %s kmalloc fail\n", __FUNCTION__);
+ RKCAMERA_TR("kmalloc failed\n");
BUG();
}
INIT_LIST_HEAD(&pcdev->camera_work_queue);
if (pcdev->vbinfo == NULL) {
pcdev->vbinfo = kzalloc(sizeof(struct rk29_camera_vbinfo)*(*count), GFP_KERNEL);
if (pcdev->vbinfo == NULL) {
- RKCAMERA_TR("\n %s vbinfo kmalloc fail\n", __FUNCTION__);
+ RKCAMERA_TR("vbinfo kmalloc fail\n");
BUG();
}
+ memset(pcdev->vbinfo,0,sizeof(struct rk29_camera_vbinfo)*(*count));
pcdev->vbinfo_count = *count;
}
#endif
}
pcdev->video_vq = vq;
- RKCAMERA_DG("%s..%d.. videobuf size:%d, vipmem_buf size:%d, count:%d \n",__FUNCTION__,__LINE__, *size,pcdev->vipmem_size, *count);
+ RKCAMERA_DG1("videobuf size:%d, vipmem_buf size:%d, count:%d \n",*size,pcdev->vipmem_size, *count);
return 0;
}
* 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);
+ videobuf_waiton(vq, &buf->vb, 0, 0);
videobuf_dma_contig_free(vq, &buf->vb);
dev_dbg(&icd->dev, "%s freed\n", __func__);
buf->vb.state = VIDEOBUF_NEEDS_INIT;
int ret;
int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
icd->current_fmt->host_fmt);
- if (bytes_per_line < 0)
- return bytes_per_line;
+ if ((bytes_per_line < 0) || (vb->boff == 0))
+ return -EINVAL;
buf = container_of(vb, struct rk_camera_buffer, vb);
y_addr = vb->boff;
uv_addr = y_addr + vb->width * vb->height;
}
+#if defined(CONFIG_ARCH_RK3188)
+ rk_camera_cif_reset(pcdev,false);
+#endif
write_cif_reg(pcdev->base,CIF_CIF_FRM0_ADDR_Y, y_addr);
write_cif_reg(pcdev->base,CIF_CIF_FRM0_ADDR_UV, uv_addr);
write_cif_reg(pcdev->base,CIF_CIF_FRM1_ADDR_Y, y_addr);
struct soc_camera_device *icd = vq->priv_data;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct rk_camera_dev *pcdev = ici->priv;
+#if CAMERA_VIDEOBUF_ARM_ACCESS
struct rk29_camera_vbinfo *vb_info;
+#endif
dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %zd\n", __func__,
vb, vb->baddr, vb->bsize);
vb_info->size = vb->bsize;
vb_info->phy_addr = vb->boff;
} else {
- RKCAMERA_TR("%s..%d:ioremap videobuf %d failed\n",__FUNCTION__,__LINE__, vb->i);
+ RKCAMERA_TR("ioremap videobuf %d failed\n",vb->i);
}
}
}
rk_videobuf_capture(vb,pcdev);
}
}
+#if (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_IPP)
static int rk_pixfmt2ippfmt(unsigned int pixfmt, int *ippfmt)
{
switch (pixfmt)
rk_pixfmt2ippfmt_err:
return -1;
}
-
+#endif
+#if (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_RGA)
static int rk_pixfmt2rgafmt(unsigned int pixfmt, int *ippfmt)
{
switch (pixfmt)
rk_pixfmt2rgafmt_err:
return -1;
}
+#endif
#if (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_PP)
static int rk_camera_scale_crop_pp(struct work_struct *work){
struct rk_camera_work *camera_work = container_of(work, struct rk_camera_work, work);
struct rk29_ipp_req ipp_req;
int src_y_offset,src_uv_offset,dst_y_offset,dst_uv_offset,src_y_size,dst_y_size;
int scale_times,w,h;
- int ret = 0;
+ int ret = 0, scale_crop_ret=0;
+
/*
*ddl@rock-chips.com:
* IPP Dest image resolution is 2047x1088, so scale operation break up some times
ipp_req.dst0.w = pcdev->icd->user_width/scale_times;
ipp_req.dst0.h = pcdev->icd->user_height/scale_times;
ipp_req.dst_vir_w = pcdev->icd->user_width;
- rk_pixfmt2ippfmt(pcdev->pixfmt, &ipp_req.dst0.fmt);
+ rk_pixfmt2ippfmt(pcdev->pixfmt, &ipp_req.dst0.fmt);
vipdata_base = pcdev->vipmem_phybase + vb->i*pcdev->vipmem_bsize;
src_y_size = pcdev->zoominfo.vir_width*pcdev->zoominfo.vir_height; //vipmem
dst_y_size = pcdev->icd->user_width*pcdev->icd->user_height;
for (h=0; h<scale_times; h++) {
for (w=0; w<scale_times; w++) {
- int ipp_times = 3;
src_y_offset = (pcdev->zoominfo.a.c.top + h*pcdev->zoominfo.a.c.height/scale_times)* pcdev->zoominfo.vir_width
+ pcdev->zoominfo.a.c.left + w*pcdev->zoominfo.a.c.width/scale_times;
src_uv_offset = (pcdev->zoominfo.a.c.top + h*pcdev->zoominfo.a.c.height/scale_times)* pcdev->zoominfo.vir_width/2
ipp_req.src0.CbrMst = vipdata_base + src_y_size + src_uv_offset;
ipp_req.dst0.YrgbMst = vb->boff + dst_y_offset;
ipp_req.dst0.CbrMst = vb->boff + dst_y_size + dst_uv_offset;
- while(ipp_times-- > 0) {
- if (ipp_blit_sync(&ipp_req)){
- RKCAMERA_TR("ipp do erro,do again,ipp_times = %d!\n",ipp_times);
- } else {
- break;
- }
+
+ if (ipp_blit_sync(&ipp_req)){
+ RKCAMERA_TR("ipp do erro, so switch to arm \n");
+ scale_crop_ret = 0x01;
+ break;
}
-
- if (ipp_times <= 0) {
- spin_lock_irqsave(&pcdev->lock, flags);
- vb->state = VIDEOBUF_NEEDS_INIT;
- spin_unlock_irqrestore(&pcdev->lock, flags);
- RKCAMERA_TR("Capture image(vb->i:0x%x) which IPP operated is error:\n",vb->i);
- RKCAMERA_TR("widx:%d hidx:%d ",w,h);
- RKCAMERA_TR("%dx%d@(%d,%d)->%dx%d\n",pcdev->zoominfo.a.c.width,pcdev->zoominfo.a.c.height,pcdev->zoominfo.a.c.left,pcdev->zoominfo.a.c.top,pcdev->icd->user_width,pcdev->icd->user_height);
- RKCAMERA_TR("ipp_req.src0.YrgbMst:0x%x ipp_req.src0.CbrMst:0x%x \n", ipp_req.src0.YrgbMst,ipp_req.src0.CbrMst);
- RKCAMERA_TR("ipp_req.src0.w:0x%x ipp_req.src0.h:0x%x \n",ipp_req.src0.w,ipp_req.src0.h);
- RKCAMERA_TR("ipp_req.src0.fmt:0x%x\n",ipp_req.src0.fmt);
- RKCAMERA_TR("ipp_req.dst0.YrgbMst:0x%x ipp_req.dst0.CbrMst:0x%x \n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
- RKCAMERA_TR("ipp_req.dst0.w:0x%x ipp_req.dst0.h:0x%x \n",ipp_req.dst0.w ,ipp_req.dst0.h);
- RKCAMERA_TR("ipp_req.dst0.fmt:0x%x\n",ipp_req.dst0.fmt);
- RKCAMERA_TR("ipp_req.src_vir_w:0x%x ipp_req.dst_vir_w :0x%x\n",ipp_req.src_vir_w ,ipp_req.dst_vir_w);
- RKCAMERA_TR("ipp_req.timeout:0x%x ipp_req.flag :0x%x\n",ipp_req.timeout,ipp_req.flag);
-
- goto do_ipp_err;
- }
}
}
-do_ipp_err:
+ if (scale_crop_ret == 0x01) {
+ ret = rk_camera_scale_crop_arm(work);
+ }
+
+ if (ret) {
+ spin_lock_irqsave(&pcdev->lock, flags);
+ vb->state = VIDEOBUF_NEEDS_INIT;
+ spin_unlock_irqrestore(&pcdev->lock, flags);
+ RKCAMERA_TR("Capture image(vb->i:0x%x) which IPP and ARM operated is error:\n",vb->i);
+ RKCAMERA_TR("widx:%d hidx:%d ",w,h);
+ RKCAMERA_TR("%dx%d@(%d,%d)->%dx%d\n",pcdev->zoominfo.a.c.width,pcdev->zoominfo.a.c.height,pcdev->zoominfo.a.c.left,pcdev->zoominfo.a.c.top,pcdev->icd->user_width,pcdev->icd->user_height);
+ RKCAMERA_TR("ipp_req.src0.YrgbMst:0x%x ipp_req.src0.CbrMst:0x%x \n", ipp_req.src0.YrgbMst,ipp_req.src0.CbrMst);
+ RKCAMERA_TR("ipp_req.src0.w:0x%x ipp_req.src0.h:0x%x \n",ipp_req.src0.w,ipp_req.src0.h);
+ RKCAMERA_TR("ipp_req.src0.fmt:0x%x\n",ipp_req.src0.fmt);
+ RKCAMERA_TR("ipp_req.dst0.YrgbMst:0x%x ipp_req.dst0.CbrMst:0x%x \n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
+ RKCAMERA_TR("ipp_req.dst0.w:0x%x ipp_req.dst0.h:0x%x \n",ipp_req.dst0.w ,ipp_req.dst0.h);
+ RKCAMERA_TR("ipp_req.dst0.fmt:0x%x\n",ipp_req.dst0.fmt);
+ RKCAMERA_TR("ipp_req.src_vir_w:0x%x ipp_req.dst_vir_w :0x%x\n",ipp_req.src_vir_w ,ipp_req.dst_vir_w);
+ RKCAMERA_TR("ipp_req.timeout:0x%x ipp_req.flag :0x%x\n",ipp_req.timeout,ipp_req.flag);
+ }
+
return ret;
}
#endif
-#if (CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_ARM)
static int rk_camera_scale_crop_arm(struct work_struct *work)
{
struct rk_camera_work *camera_work = container_of(work, struct rk_camera_work, work);
long yCoeff00,yCoeff01,xCoeff00,xCoeff01;
long sX,sY;
long r0,r1,a,b,c,d;
- int ret = 0;
+ int ret = 0, shift_bits = 0;
src_phy = pcdev->vipmem_phybase + vb->i*pcdev->vipmem_bsize;
src = psY = (unsigned char*)(pcdev->vipmem_virbase + vb->i*pcdev->vipmem_bsize);
- psUV = psY + pcdev->zoominfo.vir_width*pcdev->zoominfo.vir_height;;
+ psUV = psY + pcdev->zoominfo.vir_width*pcdev->zoominfo.vir_height;
srcW = pcdev->zoominfo.vir_width;
srcH = pcdev->zoominfo.vir_height;
cropW = pcdev->zoominfo.a.c.width;
cropH = pcdev->zoominfo.a.c.height;
- psY = psY + (srcW-cropW);
- psUV = psUV + (srcW-cropW);
+ psY = psY + pcdev->zoominfo.a.c.top*pcdev->zoominfo.vir_width+pcdev->zoominfo.a.c.left;
+ psUV = psUV + pcdev->zoominfo.a.c.top*pcdev->zoominfo.vir_width/2+pcdev->zoominfo.a.c.left;
vb_info = pcdev->vbinfo+vb->i;
dst_phy = vb_info->phy_addr;
dstW = pcdev->icd->user_width;
dstH = pcdev->icd->user_height;
- zoomindstxIntInv = ((unsigned long)cropW<<16)/dstW + 1;
- zoomindstyIntInv = ((unsigned long)cropH<<16)/dstH + 1;
-
+ zoomindstxIntInv = ((unsigned long)(cropW)<<16)/dstW + 1;
+ zoomindstyIntInv = ((unsigned long)(cropH)<<16)/dstH + 1;
+#ifdef CONFIG_SOC_RK3028
+ shift_bits = (pcdev->chip_id == 0x42)?0:2;
+#endif
//y
//for(y = 0; y<dstH - 1 ; y++ ) {
for(y = 0; y<dstH; y++ ) {
yCoeff00 = (y*zoomindstyIntInv)&0xffff;
yCoeff01 = 0xffff - yCoeff00;
sY = (y*zoomindstyIntInv >> 16);
-
+ sY = (sY >= srcH - 1)? (srcH - 2) : sY;
for(x = 0; x<dstW; x++ ) {
xCoeff00 = (x*zoomindstxIntInv)&0xffff;
xCoeff01 = 0xffff - xCoeff00;
sX = (x*zoomindstxIntInv >> 16);
-
- a = psY[sY*srcW + sX];
- b = psY[sY*srcW + sX + 1];
- c = psY[(sY+1)*srcW + sX];
- d = psY[(sY+1)*srcW + sX + 1];
+ sX = (sX >= srcW -1)?(srcW- 2) : sX;
+ a = (psY[sY*srcW + sX]<<shift_bits);
+ b = (psY[sY*srcW + sX + 1]<<shift_bits);
+ c = (psY[(sY+1)*srcW + sX]<<shift_bits);
+ d = (psY[(sY+1)*srcW + sX + 1]<<shift_bits);
r0 = (a * xCoeff01 + b * xCoeff00)>>16 ;
r1 = (c * xCoeff01 + d * xCoeff00)>>16 ;
yCoeff00 = (y*zoomindstyIntInv)&0xffff;
yCoeff01 = 0xffff - yCoeff00;
sY = (y*zoomindstyIntInv >> 16);
-
+ sY = (sY >= srcH -1)? (srcH - 2) : sY;
for(x = 0; x<dstW; x++ ) {
xCoeff00 = (x*zoomindstxIntInv)&0xffff;
xCoeff01 = 0xffff - xCoeff00;
sX = (x*zoomindstxIntInv >> 16);
-
+ sX = (sX >= srcW -1)?(srcW- 2) : sX;
//U
- a = psUV[(sY*srcW + sX)*2];
- b = psUV[(sY*srcW + sX + 1)*2];
- c = psUV[((sY+1)*srcW + sX)*2];
- d = psUV[((sY+1)*srcW + sX + 1)*2];
+ a = (psUV[(sY*srcW + sX)*2]<<shift_bits);
+ b = (psUV[(sY*srcW + sX + 1)*2]<<shift_bits);
+ c = (psUV[((sY+1)*srcW + sX)*2]<<shift_bits);
+ d = (psUV[((sY+1)*srcW + sX + 1)*2]<<shift_bits);
+
r0 = (a * xCoeff01 + b * xCoeff00)>>16 ;
r1 = (c * xCoeff01 + d * xCoeff00)>>16 ;
pdUV[x*2] = r0;
//V
- a = psUV[(sY*srcW + sX)*2 + 1];
- b = psUV[(sY*srcW + sX + 1)*2 + 1];
- c = psUV[((sY+1)*srcW + sX)*2 + 1];
- d = psUV[((sY+1)*srcW + sX + 1)*2 + 1];
-
+ a = (psUV[(sY*srcW + sX)*2 + 1]<<shift_bits);
+ b = (psUV[(sY*srcW + sX + 1)*2 + 1]<<shift_bits);
+ c = (psUV[((sY+1)*srcW + sX)*2 + 1]<<shift_bits);
+ d = (psUV[((sY+1)*srcW + sX + 1)*2 + 1]<<shift_bits);
+
r0 = (a * xCoeff01 + b * xCoeff00)>>16 ;
r1 = (c * xCoeff01 + d * xCoeff00)>>16 ;
r0 = (r0 * yCoeff01 + r1 * yCoeff00)>>16;
}
pdUV += dstW*2;
}
-
-rk_camera_scale_crop_arm_end:
-
+
dmac_flush_range((void*)src,(void*)(src+pcdev->vipmem_bsize));
outer_flush_range((phys_addr_t)src_phy,(phys_addr_t)(src_phy+pcdev->vipmem_bsize));
return ret;
}
-#endif
static void rk_camera_capture_process(struct work_struct *work)
{
struct rk_camera_work *camera_work = container_of(work, struct rk_camera_work, work);
unsigned long flags = 0;
int err = 0;
- if (!CAM_WORKQUEUE_IS_EN())
+ if (atomic_read(&pcdev->stop_cif)==true) {
+ err = -EINVAL;
+ goto rk_camera_capture_process_end;
+ }
+
+ if (!CAM_WORKQUEUE_IS_EN()) {
+ err = -EINVAL;
goto rk_camera_capture_process_end;
+ }
down(&pcdev->zoominfo.sem);
if (pcdev->icd_cb.scale_crop_cb){
vb->state = VIDEOBUF_DONE;
vb->field_count++;
}
- }
- wake_up(&(camera_work->vb->done));
+ }
spin_lock_irqsave(&pcdev->camera_work_lock, flags);
list_add_tail(&camera_work->queue, &pcdev->camera_work_queue);
- spin_unlock_irqrestore(&pcdev->camera_work_lock, flags);
+ spin_unlock_irqrestore(&pcdev->camera_work_lock, flags);
+ wake_up(&(camera_work->vb->done)); /* ddl@rock-chips.com : v0.3.9 */
return;
}
-static irqreturn_t rk_camera_irq(int irq, void *data)
+
+static void rk_camera_cifrest_delay(struct work_struct *work)
+{
+ struct rk_camera_work *camera_work = container_of(work, struct rk_camera_work, work);
+ struct rk_camera_dev *pcdev = camera_work->pcdev;
+ unsigned long flags = 0;
+
+ mdelay(1);
+ rk_camera_cif_reset(pcdev,false);
+
+ spin_lock_irqsave(&pcdev->camera_work_lock, flags);
+ list_add_tail(&camera_work->queue, &pcdev->camera_work_queue);
+ spin_unlock_irqrestore(&pcdev->camera_work_lock, flags);
+
+ spin_lock_irqsave(&pcdev->lock,flags);
+ if (atomic_read(&pcdev->stop_cif) == false) {
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, (read_cif_reg(pcdev->base,CIF_CIF_CTRL) | ENABLE_CAPTURE));
+ RKCAMERA_DG2("After reset cif, enable capture again!\n");
+ }
+ spin_unlock_irqrestore(&pcdev->lock,flags);
+ return;
+}
+
+static inline irqreturn_t rk_camera_cifirq(int irq, void *data)
+{
+ struct rk_camera_dev *pcdev = data;
+ struct rk_camera_work *wk;
+ unsigned int reg_cifctrl,reg_lastpix,reg_lastline;
+
+ write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0x0200); /* clear vip interrupte single */
+
+ reg_cifctrl = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
+ reg_lastpix = read_cif_reg(pcdev->base,CIF_CIF_LAST_PIX);
+ reg_lastline = read_cif_reg(pcdev->base,CIF_CIF_LAST_LINE);
+
+ pcdev->irqinfo.cifirq_idx++;
+ if ((reg_lastline != pcdev->host_height) /*|| (reg_lastpix != pcdev->host_width)*/) {
+ pcdev->irqinfo.cifirq_abnormal_idx = pcdev->irqinfo.cifirq_idx;
+ RKCAMERA_DG2("Cif irq-%ld is error, %dx%d != %dx%d\n",pcdev->irqinfo.cifirq_abnormal_idx,
+ reg_lastpix,reg_lastline,pcdev->host_width,pcdev->host_height);
+ } else {
+ pcdev->irqinfo.cifirq_normal_idx = pcdev->irqinfo.cifirq_idx;
+ }
+
+ if(reg_cifctrl & ENABLE_CAPTURE) {
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, (reg_cifctrl & ~ENABLE_CAPTURE));
+ }
+
+ if (pcdev->irqinfo.cifirq_abnormal_idx>0) {
+ if ((pcdev->irqinfo.cifirq_idx - pcdev->irqinfo.cifirq_abnormal_idx) == 1 ) {
+ if (!list_empty(&pcdev->camera_work_queue)) {
+ RKCAMERA_DG2("Receive cif irq-%ld and queue work to cif reset\n",pcdev->irqinfo.cifirq_idx);
+ wk = list_entry(pcdev->camera_work_queue.next, struct rk_camera_work, queue);
+ list_del_init(&wk->queue);
+ INIT_WORK(&(wk->work), rk_camera_cifrest_delay);
+ wk->pcdev = pcdev;
+ queue_work(pcdev->camera_wq, &(wk->work));
+ }
+ }
+ }
+
+ return IRQ_HANDLED;
+}
+
+static inline irqreturn_t rk_camera_dmairq(int irq, void *data)
{
struct rk_camera_dev *pcdev = data;
struct videobuf_buffer *vb;
struct rk_camera_work *wk;
struct timeval tv;
- unsigned long tmp_intstat;
- unsigned long tmp_cifctrl;
-
- tmp_intstat = read_cif_reg(pcdev->base,CIF_CIF_INTSTAT);
- tmp_cifctrl = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
- if(pcdev->stop_cif == true)
- {
- printk("cif has stopped by app,needn't to deal this irq\n");
- write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0xFFFFFFFF); /* clear vip interrupte single */
- return IRQ_HANDLED;
- }
- if ((tmp_intstat & 0x0200) /*&& ((tmp_intstat & 0x1)==0)*/){//bit9 =1 ,bit0 = 0
- write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0x0200); /* clear vip interrupte single */
- if(tmp_cifctrl & ENABLE_CAPTURE)
- write_cif_reg(pcdev->base,CIF_CIF_CTRL, (tmp_cifctrl & ~ENABLE_CAPTURE));
- return IRQ_HANDLED;
- }
-
+ unsigned long reg_cifctrl;
+
+ reg_cifctrl = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
/* ddl@rock-chps.com : Current VIP is run in One Frame Mode, Frame 1 is validate */
if (read_cif_reg(pcdev->base,CIF_CIF_FRAME_STATUS) & 0x01) {
- write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0x01); /* clear vip interrupte single */
+ write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0x01); /* clear vip interrupte single */
+
+ pcdev->irqinfo.dmairq_idx++;
+ if (pcdev->irqinfo.cifirq_abnormal_idx == pcdev->irqinfo.dmairq_idx) {
+ write_cif_reg(pcdev->base,CIF_CIF_FRAME_STATUS, 0x00000002);
+ goto end;
+ }
+
if (!pcdev->fps) {
do_gettimeofday(&pcdev->first_tv);
}
- pcdev->fps++;
- if (!pcdev->active)
- goto RK_CAMERA_IRQ_END;
+ pcdev->fps++;
+ if (!pcdev->active)
+ goto end;
if (pcdev->frame_inval>0) {
pcdev->frame_inval--;
rk_videobuf_capture(pcdev->active,pcdev);
- goto RK_CAMERA_IRQ_END;
+ goto end;
} else if (pcdev->frame_inval) {
- RKCAMERA_TR("frame_inval : %0x",pcdev->frame_inval);
+ RKCAMERA_TR("frame_inval : %0x",pcdev->frame_inval);
pcdev->frame_inval = 0;
}
+
if(pcdev->fps == RK30_CAM_FRAME_MEASURE) {
do_gettimeofday(&tv);
pcdev->frame_interval = ((tv.tv_sec*1000000 + tv.tv_usec) - (pcdev->first_tv.tv_sec*1000000 + pcdev->first_tv.tv_usec))
- /(RK30_CAM_FRAME_MEASURE-1);
+ /(RK30_CAM_FRAME_MEASURE-1);
}
+
vb = pcdev->active;
- if(!vb){
+ if (!vb) {
printk("no acticve buffer!!!\n");
- goto RK_CAMERA_IRQ_END;
- }
- /* ddl@rock-chips.com : this vb may be deleted from queue */
- if ((vb->state == VIDEOBUF_QUEUED) || (vb->state == VIDEOBUF_ACTIVE)) {
- list_del_init(&vb->queue);
- }
+ goto end;
+ }
+
+ /* ddl@rock-chips.com : this vb may be deleted from queue */
+ if ((vb->state == VIDEOBUF_QUEUED) || (vb->state == VIDEOBUF_ACTIVE)) {
+ list_del_init(&vb->queue);
+ }
pcdev->active = NULL;
if (!list_empty(&pcdev->capture)) {
pcdev->active = list_entry(pcdev->capture.next, struct videobuf_buffer, queue);
- if (pcdev->active) {
+ if (pcdev->active) {
WARN_ON(pcdev->active->state != VIDEOBUF_QUEUED);
- rk_videobuf_capture(pcdev->active,pcdev);
- }
+ rk_videobuf_capture(pcdev->active,pcdev);
+ }
}
if (pcdev->active == NULL) {
- RKCAMERA_DG("%s video_buf queue is empty!\n",__FUNCTION__);
- }
+ RKCAMERA_DG1("video_buf queue is empty!\n");
+ }
do_gettimeofday(&vb->ts);
- if (CAM_WORKQUEUE_IS_EN()) {
+ if (CAM_WORKQUEUE_IS_EN()) {
if (!list_empty(&pcdev->camera_work_queue)) {
wk = list_entry(pcdev->camera_work_queue.next, struct rk_camera_work, queue);
list_del_init(&wk->queue);
INIT_WORK(&(wk->work), rk_camera_capture_process);
- wk->vb = vb;
- wk->pcdev = pcdev;
- queue_work(pcdev->camera_wq, &(wk->work));
+ wk->vb = vb;
+ wk->pcdev = pcdev;
+ queue_work(pcdev->camera_wq, &(wk->work));
}
- } else {
- if ((vb->state == VIDEOBUF_QUEUED) || (vb->state == VIDEOBUF_ACTIVE)) {
- vb->state = VIDEOBUF_DONE;
- vb->field_count++;
- }
- wake_up(&vb->done);
- }
-
+ } else {
+ if ((vb->state == VIDEOBUF_QUEUED) || (vb->state == VIDEOBUF_ACTIVE)) {
+ vb->state = VIDEOBUF_DONE;
+ vb->field_count++;
+ }
+ wake_up(&vb->done);
+ }
}
-RK_CAMERA_IRQ_END:
- if((tmp_cifctrl & ENABLE_CAPTURE) == 0)
- write_cif_reg(pcdev->base,CIF_CIF_CTRL, (tmp_cifctrl | ENABLE_CAPTURE));
+end:
+ if((reg_cifctrl & ENABLE_CAPTURE) == 0)
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, (reg_cifctrl | ENABLE_CAPTURE));
+ return IRQ_HANDLED;
+}
+
+static irqreturn_t rk_camera_irq(int irq, void *data)
+{
+ struct rk_camera_dev *pcdev = data;
+ unsigned long reg_intstat;
+
+ spin_lock(&pcdev->lock);
+
+ if(atomic_read(&pcdev->stop_cif) == true) {
+ write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0xffffffff);
+ goto end;
+ }
+
+ reg_intstat = read_cif_reg(pcdev->base,CIF_CIF_INTSTAT);
+
+ if (reg_intstat & 0x0200)
+ rk_camera_cifirq(irq,data);
+
+ if (reg_intstat & 0x01)
+ rk_camera_dmairq(irq,data);
+
+end:
+ spin_unlock(&pcdev->lock);
return IRQ_HANDLED;
}
struct soc_camera_device *icd = vq->priv_data;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct rk_camera_dev *pcdev = ici->priv;
+#if CAMERA_VIDEOBUF_ARM_ACCESS
struct rk29_camera_vbinfo *vb_info =NULL;
+#endif
+
#ifdef DEBUG
dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
vb, vb->baddr, vb->bsize);
break;
}
#endif
- if (vb == pcdev->active) {
- RKCAMERA_DG("%s Wait for this video buf(0x%x) write finished!\n ",__FUNCTION__,(unsigned int)vb);
- interruptible_sleep_on_timeout(&vb->done, msecs_to_jiffies(500));
- RKCAMERA_DG("%s This video buf(0x%x) write finished, release now!!\n",__FUNCTION__,(unsigned int)vb);
- }
flush_workqueue(pcdev->camera_wq);
+
+ rk_videobuf_free(vq, buf);
+
#if CAMERA_VIDEOBUF_ARM_ACCESS
- if (pcdev->vbinfo) {
+ if ((pcdev->vbinfo) && (vb->i < pcdev->vbinfo_count)) {
vb_info = pcdev->vbinfo + vb->i;
if (vb_info->vir_addr) {
}
}
-#endif
- rk_videobuf_free(vq, buf);
+#endif
}
static struct videobuf_queue_ops rk_videobuf_ops =
sizeof(struct rk_camera_buffer),
icd,&icd->video_lock);
}
-static int rk_camera_activate(struct rk_camera_dev *pcdev, struct soc_camera_device *icd)
+
+static int rk_camera_mclk_ctrl(int cif_idx, int on, int clk_rate)
{
- int err = 0;
+ int err = 0,cif;
+ struct rk_cif_clk *clk;
+ struct clk *cif_clk_out_div;
- if(!pcdev->aclk_cif || !pcdev->hclk_cif || !pcdev->cif_clk_in || !pcdev->cif_clk_out){
+ cif = cif_idx - RK29_CAM_PLATFORM_DEV_ID;
+ if ((cif<0)||(cif>1)) {
+ RKCAMERA_TR(KERN_ERR "cif index(%d) is invalidate\n",cif_idx);
+ err = -1;
+ goto rk_camera_clk_ctrl_end;
+ }
+
+ clk = &cif_clk[cif];
+
+ if(!clk->aclk_cif || !clk->hclk_cif || !clk->cif_clk_in || !clk->cif_clk_out) {
RKCAMERA_TR(KERN_ERR "failed to get cif clock source\n");
err = -ENOENT;
- goto RK_CAMERA_ACTIVE_ERR;
+ goto rk_camera_clk_ctrl_end;
+ }
+
+ spin_lock(&clk->lock);
+ if (on && !clk->on) {
+ clk_enable(clk->pd_cif);
+ clk_enable(clk->aclk_cif);
+ clk_enable(clk->hclk_cif);
+ clk_enable(clk->cif_clk_in);
+ clk_enable(clk->cif_clk_out);
+ clk_set_rate(clk->cif_clk_out,clk_rate);
+ clk->on = true;
+ } else if (!on && clk->on) {
+ clk_disable(clk->aclk_cif);
+ clk_disable(clk->hclk_cif);
+ clk_disable(clk->cif_clk_in);
+ clk_disable(clk->cif_clk_out);
+ clk_disable(clk->pd_cif);
+ clk->on = false;
+ if(cif){
+ cif_clk_out_div = clk_get(NULL, "cif1_out_div");
+ }else{
+ cif_clk_out_div = clk_get(NULL, "cif0_out_div");
+ if(IS_ERR_OR_NULL(cif_clk_out_div)) {
+ cif_clk_out_div = clk_get(NULL, "cif_out_div");
+ }
}
-
- clk_enable(pcdev->pd_cif);
- clk_enable(pcdev->aclk_cif);
-
- clk_enable(pcdev->hclk_cif);
- clk_enable(pcdev->cif_clk_in);
-
- //if (icd->ops->query_bus_param) /* ddl@rock-chips.com : Query Sensor's xclk */
- //sensor_bus_flags = icd->ops->query_bus_param(icd);
- clk_enable(pcdev->cif_clk_out);
- clk_set_rate(pcdev->cif_clk_out,RK_SENSOR_24MHZ);
-
- ndelay(10);
- //soft reset the registers
- #if 0 //has somthing wrong when suspend and resume now
- if(IS_CIF0()){
- printk("before set cru register reset cif0 0x%x\n\n",read_cru_reg(CRU_CIF_RST_REG30));
- //dump regs
- {
- printk("CIF_CIF_CTRL = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_CTRL));
- printk("CIF_CIF_INTEN = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_INTEN));
- printk("CIF_CIF_INTSTAT = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_INTSTAT));
- printk("CIF_CIF_FOR = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_FOR));
- printk("CIF_CIF_CROP = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_CROP));
- printk("CIF_CIF_SET_SIZE = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_SET_SIZE));
- printk("CIF_CIF_SCL_CTRL = 0x%x\n",read_cif_reg(pcdev->base,CIF_CIF_SCL_CTRL));
- printk("CRU_PCLK_REG30 = 0X%x\n",read_cru_reg(CRU_PCLK_REG30));
- printk("CIF_CIF_LAST_LINE = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_LAST_LINE));
-
- printk("CIF_CIF_LAST_PIX = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_LAST_PIX));
- printk("CIF_CIF_VIR_LINE_WIDTH = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH));
- printk("CIF_CIF_LINE_NUM_ADDR = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_LINE_NUM_ADDR));
- printk("CIF_CIF_FRM0_ADDR_Y = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_FRM0_ADDR_Y));
- printk("CIF_CIF_FRM0_ADDR_UV = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_FRM0_ADDR_UV));
- printk("CIF_CIF_FRAME_STATUS = 0X%x\n\n",read_cif_reg(pcdev->base,CIF_CIF_FRAME_STATUS));
- }
-
- mdelay(100);
- write_cru_reg(CRU_CIF_RST_REG30,(/*read_cru_reg(CRU_CIF_RST_REG30)|*/MASK_RST_CIF0|RQUEST_RST_CIF0 ));
- printk("set cru register reset cif0 0x%x\n",read_cru_reg(CRU_CIF_RST_REG30));
- write_cru_reg(CRU_CIF_RST_REG30,(read_cru_reg(CRU_CIF_RST_REG30)&(~RQUEST_RST_CIF0)) | MASK_RST_CIF0);
- mdelay(1000);
- printk("clean cru register reset cif0 0x%x\n",read_cru_reg(CRU_CIF_RST_REG30));
- }else{
- write_cru_reg(CRU_CIF_RST_REG30,MASK_RST_CIF1|RQUEST_RST_CIF1 | (read_cru_reg(CRU_CIF_RST_REG30)));
- write_cru_reg(CRU_CIF_RST_REG30,(read_cru_reg(CRU_CIF_RST_REG30)&(~RQUEST_RST_CIF1)) | MASK_RST_CIF1);
+
+ if(IS_ERR_OR_NULL(cif_clk_out_div)) {
+ err = clk_set_parent(clk->cif_clk_out, cif_clk_out_div);
+ clk_put(cif_clk_out_div);
+ } else {
+ err = -1;
+ }
+
+ if(err)
+ RKCAMERA_TR("WARNING %s_%s_%d: camera sensor mclk maybe not close, please check!!!\n", __FILE__, __FUNCTION__, __LINE__);
}
- #endif
+ spin_unlock(&clk->lock);
+rk_camera_clk_ctrl_end:
+ return err;
+}
+static int rk_camera_activate(struct rk_camera_dev *pcdev, struct soc_camera_device *icd)
+{
+ /*
+ * ddl@rock-chips.com : Cif clk control in rk_sensor_power which in rk_camera.c
+ */
write_cif_reg(pcdev->base,CIF_CIF_CTRL,AXI_BURST_16|MODE_ONEFRAME|DISABLE_CAPTURE); /* ddl@rock-chips.com : vip ahb burst 16 */
write_cif_reg(pcdev->base,CIF_CIF_INTEN, 0x01); //capture complete interrupt enable
- RKCAMERA_DG("%s..%d.. CIF_CIF_CTRL = 0x%x\n",__FUNCTION__,__LINE__,read_cif_reg(pcdev->base, CIF_CIF_CTRL));
return 0;
-RK_CAMERA_ACTIVE_ERR:
- return -ENODEV;
}
static void rk_camera_deactivate(struct rk_camera_dev *pcdev)
-{
- clk_disable(pcdev->aclk_cif);
-
- clk_disable(pcdev->hclk_cif);
- clk_disable(pcdev->cif_clk_in);
-
- clk_disable(pcdev->cif_clk_out);
- clk_enable(pcdev->cif_clk_out);
- clk_set_rate(pcdev->cif_clk_out,48*1000*1000);
- clk_disable(pcdev->cif_clk_out);
+{
+ /*
+ * ddl@rock-chips.com : Cif clk control in rk_sensor_power which in rk_camera.c
+ */
- clk_disable(pcdev->pd_cif);
return;
}
struct v4l2_subdev *sd;
int ret,i,icd_catch;
struct rk_camera_frmivalenum *fival_list,*fival_nxt;
+ struct v4l2_cropcap cropcap;
+ struct v4l2_mbus_framefmt mf;
+ const struct soc_camera_format_xlate *xlate = NULL;
mutex_lock(&camera_lock);
goto ebusy;
}
- dev_info(&icd->dev, "RK Camera driver attached to camera%d(%s)\n",
- icd->devnum,dev_name(icd->pdev));
+ RKCAMERA_DG1("%s driver attached to %s\n",RK29_CAM_DRV_NAME,dev_name(icd->pdev));
pcdev->frame_inval = RK_CAM_FRAME_INVAL_INIT;
pcdev->active = NULL;
goto ebusy;
#endif
v4l2_subdev_call(sd, core, ioctl, RK29_CAM_SUBDEV_CB_REGISTER,(void*)(&pcdev->icd_cb));
+
+ if (v4l2_subdev_call(sd, video, cropcap, &cropcap) == 0) {
+ memcpy(&pcdev->cropinfo.bounds ,&cropcap.bounds,sizeof(struct v4l2_rect));
+ } else {
+ xlate = soc_camera_xlate_by_fourcc(icd, V4L2_PIX_FMT_NV12);
+ mf.width = 10000;
+ mf.height = 10000;
+ mf.field = V4L2_FIELD_NONE;
+ mf.code = xlate->code;
+ mf.reserved[6] = 0xfefe5a5a;
+ v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
+
+ pcdev->cropinfo.bounds.left = 0;
+ pcdev->cropinfo.bounds.top = 0;
+ pcdev->cropinfo.bounds.width = mf.width;
+ pcdev->cropinfo.bounds.height = mf.height;
+ }
}
pcdev->icd = icd;
pcdev->icd_init = 0;
-
+
icd_catch = 0;
for (i=0; i<2; i++) {
if (pcdev->icd_frmival[i].icd == icd)
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct rk_camera_dev *pcdev = ici->priv;
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+#if CAMERA_VIDEOBUF_ARM_ACCESS
struct rk29_camera_vbinfo *vb_info;
unsigned int i;
+#endif
mutex_lock(&camera_lock);
BUG_ON(icd != pcdev->icd);
- dev_info(&icd->dev, "RK Camera driver detached from camera%d(%s)\n",
- icd->devnum,dev_name(icd->pdev));
+ RKCAMERA_DG1("%s driver detached from %s\n",RK29_CAM_DRV_NAME,dev_name(icd->pdev));
/* ddl@rock-chips.com: Application will call VIDIOC_STREAMOFF before close device, but
stream may be turn on again before close device, if suspend and resume happened. */
if (read_cif_reg(pcdev->base,CIF_CIF_CTRL) & ENABLE_CAPTURE) {
rk_camera_s_stream(icd,0);
- }
+ }
- //soft reset the registers
- #if 0 //has somthing wrong when suspend and resume now
- if(IS_CIF0()){
- write_cru_reg(CRU_CIF_RST_REG30,MASK_RST_CIF0|RQUEST_RST_CIF0 | (read_cru_reg(CRU_CIF_RST_REG30)));
- write_cru_reg(CRU_CIF_RST_REG30,(read_cru_reg(CRU_CIF_RST_REG30)&(~RQUEST_RST_CIF0)) | MASK_RST_CIF0);
- }else{
- write_cru_reg(CRU_CIF_RST_REG30,MASK_RST_CIF1|RQUEST_RST_CIF1 | (read_cru_reg(CRU_CIF_RST_REG30)));
- write_cru_reg(CRU_CIF_RST_REG30,(read_cru_reg(CRU_CIF_RST_REG30)&(~RQUEST_RST_CIF1)) | MASK_RST_CIF1);
- }
- #endif
v4l2_subdev_call(sd, core, ioctl, RK29_CAM_SUBDEV_DEACTIVATE,NULL);
//if stream off is not been executed,timer is running.
if(pcdev->fps_timer.istarted){
INIT_LIST_HEAD(&pcdev->capture);
mutex_unlock(&camera_lock);
- RKCAMERA_DG("%s exit\n",__FUNCTION__);
return;
}
static int rk_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
{
unsigned long bus_flags, camera_flags, common_flags;
- unsigned int cif_ctrl_val = 0;
+ unsigned int cif_for = 0;
const struct soc_mbus_pixelfmt *fmt;
int ret = 0;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct rk_camera_dev *pcdev = ici->priv;
- RKCAMERA_DG("%s..%d..\n",__FUNCTION__,__LINE__);
+
fmt = soc_mbus_get_fmtdesc(icd->current_fmt->code);
if (!fmt)
if (ret < 0)
goto RK_CAMERA_SET_BUS_PARAM_END;
- cif_ctrl_val = read_cif_reg(pcdev->base,CIF_CIF_FOR);
- RKCAMERA_DG("%s..%d..cif_ctrl_val = 0x%x\n",__FUNCTION__,__LINE__,cif_ctrl_val);
+ cif_for = read_cif_reg(pcdev->base,CIF_CIF_FOR);
+
if (common_flags & SOCAM_PCLK_SAMPLE_FALLING) {
if(IS_CIF0()) {
write_cru_reg(CRU_PCLK_REG30, read_cru_reg(CRU_PCLK_REG30) | ENANABLE_INVERT_PCLK_CIF0);
- RKCAMERA_DG("enable cif0 pclk invert\n");
} else {
write_cru_reg(CRU_PCLK_REG30, read_cru_reg(CRU_PCLK_REG30) | ENANABLE_INVERT_PCLK_CIF1);
- RKCAMERA_DG("enable cif1 pclk invert\n");
}
} else {
if(IS_CIF0()){
write_cru_reg(CRU_PCLK_REG30, (read_cru_reg(CRU_PCLK_REG30) & 0xFFFFEFF ) | DISABLE_INVERT_PCLK_CIF0);
- RKCAMERA_DG("diable cif0 pclk invert\n");
} else {
write_cru_reg(CRU_PCLK_REG30, (read_cru_reg(CRU_PCLK_REG30) & 0xFFFEFFF) | DISABLE_INVERT_PCLK_CIF1);
- RKCAMERA_DG("diable cif1 pclk invert\n");
}
}
if (common_flags & SOCAM_HSYNC_ACTIVE_LOW) {
- cif_ctrl_val |= HSY_LOW_ACTIVE;
+ cif_for |= HSY_LOW_ACTIVE;
} else {
- cif_ctrl_val &= ~HSY_LOW_ACTIVE;
+ cif_for &= ~HSY_LOW_ACTIVE;
}
if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH) {
- cif_ctrl_val |= VSY_HIGH_ACTIVE;
+ cif_for |= VSY_HIGH_ACTIVE;
} else {
- cif_ctrl_val &= ~VSY_HIGH_ACTIVE;
+ cif_for &= ~VSY_HIGH_ACTIVE;
}
/* ddl@rock-chips.com : Don't enable capture here, enable in stream_on */
//vip_ctrl_val |= ENABLE_CAPTURE;
- write_cif_reg(pcdev->base,CIF_CIF_FOR, cif_ctrl_val);
- RKCAMERA_DG("%s..ctrl:0x%x CIF_CIF_FOR=%x \n",__FUNCTION__,cif_ctrl_val,read_cif_reg(pcdev->base,CIF_CIF_FOR));
+ write_cif_reg(pcdev->base,CIF_CIF_FOR, cif_for);
+ RKCAMERA_DG1("CIF_CIF_FOR: 0x%x \n",cif_for);
RK_CAMERA_SET_BUS_PARAM_END:
if (ret)
- RKCAMERA_TR("\n%s..%d.. ret = %d \n",__FUNCTION__,__LINE__, ret);
+ RKCAMERA_TR("rk_camera_set_bus_param ret = %d \n", ret);
return ret;
}
cif_fmt_val = YUV_INPUT_ORDER_YUYV(cif_fmt_val);
break;
}
-#if 1
- {
-#ifdef CONFIG_ARCH_RK30
- mdelay(100);
- if(IS_CIF0()){
- // pmu_set_idle_request(IDLE_REQ_VIO, true);
- cru_set_soft_reset(SOFT_RST_CIF0, true);
- udelay(5);
- cru_set_soft_reset(SOFT_RST_CIF0, false);
- // pmu_set_idle_request(IDLE_REQ_VIO, false);
-
- }else{
- // pmu_set_idle_request(IDLE_REQ_VIO, true);
- cru_set_soft_reset(SOFT_RST_CIF1, true);
- udelay(5);
- cru_set_soft_reset(SOFT_RST_CIF1, false);
- // pmu_set_idle_request(IDLE_REQ_VIO, false);
- }
-#endif
- }
+
+ mdelay(100);
+ rk_camera_cif_reset(pcdev,true);
+
write_cif_reg(pcdev->base,CIF_CIF_CTRL,AXI_BURST_16|MODE_ONEFRAME|DISABLE_CAPTURE); /* ddl@rock-chips.com : vip ahb burst 16 */
write_cif_reg(pcdev->base,CIF_CIF_INTEN, 0x01|0x200); //capture complete interrupt enable
-#endif
+
write_cif_reg(pcdev->base,CIF_CIF_FOR,cif_fmt_val); /* ddl@rock-chips.com: VIP capture mode and capture format must be set before FS register set */
- // read_cif_reg(pcdev->base,CIF_CIF_INTSTAT); /* clear vip interrupte single */
write_cif_reg(pcdev->base,CIF_CIF_INTSTAT,0xFFFFFFFF);
if((read_cif_reg(pcdev->base,CIF_CIF_CTRL) & MODE_PINGPONG)
||(read_cif_reg(pcdev->base,CIF_CIF_CTRL) & MODE_LINELOOP)) {
BUG();
- } else{ // this is one frame mode
- cif_crop = (rect->left+ (rect->top<<16));
- cif_fs = ((rect->width ) + (rect->height<<16));
- }
- RKCAMERA_TR("%s..%d.. \n",__FUNCTION__,__LINE__);
+ } else{ // this is one frame mode
+ cif_crop = (rect->left+ (rect->top<<16));
+ cif_fs = ((rect->width ) + (rect->height<<16));
+ }
write_cif_reg(pcdev->base,CIF_CIF_CROP, cif_crop);
write_cif_reg(pcdev->base,CIF_CIF_SET_SIZE, cif_fs);
//MUST bypass scale
write_cif_reg(pcdev->base,CIF_CIF_SCL_CTRL,0x10);
- RKCAMERA_DG("%s.. crop:0x%x fs:0x%x cif_fmt_val:0x%x CIF_CIF_FOR:0x%x\n",__FUNCTION__,cif_crop,cif_fs,cif_fmt_val,read_cif_reg(pcdev->base,CIF_CIF_FOR));
+ RKCAMERA_DG1("CIF_CIF_CROP:0x%x CIF_CIF_FS:0x%x CIF_CIF_FOR:0x%x\n",cif_crop,cif_fs,cif_fmt_val);
return;
}
return 0;
switch (code) {
- case V4L2_MBUS_FMT_UYVY8_2X8:
- case V4L2_MBUS_FMT_YUYV8_2X8:
- case V4L2_MBUS_FMT_YVYU8_2X8:
- case V4L2_MBUS_FMT_VYUY8_2X8:
+ case V4L2_MBUS_FMT_UYVY8_2X8:
+ case V4L2_MBUS_FMT_YUYV8_2X8:
+ case V4L2_MBUS_FMT_YVYU8_2X8:
+ case V4L2_MBUS_FMT_VYUY8_2X8:
+ {
+
#if (CONFIG_CAMERA_SCALE_CROP_MACHINE != RK_CAM_SCALE_CROP_RGA)
- formats++;
- if (xlate) {
- xlate->host_fmt = &rk_camera_formats[0];
- xlate->code = code;
- xlate++;
- dev_dbg(dev, "Providing format %s using code %d\n",
- rk_camera_formats[0].name,code);
- }
-
- formats++;
- if (xlate) {
- xlate->host_fmt = &rk_camera_formats[1];
- xlate->code = code;
- xlate++;
- dev_dbg(dev, "Providing format %s using code %d\n",
- rk_camera_formats[1].name,code);
- }
-
- formats++;
- if (xlate) {
- xlate->host_fmt = &rk_camera_formats[2];
- xlate->code = code;
- xlate++;
- dev_dbg(dev, "Providing format %s using code %d\n",
- rk_camera_formats[2].name,code);
- }
-
- formats++;
- if (xlate) {
- xlate->host_fmt = &rk_camera_formats[3];
- xlate->code = code;
- xlate++;
- dev_dbg(dev, "Providing format %s using code %d\n",
- rk_camera_formats[3].name,code);
- }
- break;
+ formats++;
+ if (xlate) {
+ xlate->host_fmt = &rk_camera_formats[0];
+ xlate->code = code;
+ xlate++;
+ dev_dbg(dev, "Providing format %s using code %d\n",
+ rk_camera_formats[0].name,code);
+ }
+
+ formats++;
+ if (xlate) {
+ xlate->host_fmt = &rk_camera_formats[1];
+ xlate->code = code;
+ xlate++;
+ dev_dbg(dev, "Providing format %s using code %d\n",
+ rk_camera_formats[1].name,code);
+ }
+
+ formats++;
+ if (xlate) {
+ xlate->host_fmt = &rk_camera_formats[2];
+ xlate->code = code;
+ xlate++;
+ dev_dbg(dev, "Providing format %s using code %d\n",
+ rk_camera_formats[2].name,code);
+ }
+
+ formats++;
+ if (xlate) {
+ xlate->host_fmt = &rk_camera_formats[3];
+ xlate->code = code;
+ xlate++;
+ dev_dbg(dev, "Providing format %s using code %d\n",
+ rk_camera_formats[3].name,code);
+ }
+ break;
#else
- formats++;
- if (xlate) {
- xlate->host_fmt = &rk_camera_formats[4];
- xlate->code = code;
- xlate++;
- dev_dbg(dev, "Providing format %s using code %d\n",
- rk_camera_formats[4].name,code);
- }
- formats++;
- if (xlate) {
- xlate->host_fmt = &rk_camera_formats[5];
- xlate->code = code;
- xlate++;
- dev_dbg(dev, "Providing format %s using code %d\n",
- rk_camera_formats[5].name,code);
- }
+ formats++;
+ if (xlate) {
+ xlate->host_fmt = &rk_camera_formats[4];
+ xlate->code = code;
+ xlate++;
+ dev_dbg(dev, "Providing format %s using code %d\n",
+ rk_camera_formats[4].name,code);
+ }
+ formats++;
+ if (xlate) {
+ xlate->host_fmt = &rk_camera_formats[5];
+ xlate->code = code;
+ xlate++;
+ dev_dbg(dev, "Providing format %s using code %d\n",
+ rk_camera_formats[5].name,code);
+ }
break;
#endif
+ }
default:
break;
}
{
return;
}
-
-static int rk_camera_set_crop(struct soc_camera_device *icd,
- struct v4l2_crop *a)
+static int rk_camera_cropcap(struct soc_camera_device *icd, struct v4l2_cropcap *cropcap)
{
struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
- struct v4l2_mbus_framefmt mf;
- u32 fourcc = icd->current_fmt->host_fmt->fourcc;
- int ret;
-
- ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
- if (ret < 0)
- return ret;
-
- if ((mf.width < (a->c.left + a->c.width)) || (mf.height < (a->c.top + a->c.height))) {
-
- mf.width = a->c.left + a->c.width;
- mf.height = a->c.top + a->c.height;
-
- v4l_bound_align_image(&mf.width, RK_CAM_W_MIN, RK_CAM_W_MAX, 1,
- &mf.height, RK_CAM_H_MIN, RK_CAM_H_MAX, 0,
- fourcc == V4L2_PIX_FMT_NV16 ?4 : 0);
-
- ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
- if (ret < 0)
- return ret;
- }
-
- rk_camera_setup_format(icd, fourcc, mf.code, &a->c);
+ int ret=0;
+
+ ret = v4l2_subdev_call(sd, video, cropcap, cropcap);
+ if (ret != 0)
+ goto end;
+ /* ddl@rock-chips.com: driver decide the cropping rectangle */
+ memset(&cropcap->defrect,0x00,sizeof(struct v4l2_rect));
+end:
+ return ret;
+}
+static int rk_camera_get_crop(struct soc_camera_device *icd,struct v4l2_crop *crop)
+{
+ struct soc_camera_host *ici =to_soc_camera_host(icd->dev.parent);
+ struct rk_camera_dev *pcdev = ici->priv;
- icd->user_width = mf.width;
- icd->user_height = mf.height;
+ spin_lock(&pcdev->cropinfo.lock);
+ memcpy(&crop->c,&pcdev->cropinfo.c,sizeof(struct v4l2_rect));
+ spin_unlock(&pcdev->cropinfo.lock);
+
+ return 0;
+}
+static int rk_camera_set_crop(struct soc_camera_device *icd,
+ struct v4l2_crop *crop)
+{
+ struct soc_camera_host *ici =to_soc_camera_host(icd->dev.parent);
+ struct rk_camera_dev *pcdev = ici->priv;
+ spin_lock(&pcdev->cropinfo.lock);
+ memcpy(&pcdev->cropinfo.c,&crop->c,sizeof(struct v4l2_rect));
+ spin_unlock(&pcdev->cropinfo.lock);
return 0;
}
+static bool rk_camera_fmt_capturechk(struct v4l2_format *f)
+{
+ bool ret = false;
+ if (f->fmt.pix.priv == 0xfefe5a5a) {
+ ret = true;
+ }
+
+ if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
+ ret = true;
+ } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
+ ret = true;
+ } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
+ ret = true;
+ } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
+ ret = true;
+ } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
+ ret = true;
+ } else if ((f->fmt.pix.width == 3264) && (f->fmt.pix.height == 2448)) {
+ ret = true;
+ }
+
+ if (ret == true)
+ RKCAMERA_DG1("%dx%d is capture format\n",f->fmt.pix.width, f->fmt.pix.height);
+ return ret;
+}
static int rk_camera_set_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
struct v4l2_pix_format *pix = &f->fmt.pix;
struct v4l2_mbus_framefmt mf;
struct v4l2_rect rect;
- int ret,usr_w,usr_h;
+ int ret,usr_w,usr_h,sensor_w,sensor_h;
int stream_on = 0;
-
+ int ratio, bounds_aspect;
+
usr_w = pix->width;
usr_h = pix->height;
- RKCAMERA_TR("%s enter width:%d height:%d\n",__FUNCTION__,usr_w,usr_h);
+
+ RKCAMERA_DG1("enter width:%d height:%d\n",usr_w,usr_h);
xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
if (!xlate) {
dev_err(dev, "Format %x not found\n", pix->pixelformat);
if (pcdev->icd_init == 0) {
v4l2_subdev_call(sd,core, init, 0);
pcdev->icd_init = 1;
+ return 0;
}
stream_on = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
if (stream_on & ENABLE_CAPTURE)
write_cif_reg(pcdev->base,CIF_CIF_CTRL, (stream_on & (~ENABLE_CAPTURE)));
-
- 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, video, s_mbus_fmt, &mf);
- if (mf.code != xlate->code)
- return -EINVAL;
- #ifdef CONFIG_VIDEO_RK29_WORK_IPP
+
+ mf.width = pix->width;
+ mf.height = pix->height;
+ mf.field = pix->field;
+ mf.colorspace = pix->colorspace;
+ mf.code = xlate->code;
+ mf.reserved[0] = pix->priv; /* ddl@rock-chips.com : v0.3.3 */
+ mf.reserved[1] = 0;
+
+ ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
+ if (mf.code != xlate->code)
+ return -EINVAL;
+
+ if ((pcdev->cropinfo.c.width == pcdev->cropinfo.bounds.width) &&
+ (pcdev->cropinfo.c.height == pcdev->cropinfo.bounds.height)) {
+ bounds_aspect = (pcdev->cropinfo.bounds.width*10/pcdev->cropinfo.bounds.height);
+ if ((mf.width*10/mf.height) != bounds_aspect) {
+ RKCAMERA_DG1("User request fov unchanged in %dx%d, But sensor %dx%d is croped, so switch to full resolution %dx%d\n",
+ usr_w,usr_h,mf.width, mf.height,pcdev->cropinfo.bounds.width,pcdev->cropinfo.bounds.height);
+
+ mf.width = pcdev->cropinfo.bounds.width/4;
+ mf.height = pcdev->cropinfo.bounds.height/4;
+
+ mf.field = pix->field;
+ mf.colorspace = pix->colorspace;
+ mf.code = xlate->code;
+ mf.reserved[0] = pix->priv;
+ mf.reserved[1] = 0;
+
+ ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
+ if (mf.code != xlate->code)
+ return -EINVAL;
+ }
+ }
+
+ sensor_w = mf.width;
+ sensor_h = mf.height;
+
+ ratio = ((mf.width*mf.reserved[1])/100)&(~0x03); // 4 align
+ mf.width -= ratio;
+
+ ratio = ((ratio*mf.height/mf.width)+1)&(~0x01); // 2 align
+ mf.height -= ratio;
+
if ((mf.width != usr_w) || (mf.height != usr_h)) {
- int ratio;
+
if (unlikely((mf.width <16) || (mf.width > 8190) || (mf.height < 16) || (mf.height > 8190))) {
RKCAMERA_TR("Senor and IPP both invalid source resolution(%dx%d)\n",mf.width,mf.height);
ret = -EINVAL;
goto RK_CAMERA_SET_FMT_END;
- }
+ }
if (unlikely((usr_w <16)||(usr_h < 16))) {
RKCAMERA_TR("Senor and IPP both invalid destination resolution(%dx%d)\n",usr_w,usr_h);
ret = -EINVAL;
goto RK_CAMERA_SET_FMT_END;
- }
- //need crop ?
- if((mf.width*10/mf.height) != (usr_w*10/usr_h)){
- ratio = ((mf.width*10/usr_w) >= (mf.height*10/usr_h))?(mf.height*10/usr_h):(mf.width*10/usr_w);
- pcdev->host_width = ratio*usr_w/10;
- pcdev->host_height = ratio*usr_h/10;
- //for ipp ,need 4 bit alligned.
- pcdev->host_width &= ~CROP_ALIGN_BYTES;
- pcdev->host_height &= ~CROP_ALIGN_BYTES;
- RKCAMERA_DG("ratio = %d ,host:%d*%d\n",ratio,pcdev->host_width,pcdev->host_height);
- }
- else{ // needn't crop ,just scaled by ipp
- pcdev->host_width = mf.width;
- pcdev->host_height = mf.height;
- }
- }
- else{
- pcdev->host_width = usr_w;
- pcdev->host_height = usr_h;
- }
- #else
- //according to crop and scale capability to change , here just cropt to user needed
- if (unlikely((mf.width <16) || (mf.width > 8190) || (mf.height < 16) || (mf.height > 8190))) {
- RKCAMERA_TR("Senor invalid source resolution(%dx%d)\n",mf.width,mf.height);
- ret = -EINVAL;
- goto RK_CAMERA_SET_FMT_END;
- }
- if (unlikely((usr_w <16)||(usr_h < 16))) {
- RKCAMERA_TR("Senor invalid destination resolution(%dx%d)\n",usr_w,usr_h);
- ret = -EINVAL;
- goto RK_CAMERA_SET_FMT_END;
- }
- pcdev->host_width = usr_w;
- pcdev->host_height = usr_h;
- #endif
+ }
+
+ spin_lock(&pcdev->cropinfo.lock);
+ if (((mf.width*10/mf.height) != (usr_w*10/usr_h))) {
+ if ((pcdev->cropinfo.c.width == 0)&&(pcdev->cropinfo.c.height == 0)) {
+ //Scale + Crop center is for keep aspect ratio unchange
+ ratio = ((mf.width*10/usr_w) >= (mf.height*10/usr_h))?(mf.height*10/usr_h):(mf.width*10/usr_w);
+ pcdev->host_width = ratio*usr_w/10;
+ pcdev->host_height = ratio*usr_h/10;
+ pcdev->host_width &= ~CROP_ALIGN_BYTES;
+ pcdev->host_height &= ~CROP_ALIGN_BYTES;
+
+ pcdev->host_left = ((sensor_w-pcdev->host_width )>>1);
+ pcdev->host_top = ((sensor_h-pcdev->host_height)>>1);
+ } else {
+ //Scale + crop(user define)
+ pcdev->host_width = pcdev->cropinfo.c.width*mf.width/pcdev->cropinfo.bounds.width;
+ pcdev->host_height = pcdev->cropinfo.c.height*mf.height/pcdev->cropinfo.bounds.height;
+ pcdev->host_left = (pcdev->cropinfo.c.left*mf.width/pcdev->cropinfo.bounds.width);
+ pcdev->host_top = (pcdev->cropinfo.c.top*mf.height/pcdev->cropinfo.bounds.height);
+ }
+
+ pcdev->host_left &= (~0x01);
+ pcdev->host_top &= (~0x01);
+ } else {
+ if ((pcdev->cropinfo.c.width == 0)&&(pcdev->cropinfo.c.height == 0)) {
+ //Crop Center for cif can work , then scale
+ pcdev->host_width = mf.width;
+ pcdev->host_height = mf.height;
+ pcdev->host_left = ((sensor_w - mf.width)>>1)&(~0x01);
+ pcdev->host_top = ((sensor_h - mf.height)>>1)&(~0x01);
+ } else {
+ //Crop center for cif can work + crop(user define), then scale
+ pcdev->host_width = pcdev->cropinfo.c.width*mf.width/pcdev->cropinfo.bounds.width;
+ pcdev->host_height = pcdev->cropinfo.c.height*mf.height/pcdev->cropinfo.bounds.height;
+ pcdev->host_left = (pcdev->cropinfo.c.left*mf.width/pcdev->cropinfo.bounds.width)+((sensor_w - mf.width)>>1);
+ pcdev->host_top = (pcdev->cropinfo.c.top*mf.height/pcdev->cropinfo.bounds.height)+((sensor_h - mf.height)>>1);
+ }
+
+ pcdev->host_left &= (~0x01);
+ pcdev->host_top &= (~0x01);
+ }
+ spin_unlock(&pcdev->cropinfo.lock);
+ } else {
+ spin_lock(&pcdev->cropinfo.lock);
+ if ((pcdev->cropinfo.c.width == 0)&&(pcdev->cropinfo.c.height == 0)) {
+ pcdev->host_width = mf.width;
+ pcdev->host_height = mf.height;
+ pcdev->host_left = 0;
+ pcdev->host_top = 0;
+ } else {
+ pcdev->host_width = pcdev->cropinfo.c.width*mf.width/pcdev->cropinfo.bounds.width;
+ pcdev->host_height = pcdev->cropinfo.c.height*mf.height/pcdev->cropinfo.bounds.height;
+ pcdev->host_left = (pcdev->cropinfo.c.left*mf.width/pcdev->cropinfo.bounds.width);
+ pcdev->host_top = (pcdev->cropinfo.c.top*mf.height/pcdev->cropinfo.bounds.height);
+ }
+ spin_unlock(&pcdev->cropinfo.lock);
+ }
+
icd->sense = NULL;
if (!ret) {
- RKCAMERA_DG("%s..%d.. host:%d*%d , sensor output:%d*%d,user demand:%d*%d\n",__FUNCTION__,__LINE__,
- pcdev->host_width,pcdev->host_height,mf.width,mf.height,usr_w,usr_h);
rect.width = pcdev->host_width;
rect.height = pcdev->host_height;
- rect.left = ((mf.width-pcdev->host_width )>>1)&(~0x01);
- rect.top = ((mf.height-pcdev->host_height)>>1)&(~0x01);
- pcdev->host_left = rect.left;
- pcdev->host_top = rect.top;
+ rect.left = pcdev->host_left;
+ rect.top = pcdev->host_top;
down(&pcdev->zoominfo.sem);
- #if CIF_DO_CROP
- pcdev->zoominfo.a.c.left = 0;
- pcdev->zoominfo.a.c.top = 0;
- pcdev->zoominfo.a.c.width = pcdev->host_width*100/pcdev->zoominfo.zoom_rate;
- pcdev->zoominfo.a.c.width &= ~CROP_ALIGN_BYTES;
- pcdev->zoominfo.a.c.height = pcdev->host_height*100/pcdev->zoominfo.zoom_rate;
- pcdev->zoominfo.a.c.height &= ~CROP_ALIGN_BYTES;
- pcdev->zoominfo.vir_width = pcdev->zoominfo.a.c.width;
- pcdev->zoominfo.vir_height = pcdev->zoominfo.a.c.height;
- //recalculate the CIF width & height
- rect.width = pcdev->zoominfo.a.c.width ;
- rect.height = pcdev->zoominfo.a.c.height;
- rect.left = (((pcdev->host_width - pcdev->zoominfo.a.c.width)>>1)&(~0x01))+pcdev->host_left;
- rect.top = (((pcdev->host_height - pcdev->zoominfo.a.c.height)>>1)&(~0x01))+pcdev->host_top;
- #else
- pcdev->zoominfo.a.c.width = pcdev->host_width*100/pcdev->zoominfo.zoom_rate;
- pcdev->zoominfo.a.c.width &= ~CROP_ALIGN_BYTES;
- pcdev->zoominfo.a.c.height = pcdev->host_height*100/pcdev->zoominfo.zoom_rate;
- pcdev->zoominfo.a.c.height &= ~CROP_ALIGN_BYTES;
- //now digital zoom use ipp to do crop and scale
- if(pcdev->zoominfo.zoom_rate != 100){
- pcdev->zoominfo.a.c.left = ((pcdev->host_width - pcdev->zoominfo.a.c.width)>>1)&(~0x01);
- pcdev->zoominfo.a.c.top = ((pcdev->host_height - pcdev->zoominfo.a.c.height)>>1)&(~0x01);
- }
- else{
- pcdev->zoominfo.a.c.left = 0;
- pcdev->zoominfo.a.c.top = 0;
- }
- pcdev->zoominfo.vir_width = pcdev->host_width;
- pcdev->zoominfo.vir_height = pcdev->host_height;
- #endif
+#if CIF_DO_CROP // this crop is only for digital zoom
+ pcdev->zoominfo.a.c.left = 0;
+ pcdev->zoominfo.a.c.top = 0;
+ pcdev->zoominfo.a.c.width = pcdev->host_width*100/pcdev->zoominfo.zoom_rate;
+ pcdev->zoominfo.a.c.width &= ~CROP_ALIGN_BYTES;
+ pcdev->zoominfo.a.c.height = pcdev->host_height*100/pcdev->zoominfo.zoom_rate;
+ pcdev->zoominfo.a.c.height &= ~CROP_ALIGN_BYTES;
+ pcdev->zoominfo.vir_width = pcdev->zoominfo.a.c.width;
+ pcdev->zoominfo.vir_height = pcdev->zoominfo.a.c.height;
+ //recalculate the CIF width & height
+ rect.width = pcdev->zoominfo.a.c.width ;
+ rect.height = pcdev->zoominfo.a.c.height;
+ rect.left = ((((pcdev->host_width - pcdev->zoominfo.a.c.width)>>1))+pcdev->host_left)&(~0x01);
+ rect.top = ((((pcdev->host_height - pcdev->zoominfo.a.c.height)>>1))+pcdev->host_top)&(~0x01);
+#else
+ pcdev->zoominfo.a.c.width = pcdev->host_width*100/pcdev->zoominfo.zoom_rate;
+ pcdev->zoominfo.a.c.width &= ~CROP_ALIGN_BYTES;
+ pcdev->zoominfo.a.c.height = pcdev->host_height*100/pcdev->zoominfo.zoom_rate;
+ pcdev->zoominfo.a.c.height &= ~CROP_ALIGN_BYTES;
+ //now digital zoom use ipp to do crop and scale
+ if(pcdev->zoominfo.zoom_rate != 100){
+ pcdev->zoominfo.a.c.left = ((pcdev->host_width - pcdev->zoominfo.a.c.width)>>1)&(~0x01);
+ pcdev->zoominfo.a.c.top = ((pcdev->host_height - pcdev->zoominfo.a.c.height)>>1)&(~0x01);
+ } else {
+ pcdev->zoominfo.a.c.left = 0;
+ pcdev->zoominfo.a.c.top = 0;
+ }
+ pcdev->zoominfo.vir_width = pcdev->host_width;
+ pcdev->zoominfo.vir_height = pcdev->host_height;
+#endif
up(&pcdev->zoominfo.sem);
/* ddl@rock-chips.com: IPP work limit check */
}
}
}
- RKCAMERA_DG("%s..%s icd width:%d user width:%d (zoom: %dx%d@(%d,%d)->%dx%d)\n",__FUNCTION__,xlate->host_fmt->name,
- rect.width, pix->width, pcdev->zoominfo.a.c.width,pcdev->zoominfo.a.c.height, pcdev->zoominfo.a.c.left,pcdev->zoominfo.a.c.top,
+
+ RKCAMERA_DG1("%s CIF Host:%dx%d@(%d,%d) Sensor:%dx%d->%dx%d User crop:(%d,%d,%d,%d)in(%d,%d) (zoom: %dx%d@(%d,%d)->%dx%d)\n",xlate->host_fmt->name,
+ pcdev->host_width,pcdev->host_height,pcdev->host_left,pcdev->host_top,
+ sensor_w,sensor_h,mf.width,mf.height,
+ pcdev->cropinfo.c.left,pcdev->cropinfo.c.top,pcdev->cropinfo.c.width,pcdev->cropinfo.c.height,
+ pcdev->cropinfo.bounds.width,pcdev->cropinfo.bounds.height,
+ pcdev->zoominfo.a.c.width,pcdev->zoominfo.a.c.height, pcdev->zoominfo.a.c.left,pcdev->zoominfo.a.c.top,
pix->width, pix->height);
+
rk_camera_setup_format(icd, pix->pixelformat, mf.code, &rect);
if (CAM_IPPWORK_IS_EN()) {
RKCAMERA_TR("\n%s..%d.. ret = %d \n",__FUNCTION__,__LINE__, ret);
return ret;
}
-static bool rk_camera_fmt_capturechk(struct v4l2_format *f)
-{
- bool ret = false;
-
- if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
- ret = true;
- } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
- ret = true;
- } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
- ret = true;
- } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
- ret = true;
- } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
- ret = true;
- }
- if (ret == true)
- RKCAMERA_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
- return ret;
-}
static int rk_camera_try_fmt(struct soc_camera_device *icd,
struct v4l2_format *f)
{
usr_w = pix->width;
usr_h = pix->height;
- RKCAMERA_DG("%s enter width:%d height:%d\n",__FUNCTION__,usr_w,usr_h);
-
+
xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
if (!xlate) {
dev_err(icd->dev.parent, "Format (%c%c%c%c) not found\n", pixfmt & 0xFF, (pixfmt >> 8) & 0xFF,
return pix->bytesperline;
/* limit to sensor capabilities */
+ memset(&mf,0x00,sizeof(struct v4l2_mbus_framefmt));
mf.width = pix->width;
mf.height = pix->height;
mf.field = pix->field;
mf.colorspace = pix->colorspace;
mf.code = xlate->code;
+ /* ddl@rock-chips.com : It is query max resolution only. */
+ if ((usr_w == 10000) && (usr_h == 10000)) {
+ mf.reserved[6] = 0xfefe5a5a;
+ }
ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
if (ret < 0)
goto RK_CAMERA_TRY_FMT_END;
- RKCAMERA_DG("%s mf.width:%d mf.height:%d\n",__FUNCTION__,mf.width,mf.height);
- #ifdef CONFIG_VIDEO_RK29_WORK_IPP
+
+ //query resolution.
+ if((usr_w == 10000) && (usr_h == 10000)) {
+ pix->width = mf.width;
+ pix->height = mf.height;
+ RKCAMERA_DG1("Sensor resolution : %dx%d\n",mf.width,mf.height);
+ goto RK_CAMERA_TRY_FMT_END;
+ } else {
+ RKCAMERA_DG1("user demand: %dx%d sensor output: %dx%d \n",usr_w,usr_h,mf.width,mf.height);
+ }
+
if ((mf.width != usr_w) || (mf.height != usr_h)) {
bytes_per_line_host = soc_mbus_bytes_per_line(mf.width,icd->current_fmt->host_fmt);
if (is_capture) {
pix->width = mf.width;
pix->height = mf.height;
}
-
+ /* ddl@rock-chips.com: Invalidate these code, because sensor need interpolate */
+ #if 0
if ((mf.width < usr_w) || (mf.height < usr_h)) {
if (((usr_w>>1) > mf.width) || ((usr_h>>1) > mf.height)) {
RKCAMERA_TR("The aspect ratio(%dx%d/%dx%d) is bigger than 2 !\n",mf.width,mf.height,usr_w,usr_h);
pix->width = mf.width;
pix->height = mf.height;
}
- }
+ }
+ #endif
}
- #else
- //need to change according to crop and scale capablicity
- if ((mf.width > usr_w) && (mf.height > usr_h)) {
- pix->width = usr_w;
- pix->height = usr_h;
- } else if ((mf.width < usr_w) && (mf.height < usr_h)) {
- RKCAMERA_TR("%dx%d can't scale up to %dx%d!\n",mf.width,mf.height,usr_w,usr_h);
- pix->width = mf.width;
- pix->height = mf.height;
- }
- #endif
+
pix->colorspace = mf.colorspace;
switch (mf.field) {
}
RK_CAMERA_TRY_FMT_END:
- if (ret)
+ if (ret<0)
RKCAMERA_TR("\n%s..%d.. ret = %d \n",__FUNCTION__,__LINE__, ret);
return ret;
}
return 0;
}
-
+/*
+*card: sensor name _ facing _ device index - orientation _ fov horizontal _ fov vertical
+* 10 5 1 3 3 3 + 5 < 32
+*/
static int rk_camera_querycap(struct soc_camera_host *ici,
struct v4l2_capability *cap)
{
struct rk_camera_dev *pcdev = ici->priv;
+ struct rkcamera_platform_data *new_camera;
char orientation[5];
+ char fov[9];
int i;
- strlcpy(cap->card, dev_name(pcdev->icd->pdev), sizeof(cap->card));
+ strlcpy(cap->card, dev_name(pcdev->icd->pdev), 18);
memset(orientation,0x00,sizeof(orientation));
for (i=0; i<RK_CAM_NUM;i++) {
if ((pcdev->pdata->info[i].dev_name!=NULL) && (strcmp(dev_name(pcdev->icd->pdev), pcdev->pdata->info[i].dev_name) == 0)) {
sprintf(orientation,"-%d",pcdev->pdata->info[i].orientation);
+ sprintf(fov,"_50_50");
+ }
+ }
+
+ i=0;
+ new_camera = pcdev->pdata->register_dev_new;
+ while (strstr(new_camera->dev_name,"end")==NULL) {
+ if (strcmp(dev_name(pcdev->icd->pdev), new_camera->dev_name) == 0) {
+ sprintf(orientation,"-%d",new_camera->orientation);
+ sprintf(fov,"_%d_%d",new_camera->fov_h,new_camera->fov_v);
}
+ new_camera++;
}
if (orientation[0] != '-') {
} else {
strcat(cap->card,orientation);
}
+
+ strcat(cap->card,fov); /* ddl@rock-chips.com: v0.3.f */
cap->version = RK_CAM_VERSION_CODE;
cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
return 0;
}
-static void rk_camera_store_register(struct rk_camera_dev *pcdev)
-{
- pcdev->reginfo_suspend.cifCtrl = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
- pcdev->reginfo_suspend.cifCrop = read_cif_reg(pcdev->base,CIF_CIF_CROP);
- pcdev->reginfo_suspend.cifFs = read_cif_reg(pcdev->base,CIF_CIF_SET_SIZE);
- pcdev->reginfo_suspend.cifIntEn = read_cif_reg(pcdev->base,CIF_CIF_INTEN);
- pcdev->reginfo_suspend.cifFmt= read_cif_reg(pcdev->base,CIF_CIF_FOR);
- pcdev->reginfo_suspend.cifVirWidth = read_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH);
- pcdev->reginfo_suspend.cifScale= read_cif_reg(pcdev->base,CIF_CIF_SCL_CTRL);
-}
-static void rk_camera_restore_register(struct rk_camera_dev *pcdev)
-{
- write_cif_reg(pcdev->base,CIF_CIF_CTRL, pcdev->reginfo_suspend.cifCtrl&~ENABLE_CAPTURE);
- write_cif_reg(pcdev->base,CIF_CIF_INTEN, pcdev->reginfo_suspend.cifIntEn);
- write_cif_reg(pcdev->base,CIF_CIF_CROP, pcdev->reginfo_suspend.cifCrop);
- write_cif_reg(pcdev->base,CIF_CIF_SET_SIZE, pcdev->reginfo_suspend.cifFs);
- write_cif_reg(pcdev->base,CIF_CIF_FOR, pcdev->reginfo_suspend.cifFmt);
- write_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH,pcdev->reginfo_suspend.cifVirWidth);
- write_cif_reg(pcdev->base,CIF_CIF_SCL_CTRL, pcdev->reginfo_suspend.cifScale);
-}
static int rk_camera_suspend(struct soc_camera_device *icd, pm_message_t state)
{
struct soc_camera_host *ici =
pcdev->reginfo_suspend.Inval = Reg_Validate;
rk_camera_deactivate(pcdev);
- RKCAMERA_DG("%s Enter Success...\n", __FUNCTION__);
+ RKCAMERA_DG1("%s Enter Success...\n", __FUNCTION__);
} else {
- RKCAMERA_DG("%s icd has been deattach, don't need enter suspend\n", __FUNCTION__);
+ RKCAMERA_DG1("%s icd has been deattach, don't need enter suspend\n", __FUNCTION__);
}
mutex_unlock(&camera_lock);
return ret;
sd = soc_camera_to_subdev(icd);
v4l2_subdev_call(sd, video, s_stream, 1);
- RKCAMERA_DG("%s Enter success\n",__FUNCTION__);
+ RKCAMERA_DG1("%s Enter success\n",__FUNCTION__);
} else {
- RKCAMERA_DG("%s icd has been deattach, don't need enter resume\n", __FUNCTION__);
+ RKCAMERA_DG1("%s icd has been deattach, don't need enter resume\n", __FUNCTION__);
}
rk_camera_resume_end:
RKCAMERA_TR("CIF_CIF_FRAME_STATUS = 0X%x\n",read_cif_reg(pcdev->base,CIF_CIF_FRAME_STATUS));
}
- pcdev->stop_cif = true;
+ atomic_set(&pcdev->stop_cif,true);
write_cif_reg(pcdev->base,CIF_CIF_CTRL, (read_cif_reg(pcdev->base,CIF_CIF_CTRL)&(~ENABLE_CAPTURE)));
- RKCAMERA_DG("the reinit times = %d\n",pcdev->reinit_times);
-
- spin_lock_irqsave(pcdev->video_vq->irqlock, flags);
- for (index = 0; index < VIDEO_MAX_FRAME; index++) {
- if (NULL == pcdev->video_vq->bufs[index])
- continue;
-
- if (pcdev->video_vq->bufs[index]->state == VIDEOBUF_QUEUED)
- {
- list_del_init(&pcdev->video_vq->bufs[index]->queue);
- pcdev->video_vq->bufs[index]->state = VIDEOBUF_NEEDS_INIT;
- wake_up_all(&pcdev->video_vq->bufs[index]->done);
+ RKCAMERA_DG1("the reinit times = %d\n",pcdev->reinit_times);
+
+ if(pcdev->video_vq && pcdev->video_vq->irqlock){
+ spin_lock_irqsave(pcdev->video_vq->irqlock, flags);
+ for (index = 0; index < VIDEO_MAX_FRAME; index++) {
+ if (NULL == pcdev->video_vq->bufs[index])
+ continue;
+
+ if (pcdev->video_vq->bufs[index]->state == VIDEOBUF_QUEUED) {
+ list_del_init(&pcdev->video_vq->bufs[index]->queue);
+ pcdev->video_vq->bufs[index]->state = VIDEOBUF_NEEDS_INIT;
+ wake_up_all(&pcdev->video_vq->bufs[index]->done);
printk("wake up video buffer index = %d !!!\n",index);
- }
- }
- spin_unlock_irqrestore(pcdev->video_vq->irqlock, flags);
+ }
+ }
+ spin_unlock_irqrestore(pcdev->video_vq->irqlock, flags);
+ }else{
+ RKCAMERA_TR("video queue has somthing wrong !!\n");
+ }
RKCAMERA_TR("the %d reinit times ,wake up video buffers!\n ",pcdev->reinit_times);
}
struct soc_camera_link *tmp_soc_cam_link;
tmp_soc_cam_link = to_soc_camera_link(pcdev->icd);
- RKCAMERA_DG("rk_camera_fps_func fps:0x%x\n",pcdev->fps);
+ RKCAMERA_DG1("rk_camera_fps_func fps:0x%x\n",pcdev->fps);
if ((pcdev->fps < 1) || (pcdev->last_fps == pcdev->fps)) {
RKCAMERA_TR("Camera host haven't recevie data from sensor,Reinit sensor delay,last fps = %d,pcdev->fps = %d!\n",pcdev->last_fps,pcdev->fps);
pcdev->camera_reinit_work.pcdev = pcdev;
fival_pre = fival_nxt;
while (fival_nxt != NULL) {
- RKCAMERA_DG("%s %c%c%c%c %dx%d framerate : %d/%d\n", dev_name(&pcdev->icd->dev),
+ RKCAMERA_DG1("%s %c%c%c%c %dx%d framerate : %d/%d\n", dev_name(&pcdev->icd->dev),
fival_nxt->fival.pixel_format & 0xFF, (fival_nxt->fival.pixel_format >> 8) & 0xFF,
(fival_nxt->fival.pixel_format >> 16) & 0xFF, (fival_nxt->fival.pixel_format >> 24),
fival_nxt->fival.width, fival_nxt->fival.height, fival_nxt->fival.discrete.denominator,
pcdev->fps_timer.pcdev = pcdev;
pcdev->timer_get_fps = false;
pcdev->reinit_times = 0;
- pcdev->stop_cif = false;
-// hrtimer_start(&(pcdev->fps_timer.timer),ktime_set(3, 0),HRTIMER_MODE_REL);
+
+ spin_lock_irqsave(&pcdev->lock,flags);
+ atomic_set(&pcdev->stop_cif,false);
+ pcdev->irqinfo.cifirq_idx = 0;
+ pcdev->irqinfo.cifirq_normal_idx = 0;
+ pcdev->irqinfo.cifirq_abnormal_idx = 0;
+ pcdev->irqinfo.dmairq_idx = 0;
+
cif_ctrl_val |= ENABLE_CAPTURE;
- write_cif_reg(pcdev->base,CIF_CIF_CTRL, cif_ctrl_val);
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, cif_ctrl_val);
+ spin_unlock_irqrestore(&pcdev->lock,flags);
+
hrtimer_start(&(pcdev->fps_timer.timer),ktime_set(3, 0),HRTIMER_MODE_REL);
pcdev->fps_timer.istarted = true;
} else {
cif_ctrl_val &= ~ENABLE_CAPTURE;
spin_lock_irqsave(&pcdev->lock, flags);
write_cif_reg(pcdev->base,CIF_CIF_CTRL, cif_ctrl_val);
- pcdev->stop_cif = true;
+ atomic_set(&pcdev->stop_cif,true);
spin_unlock_irqrestore(&pcdev->lock, flags);
flush_workqueue((pcdev->camera_wq));
- RKCAMERA_DG("STREAM_OFF cancel timer and flush work:0x%x \n", ret);
}
//must be reinit,or will be somthing wrong in irq process.
- if(enable == false){
+ if(enable == false) {
pcdev->active = NULL;
INIT_LIST_HEAD(&pcdev->capture);
- }
- RKCAMERA_DG("%s.. enable : 0x%x , CIF_CIF_CTRL = 0x%x\n", __FUNCTION__, enable,read_cif_reg(pcdev->base,CIF_CIF_CTRL));
+ }
+ RKCAMERA_DG1("s_stream: enable : 0x%x , CIF_CIF_CTRL = 0x%x\n",enable,read_cif_reg(pcdev->base,CIF_CIF_CTRL));
return 0;
}
int rk_camera_enum_frameintervals(struct soc_camera_device *icd, struct v4l2_frmivalenum *fival)
{
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct rk_camera_dev *pcdev = ici->priv;
+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
struct rk_camera_frmivalenum *fival_list = NULL;
struct v4l2_frmivalenum *fival_head = NULL;
+ struct rkcamera_platform_data *new_camera;
int i,ret = 0,index;
+ const struct soc_camera_format_xlate *xlate;
+ struct v4l2_mbus_framefmt mf;
+ __u32 pixfmt;
index = fival->index & 0x00ffffff;
if ((fival->index & 0xff000000) == 0xff000000) { /* ddl@rock-chips.com: detect framerate */
fival_head = pcdev->pdata->info[i].fival;
}
}
-
- if (fival_head == NULL) {
- RKCAMERA_TR("%s: %s is not registered in rk_camera_platform_data!!",__FUNCTION__,dev_name(pcdev->icd->pdev));
- ret = -EINVAL;
- goto rk_camera_enum_frameintervals_end;
- }
-
- i = 0;
- while (fival_head->width && fival_head->height) {
- if ((fival->pixel_format == fival_head->pixel_format)
- && (fival->height == fival_head->height)
- && (fival->width == fival_head->width)) {
- if (i == index) {
- break;
+
+ if (fival_head) {
+ i = 0;
+ while (fival_head->width && fival_head->height) {
+ if ((fival->pixel_format == fival_head->pixel_format)
+ && (fival->height == fival_head->height)
+ && (fival->width == fival_head->width)) {
+ if (i == index) {
+ break;
+ }
+ i++;
}
- i++;
+ fival_head++;
}
- fival_head++;
- }
- if ((i == index) && (fival->height == fival_head->height) && (fival->width == fival_head->width)) {
- memcpy(fival, fival_head, sizeof(struct v4l2_frmivalenum));
- RKCAMERA_DG("%s %dx%d@%c%c%c%c framerate : %d/%d\n", dev_name(pcdev->icd->pdev),
- fival->width, fival->height,
- fival->pixel_format & 0xFF, (fival->pixel_format >> 8) & 0xFF,
- (fival->pixel_format >> 16) & 0xFF, (fival->pixel_format >> 24),
- fival->discrete.denominator,fival->discrete.numerator);
- } else {
- if (index == 0)
- RKCAMERA_TR("%s have not catch %d%d@%c%c%c%c index(%d) framerate\n",dev_name(pcdev->icd->pdev),
- fival->width,fival->height,
- fival->pixel_format & 0xFF, (fival->pixel_format >> 8) & 0xFF,
- (fival->pixel_format >> 16) & 0xFF, (fival->pixel_format >> 24),
- index);
- else
- RKCAMERA_DG("%s have not catch %d%d@%c%c%c%c index(%d) framerate\n",dev_name(pcdev->icd->pdev),
- fival->width,fival->height,
+ if ((i == index) && (fival->height == fival_head->height) && (fival->width == fival_head->width)) {
+ memcpy(fival, fival_head, sizeof(struct v4l2_frmivalenum));
+
+ pixfmt = fival->pixel_format; /* ddl@rock-chips.com: v0.3.9 */
+ xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
+ memset(&mf,0x00,sizeof(struct v4l2_mbus_framefmt));
+ mf.width = fival->width;
+ mf.height = fival->height;
+ mf.code = xlate->code;
+
+ v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
+
+ fival->reserved[1] = (mf.width<<16)|(mf.height);
+
+ RKCAMERA_DG1("%s %dx%d@%c%c%c%c framerate : %d/%d\n", dev_name(pcdev->icd->pdev),
+ fival->width, fival->height,
fival->pixel_format & 0xFF, (fival->pixel_format >> 8) & 0xFF,
(fival->pixel_format >> 16) & 0xFF, (fival->pixel_format >> 24),
- index);
- ret = -EINVAL;
+ fival->discrete.denominator,fival->discrete.numerator);
+ } else {
+ if (index == 0)
+ RKCAMERA_TR("%s have not catch %d%d@%c%c%c%c index(%d) framerate\n",dev_name(pcdev->icd->pdev),
+ fival->width,fival->height,
+ fival->pixel_format & 0xFF, (fival->pixel_format >> 8) & 0xFF,
+ (fival->pixel_format >> 16) & 0xFF, (fival->pixel_format >> 24),
+ index);
+ else
+ RKCAMERA_DG1("%s have not catch %d%d@%c%c%c%c index(%d) framerate\n",dev_name(pcdev->icd->pdev),
+ fival->width,fival->height,
+ fival->pixel_format & 0xFF, (fival->pixel_format >> 8) & 0xFF,
+ (fival->pixel_format >> 16) & 0xFF, (fival->pixel_format >> 24),
+ index);
+ ret = -EINVAL;
+ goto rk_camera_enum_frameintervals_end;
+ }
+ } else {
+ i = 0x00;
+ new_camera = pcdev->pdata->register_dev_new;
+ while (strstr(new_camera->dev_name,"end")==NULL) {
+ if (strcmp(new_camera->dev_name, dev_name(pcdev->icd->pdev)) == 0) {
+ i = 0x01;
+ break;
+ }
+ new_camera++;
+ }
+
+ if (i == 0x00) {
+ printk(KERN_ERR "%s(%d): %s have not found in new_camera[] and rk_camera_platform_data!",
+ __FUNCTION__,__LINE__,dev_name(pcdev->icd->pdev));
+ } else {
+
+ pixfmt = fival->pixel_format; /* ddl@rock-chips.com: v0.3.9 */
+ xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
+ memset(&mf,0x00,sizeof(struct v4l2_mbus_framefmt));
+ mf.width = fival->width;
+ mf.height = fival->height;
+ mf.code = xlate->code;
+
+ v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
+
+ fival->discrete.numerator= 1000;
+ fival->discrete.denominator = 15000;
+ fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+ fival->reserved[1] = (mf.width<<16)|(mf.height);
+ }
}
}
rk_camera_enum_frameintervals_end:
return ret;
}
-#ifdef CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_ON
static int rk_camera_set_digit_zoom(struct soc_camera_device *icd,
const struct v4l2_queryctrl *qctrl, int zoom_rate)
{
struct v4l2_crop a;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct rk_camera_dev *pcdev = ici->priv;
+#if CIF_DO_CROP
unsigned long tmp_cifctrl;
- int flags;
+#endif
//change the crop and scale parameters
#if CIF_DO_CROP
- a.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- //a.c.width = pcdev->host_width*100/zoom_rate;
- a.c.width = pcdev->host_width*100/zoom_rate;
- a.c.width &= ~CROP_ALIGN_BYTES;
- a.c.height = pcdev->host_height*100/zoom_rate;
- a.c.height &= ~CROP_ALIGN_BYTES;
- a.c.left = ((pcdev->host_width - a.c.width)>>1)+pcdev->host_left;
- a.c.top = ((pcdev->host_height - a.c.height)>>1)+pcdev->host_top;
- pcdev->stop_cif = true;
- tmp_cifctrl = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
- write_cif_reg(pcdev->base,CIF_CIF_CTRL, (tmp_cifctrl & ~ENABLE_CAPTURE));
- hrtimer_cancel(&(pcdev->fps_timer.timer));
- flush_workqueue((pcdev->camera_wq));
- down(&pcdev->zoominfo.sem);
- pcdev->zoominfo.a.c.left = 0;
- pcdev->zoominfo.a.c.top = 0;
- pcdev->zoominfo.a.c.width = a.c.width;
- pcdev->zoominfo.a.c.height = a.c.height;
- pcdev->zoominfo.vir_width = pcdev->zoominfo.a.c.width;
- pcdev->zoominfo.vir_height = pcdev->zoominfo.a.c.height;
- pcdev->frame_inval = 1;
- write_cif_reg(pcdev->base,CIF_CIF_CROP, (a.c.left + (a.c.top<<16)));
- write_cif_reg(pcdev->base,CIF_CIF_SET_SIZE, ((a.c.width ) + (a.c.height<<16)));
- write_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH, a.c.width);
- write_cif_reg(pcdev->base,CIF_CIF_FRAME_STATUS, 0x00000002);//frame1 has been ready to receive data,frame 2 is not used
- if(pcdev->active)
- rk_videobuf_capture(pcdev->active,pcdev);
- if(tmp_cifctrl & ENABLE_CAPTURE)
- write_cif_reg(pcdev->base,CIF_CIF_CTRL, (tmp_cifctrl | ENABLE_CAPTURE));
- up(&pcdev->zoominfo.sem);
- pcdev->stop_cif = false;
- hrtimer_start(&(pcdev->fps_timer.timer),ktime_set(3, 0),HRTIMER_MODE_REL);
- RKCAMERA_DG("%s..zoom_rate:%d (%dx%d at (%d,%d)-> %dx%d)\n",__FUNCTION__, zoom_rate,a.c.width, a.c.height, a.c.left, a.c.top, icd->user_width, icd->user_height );
+ a.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ //a.c.width = pcdev->host_width*100/zoom_rate;
+ a.c.width = pcdev->host_width*100/zoom_rate;
+ a.c.width &= ~CROP_ALIGN_BYTES;
+ a.c.height = pcdev->host_height*100/zoom_rate;
+ a.c.height &= ~CROP_ALIGN_BYTES;
+ a.c.left = (((pcdev->host_width - a.c.width)>>1)+pcdev->host_left)&(~0x01);
+ a.c.top = (((pcdev->host_height - a.c.height)>>1)+pcdev->host_top)&(~0x01);
+ atomic_set(&pcdev->stop_cif,true);
+ tmp_cifctrl = read_cif_reg(pcdev->base,CIF_CIF_CTRL);
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, (tmp_cifctrl & ~ENABLE_CAPTURE));
+ hrtimer_cancel(&(pcdev->fps_timer.timer));
+ flush_workqueue((pcdev->camera_wq));
+
+ down(&pcdev->zoominfo.sem);
+ pcdev->zoominfo.a.c.left = 0;
+ pcdev->zoominfo.a.c.top = 0;
+ pcdev->zoominfo.a.c.width = a.c.width;
+ pcdev->zoominfo.a.c.height = a.c.height;
+ pcdev->zoominfo.vir_width = pcdev->zoominfo.a.c.width;
+ pcdev->zoominfo.vir_height = pcdev->zoominfo.a.c.height;
+ pcdev->frame_inval = 1;
+ write_cif_reg(pcdev->base,CIF_CIF_CROP, (a.c.left + (a.c.top<<16)));
+ write_cif_reg(pcdev->base,CIF_CIF_SET_SIZE, ((a.c.width ) + (a.c.height<<16)));
+ write_cif_reg(pcdev->base,CIF_CIF_VIR_LINE_WIDTH, a.c.width);
+ write_cif_reg(pcdev->base,CIF_CIF_FRAME_STATUS, 0x00000002);//frame1 has been ready to receive data,frame 2 is not used
+ if(pcdev->active)
+ rk_videobuf_capture(pcdev->active,pcdev);
+ if(tmp_cifctrl & ENABLE_CAPTURE)
+ write_cif_reg(pcdev->base,CIF_CIF_CTRL, (tmp_cifctrl | ENABLE_CAPTURE));
+ up(&pcdev->zoominfo.sem);
+
+ atomic_set(&pcdev->stop_cif,false);
+ hrtimer_start(&(pcdev->fps_timer.timer),ktime_set(3, 0),HRTIMER_MODE_REL);
+ RKCAMERA_DG1("zoom_rate:%d (%dx%d at (%d,%d)-> %dx%d)\n", zoom_rate,a.c.width, a.c.height, a.c.left, a.c.top, icd->user_width, icd->user_height );
#else
- a.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- a.c.width = pcdev->host_width*100/zoom_rate;
- a.c.width &= ~CROP_ALIGN_BYTES;
- a.c.height = pcdev->host_height*100/zoom_rate;
- a.c.height &= ~CROP_ALIGN_BYTES;
- a.c.left = (pcdev->host_width - a.c.width)>>1;
- a.c.top = (pcdev->host_height - a.c.height)>>1;
- down(&pcdev->zoominfo.sem);
- pcdev->zoominfo.a.c.height = a.c.height;
- pcdev->zoominfo.a.c.width = a.c.width;
- pcdev->zoominfo.a.c.top = a.c.top;
- pcdev->zoominfo.a.c.left = a.c.left;
- pcdev->zoominfo.vir_width = pcdev->host_width;
- pcdev->zoominfo.vir_height= pcdev->host_height;
- up(&pcdev->zoominfo.sem);
- RKCAMERA_DG("%s..zoom_rate:%d (%dx%d at (%d,%d)-> %dx%d)\n",__FUNCTION__, zoom_rate,a.c.width, a.c.height, a.c.left, a.c.top, icd->user_width, icd->user_height );
+ a.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ a.c.width = pcdev->host_width*100/zoom_rate;
+ a.c.width &= ~CROP_ALIGN_BYTES;
+ a.c.height = pcdev->host_height*100/zoom_rate;
+ a.c.height &= ~CROP_ALIGN_BYTES;
+ a.c.left = (pcdev->host_width - a.c.width)>>1;
+ a.c.top = (pcdev->host_height - a.c.height)>>1;
+
+ down(&pcdev->zoominfo.sem);
+ pcdev->zoominfo.a.c.height = a.c.height;
+ pcdev->zoominfo.a.c.width = a.c.width;
+ pcdev->zoominfo.a.c.top = a.c.top;
+ pcdev->zoominfo.a.c.left = a.c.left;
+ pcdev->zoominfo.vir_width = pcdev->host_width;
+ pcdev->zoominfo.vir_height= pcdev->host_height;
+ up(&pcdev->zoominfo.sem);
+
+ RKCAMERA_DG1("zoom_rate:%d (%dx%d at (%d,%d)-> %dx%d)\n", zoom_rate,a.c.width, a.c.height, a.c.left, a.c.top, icd->user_width, icd->user_height );
#endif
return 0;
}
-#endif
+
static inline struct v4l2_queryctrl const *rk_camera_soc_camera_find_qctrl(
struct soc_camera_host_ops *ops, int id)
{
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
const struct v4l2_queryctrl *qctrl;
-#ifdef CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_ON
struct rk_camera_dev *pcdev = ici->priv;
-#endif
+
int ret = 0;
qctrl = rk_camera_soc_camera_find_qctrl(ici->ops, sctrl->id);
switch (sctrl->id)
{
- #ifdef CONFIG_VIDEO_RK29_DIGITALZOOM_IPP_ON
case V4L2_CID_ZOOM_ABSOLUTE:
{
if ((sctrl->value < qctrl->minimum) || (sctrl->value > qctrl->maximum)){
}
break;
}
- #endif
default:
ret = -ENOIOCTLCMD;
break;
.suspend = rk_camera_suspend,
.resume = rk_camera_resume,
.enum_frameinervals = rk_camera_enum_frameintervals,
+ .cropcap = rk_camera_cropcap,
.set_crop = rk_camera_set_crop,
+ .get_crop = rk_camera_get_crop,
.get_formats = rk_camera_get_formats,
.put_formats = rk_camera_put_formats,
.set_fmt = rk_camera_set_fmt,
.set_ctrl = rk_camera_set_ctrl,
.controls = rk_camera_controls,
.num_controls = ARRAY_SIZE(rk_camera_controls)
-
};
static void rk_camera_cif_iomux(int cif_index)
{
-#if defined(CONFIG_ARCH_RK3066B)
+#if defined(CONFIG_ARCH_RK3066B) || defined(CONFIG_ARCH_RK3188)
+ switch(cif_index){
+ case 0:
+ {
+ iomux_set(CIF0_CLKOUT);
+ write_grf_reg(GRF_IO_CON3, (CIF_DRIVER_STRENGTH_MASK|CIF_DRIVER_STRENGTH_8MA));
+ write_grf_reg(GRF_IO_CON4, (CIF_CLKOUT_AMP_MASK|CIF_CLKOUT_AMP_1V8));
+ #if (CONFIG_CAMERA_INPUT_FMT_SUPPORT & (RK_CAM_INPUT_FMT_RAW10|RK_CAM_INPUT_FMT_RAW12))
+ iomux_set(CIF0_D0);
+ iomux_set(CIF0_D1);
+ #endif
+ #if (CONFIG_CAMERA_INPUT_FMT_SUPPORT & RK_CAM_INPUT_FMT_RAW12)
+ iomux_set(CIF0_D10);
+ iomux_set(CIF0_D11);
+ RKCAMERA_TR("%s(%d): WARNING: Cif 0 is configurated that support RAW 12bit, so I2C3 is invalidate!!\n",__FUNCTION__,__LINE__);
+ #endif
+
+ break;
+ }
+ default:
+ RKCAMERA_TR("%s(%d): Cif index(%d) is invalidate!!!\n",__FUNCTION__,__LINE__, cif_index);
+ break;
+ }
#elif defined(CONFIG_ARCH_RK30)
switch(cif_index){
case 0:
+ {
rk30_mux_api_set(GPIO1B3_CIF0CLKOUT_NAME, GPIO1B_CIF0_CLKOUT);
+ #if (CONFIG_CAMERA_INPUT_FMT_SUPPORT & (RK_CAM_INPUT_FMT_RAW10|RK_CAM_INPUT_FMT_RAW12))
+ rk30_mux_api_set(GPIO1B4_CIF0DATA0_NAME, GPIO1B_CIF0_DATA0);
+ rk30_mux_api_set(GPIO1B5_CIF0DATA1_NAME, GPIO1B_CIF0_DATA1);
+ #endif
+ #if (CONFIG_CAMERA_INPUT_FMT_SUPPORT & RK_CAM_INPUT_FMT_RAW12)
+ rk30_mux_api_set(GPIO1B6_CIFDATA10_NAME, GPIO1B_CIF_DATA10);
+ rk30_mux_api_set(GPIO1B7_CIFDATA11_NAME, GPIO1B_CIF_DATA11);
+ #endif
break;
+ }
case 1:
+ {
rk30_mux_api_set(GPIO1C0_CIF1DATA2_RMIICLKOUT_RMIICLKIN_NAME,GPIO1C_CIF1_DATA2);
rk30_mux_api_set(GPIO1C1_CIFDATA3_RMIITXEN_NAME,GPIO1C_CIF_DATA3);
rk30_mux_api_set(GPIO1C2_CIF1DATA4_RMIITXD1_NAME,GPIO1C_CIF1_DATA4);
rk30_mux_api_set(GPIO1D6_CIF1DATA11_NAME,GPIO1D_CIF1_DATA11);
rk30_mux_api_set(GPIO1D7_CIF1CLKOUT_NAME,GPIO1D_CIF1_CLKOUT);
break;
+ }
default:
- printk("cif index is erro!!!\n");
+ RKCAMERA_TR("%s(%d): Cif index(%d) is invalidate!!!\n",__FUNCTION__,__LINE__, cif_index);
+ break;
}
-#else
#endif
struct rk29camera_mem_res *meminfo_ptr,*meminfo_ptrr;
int irq,i;
int err = 0;
- static int ipp_mem = 0;
+ struct rk_cif_clk *clk=NULL;
- RKCAMERA_DG("%s(%d) Enter..\n",__FUNCTION__,__LINE__);
+ RKCAMERA_TR("%s version: v%d.%d.%d Zoom by %s",RK29_CAM_DRV_NAME,(RK_CAM_VERSION_CODE&0xff0000)>>16,
+ (RK_CAM_VERSION_CODE&0xff00)>>8,RK_CAM_VERSION_CODE&0xff,CAMERA_SCALE_CROP_MACHINE);
if ((pdev->id == RK_CAM_PLATFORM_DEV_ID_1) && (RK_SUPPORT_CIF1 == 0)) {
RKCAMERA_TR("%s(%d): This chip is not support CIF1!!\n",__FUNCTION__,__LINE__);
goto exit_alloc;
}
- pcdev->zoominfo.zoom_rate = 100;
- pcdev->hostid = pdev->id;
- /*config output clk*/ // must modify start
- if(IS_CIF0()){
- pcdev->pd_cif = clk_get(NULL, "pd_cif0");
- pcdev->aclk_cif = clk_get(NULL, "aclk_cif0");
- pcdev->hclk_cif = clk_get(NULL, "hclk_cif0");
- pcdev->cif_clk_in = clk_get(NULL, "cif0_in");
- pcdev->cif_clk_out = clk_get(NULL, "cif0_out");
+ pcdev->zoominfo.zoom_rate = 100;
+ pcdev->hostid = pdev->id;
+ #ifdef CONFIG_SOC_RK3028
+ pcdev->chip_id = rk3028_version_val();
+ #else
+ pcdev->chip_id = -1;
+ #endif
+
+
+ if (IS_CIF0()) {
+ clk = &cif_clk[0];
+ cif_clk[0].pd_cif = clk_get(NULL, "pd_cif0");
+ cif_clk[0].aclk_cif = clk_get(NULL, "aclk_cif0");
+ cif_clk[0].hclk_cif = clk_get(NULL, "hclk_cif0");
+ cif_clk[0].cif_clk_in = clk_get(NULL, "cif0_in");
+ cif_clk[0].cif_clk_out = clk_get(NULL, "cif0_out");
+ spin_lock_init(&cif_clk[0].lock);
+ cif_clk[0].on = false;
rk_camera_cif_iomux(0);
} else {
- pcdev->pd_cif = clk_get(NULL, "pd_cif1");
- pcdev->aclk_cif = clk_get(NULL, "aclk_cif1");
- pcdev->hclk_cif = clk_get(NULL, "hclk_cif1");
- pcdev->cif_clk_in = clk_get(NULL, "cif1_in");
- pcdev->cif_clk_out = clk_get(NULL, "cif1_out");
-
+ clk = &cif_clk[1];
+ cif_clk[1].pd_cif = clk_get(NULL, "pd_cif1");
+ cif_clk[1].aclk_cif = clk_get(NULL, "aclk_cif1");
+ cif_clk[1].hclk_cif = clk_get(NULL, "hclk_cif1");
+ cif_clk[1].cif_clk_in = clk_get(NULL, "cif1_in");
+ cif_clk[1].cif_clk_out = clk_get(NULL, "cif1_out");
+ spin_lock_init(&cif_clk[1].lock);
+ cif_clk[1].on = false;
rk_camera_cif_iomux(1);
}
- if(IS_ERR(pcdev->pd_cif) || IS_ERR(pcdev->aclk_cif) || IS_ERR(pcdev->hclk_cif) || IS_ERR(pcdev->cif_clk_in) || IS_ERR(pcdev->cif_clk_out)){
- RKCAMERA_TR(KERN_ERR "%s(%d): failed to get cif clock source\n",__FUNCTION__,__LINE__);
- err = -ENOENT;
- goto exit_reqmem_vip;
- }
-
dev_set_drvdata(&pdev->dev, pcdev);
pcdev->res = res;
pcdev->pdata = pdev->dev.platform_data; /* ddl@rock-chips.com : Request IO in init function */
if (pcdev->pdata && pcdev->pdata->io_init) {
pcdev->pdata->io_init();
+
+ if (pcdev->pdata->sensor_mclk == NULL)
+ pcdev->pdata->sensor_mclk = rk_camera_mclk_ctrl;
}
- #ifdef CONFIG_VIDEO_RK29_WORK_IPP
+
meminfo_ptr = IS_CIF0()? (&pcdev->pdata->meminfo):(&pcdev->pdata->meminfo_cif1);
meminfo_ptrr = IS_CIF0()? (&pcdev->pdata->meminfo_cif1):(&pcdev->pdata->meminfo);
}
meminfo_ptr->vbase = pcdev->vipmem_virbase = ioremap_cached(meminfo_ptr->start,meminfo_ptr->size);
if (pcdev->vipmem_virbase == NULL) {
- dev_err(pcdev->dev, "ioremap() of vip internal memory(Ex:IPP process/raw process) failed\n");
+ RKCAMERA_TR("%s(%d): ioremap of CIF internal memory(Ex:IPP process/raw process) failed\n",__FUNCTION__,__LINE__);
err = -ENXIO;
goto exit_ioremap_vipmem;
}
pcdev->vipmem_phybase = meminfo_ptr->start;
pcdev->vipmem_size = meminfo_ptr->size;
- pcdev->pdata->meminfo.vbase = meminfo_ptr->vbase;
- #endif
+ pcdev->vipmem_virbase = meminfo_ptr->vbase;
+
INIT_LIST_HEAD(&pcdev->capture);
INIT_LIST_HEAD(&pcdev->camera_work_queue);
spin_lock_init(&pcdev->lock);
spin_lock_init(&pcdev->camera_work_lock);
+
+ memset(&pcdev->cropinfo.c,0x00,sizeof(struct v4l2_rect));
+ spin_lock_init(&pcdev->cropinfo.lock);
sema_init(&pcdev->zoominfo.sem,1);
/*
}
}
- pcdev->irq = irq;
+ pcdev->irqinfo.irq = irq;
pcdev->dev = &pdev->dev;
/* config buffer address */
/* request irq */
if(irq > 0){
- err = request_irq(pcdev->irq, rk_camera_irq, 0, RK29_CAM_DRV_NAME,
+ err = request_irq(pcdev->irqinfo.irq, rk_camera_irq, 0, RK29_CAM_DRV_NAME,
pcdev);
if (err) {
dev_err(pcdev->dev, "Camera interrupt register failed \n");
}
}
-//#ifdef CONFIG_VIDEO_RK29_WORK_IPP
if(IS_CIF0()) {
pcdev->camera_wq = create_workqueue("rk_cam_wkque_cif0");
} else {
pcdev->camera_wq = create_workqueue("rk_cam_wkque_cif1");
}
- if (pcdev->camera_wq == NULL)
- goto exit_free_irq;
-//#endif
+ if (pcdev->camera_wq == NULL) {
+ RKCAMERA_TR("%s(%d): Create workqueue failed!\n",__FUNCTION__,__LINE__);
+ goto exit_free_irq;
+ }
pcdev->camera_reinit_work.pcdev = pcdev;
INIT_WORK(&(pcdev->camera_reinit_work.work), rk_camera_reinit_work);
pcdev->soc_host.nr = pdev->id;
err = soc_camera_host_register(&pcdev->soc_host);
- if (err)
+ if (err) {
+ RKCAMERA_TR("%s(%d): soc_camera_host_register failed\n",__FUNCTION__,__LINE__);
goto exit_free_irq;
+ }
pcdev->fps_timer.pcdev = pcdev;
hrtimer_init(&(pcdev->fps_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
pcdev->fps_timer.timer.function = rk_camera_fps_func;
#elif(CONFIG_CAMERA_SCALE_CROP_MACHINE == RK_CAM_SCALE_CROP_PP)
pcdev->icd_cb.scale_crop_cb = rk_camera_scale_crop_pp;
#endif
- RKCAMERA_DG("%s(%d) Exit \n",__FUNCTION__,__LINE__);
return 0;
exit_free_irq:
}
}
- free_irq(pcdev->irq, pcdev);
+ free_irq(pcdev->irqinfo.irq, pcdev);
if (pcdev->camera_wq) {
destroy_workqueue(pcdev->camera_wq);
pcdev->camera_wq = NULL;
iounmap(pcdev->vipmem_virbase);
release_mem_region(pcdev->vipmem_phybase,pcdev->vipmem_size);
exit_reqmem_vip:
- if(pcdev->aclk_cif)
- pcdev->aclk_cif = NULL;
- if(pcdev->hclk_cif)
- pcdev->hclk_cif = NULL;
- if(pcdev->cif_clk_in)
- pcdev->cif_clk_in = NULL;
- if(pcdev->cif_clk_out)
- pcdev->cif_clk_out = NULL;
-
+ if (clk) {
+ if (clk->pd_cif)
+ clk_put(clk->pd_cif);
+ if (clk->aclk_cif)
+ clk_put(clk->aclk_cif);
+ if (clk->hclk_cif)
+ clk_put(clk->hclk_cif);
+ if (clk->cif_clk_in)
+ clk_put(clk->cif_clk_in);
+ if (clk->cif_clk_out)
+ clk_put(clk->cif_clk_out);
+ }
kfree(pcdev);
exit_alloc:
struct rk29camera_mem_res *meminfo_ptr,*meminfo_ptrr;
int i;
- free_irq(pcdev->irq, pcdev);
+ free_irq(pcdev->irqinfo.irq, pcdev);
if (pcdev->camera_wq) {
destroy_workqueue(pcdev->camera_wq);
if (meminfo_ptr->vbase == meminfo_ptrr->vbase) {
meminfo_ptr->vbase = NULL;
} else {
- iounmap((void __iomem*)pcdev->vipmem_phybase);
+ iounmap((void __iomem*)pcdev->vipmem_virbase);
release_mem_region(pcdev->vipmem_phybase, pcdev->vipmem_size);
meminfo_ptr->vbase = NULL;
}
static int rk_camera_init_async(void *unused)
{
- RKCAMERA_DG("%s..%s..%d \n",__FUNCTION__,__FILE__,__LINE__);
platform_driver_register(&rk_camera_driver);
return 0;
}
static int __devinit rk_camera_init(void)
{
- RKCAMERA_DG("%s..%s..%d \n",__FUNCTION__,__FILE__,__LINE__);
kthread_run(rk_camera_init_async, NULL, "rk_camera_init");
return 0;
}