FROMLIST: media: rkisp1: add capture device driver

This is the capture device interface driver that provides the v4l2
user interface. Frames can be received from ISP1.

Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
Signed-off-by: Shunqian Zheng <zhengsq@rock-chips.com>
Signed-off-by: Yichong Zhong <zyc@rock-chips.com>
Signed-off-by: Jacob Chen <cc@rock-chips.com>
Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com>
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: Allon Huang <allon.huang@rock-chips.com>
Signed-off-by: Tomasz Figa <tfiga@chromium.org>

BUG=b:36227021
TEST=Camera works on Scarlet with the whole series
(am from https://patchwork.linuxtv.org/patch/46232/)

Change-Id: I3ff679d32c48c8dd8e91f22879e58e1b1ef896d7
Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
This commit is contained in:
Jacob Chen 2017-12-18 20:14:37 +08:00 committed by Tao Huang
parent 760a375e13
commit 68c406aa36
4 changed files with 3766 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,194 @@
/*
* Rockchip isp1 driver
*
* Copyright (C) 2017 Rockchip Electronics Co., Ltd.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _RKISP1_PATH_VIDEO_H
#define _RKISP1_PATH_VIDEO_H
#include "common.h"
struct rkisp1_stream;
/*
* @fourcc: pixel format
* @mbus_code: pixel format over bus
* @fmt_type: helper filed for pixel format
* @bpp: bits per pixel
* @bayer_pat: bayer patten type
* @cplanes: number of colour planes
* @mplanes: number of stored memory planes
* @uv_swap: if cb cr swaped, for yuv
* @write_format: defines how YCbCr self picture data is written to memory
* @input_format: defines sp input format
* @output_format: defines sp output format
*/
struct capture_fmt {
u32 fourcc;
u32 mbus_code;
u8 fmt_type;
u8 cplanes;
u8 mplanes;
u8 uv_swap;
u32 write_format;
u32 output_format;
u8 bpp[VIDEO_MAX_PLANES];
};
enum rkisp1_sp_inp {
RKISP1_SP_INP_ISP,
RKISP1_SP_INP_DMA_SP,
RKISP1_SP_INP_MAX
};
struct rkisp1_stream_sp {
int y_stride;
enum rkisp1_sp_inp input_sel;
};
struct rkisp1_stream_mp {
bool raw_enable;
};
/* Different config between selfpath and mainpath */
struct stream_config {
const struct capture_fmt *fmts;
int fmt_size;
/* constrains */
const int max_rsz_width;
const int max_rsz_height;
const int min_rsz_width;
const int min_rsz_height;
/* registers */
struct {
u32 ctrl;
u32 ctrl_shd;
u32 scale_hy;
u32 scale_hcr;
u32 scale_hcb;
u32 scale_vy;
u32 scale_vc;
u32 scale_lut;
u32 scale_lut_addr;
u32 scale_hy_shd;
u32 scale_hcr_shd;
u32 scale_hcb_shd;
u32 scale_vy_shd;
u32 scale_vc_shd;
u32 phase_hy;
u32 phase_hc;
u32 phase_vy;
u32 phase_vc;
u32 phase_hy_shd;
u32 phase_hc_shd;
u32 phase_vy_shd;
u32 phase_vc_shd;
} rsz;
struct {
u32 ctrl;
u32 yuvmode_mask;
u32 rawmode_mask;
u32 h_offset;
u32 v_offset;
u32 h_size;
u32 v_size;
} dual_crop;
struct {
u32 y_size_init;
u32 cb_size_init;
u32 cr_size_init;
u32 y_base_ad_init;
u32 cb_base_ad_init;
u32 cr_base_ad_init;
u32 y_offs_cnt_init;
u32 cb_offs_cnt_init;
u32 cr_offs_cnt_init;
} mi;
};
/* Different reg ops between selfpath and mainpath */
struct streams_ops {
int (*config_mi)(struct rkisp1_stream *stream);
void (*stop_mi)(struct rkisp1_stream *stream);
void (*enable_mi)(struct rkisp1_stream *stream);
void (*disable_mi)(struct rkisp1_stream *stream);
void (*set_data_path)(void __iomem *base);
void (*clr_frame_end_int)(void __iomem *base);
bool (*is_frame_end_int_masked)(void __iomem *base);
bool (*is_stream_stopped)(void __iomem *base);
};
/*
* struct rkisp1_stream - ISP capture video device
*
* @out_isp_fmt: output isp format
* @out_fmt: output buffer size
* @dcrop: coordinates of dual-crop
*
* @vbq_lock: lock to protect buf_queue
* @buf_queue: queued buffer list
* @dummy_buf: dummy space to store dropped data
*
* rkisp1 use shadowsock registers, so it need two buffer at a time
* @curr_buf: the buffer used for current frame
* @next_buf: the buffer used for next frame
*/
struct rkisp1_stream {
u32 id;
struct rkisp1_device *ispdev;
struct rkisp1_vdev_node vnode;
enum rkisp1_state state;
enum rkisp1_state saved_state;
struct capture_fmt out_isp_fmt;
struct v4l2_pix_format_mplane out_fmt;
struct v4l2_rect dcrop;
struct streams_ops *ops;
struct stream_config *config;
spinlock_t vbq_lock;
struct list_head buf_queue;
struct rkisp1_dummy_buffer dummy_buf;
struct rkisp1_buffer *curr_buf;
struct rkisp1_buffer *next_buf;
bool stopping;
wait_queue_head_t done;
union {
struct rkisp1_stream_sp sp;
struct rkisp1_stream_mp mp;
} u;
};
void rkisp1_unregister_stream_vdevs(struct rkisp1_device *dev);
int rkisp1_register_stream_vdevs(struct rkisp1_device *dev);
void rkisp1_mi_isr(struct rkisp1_stream *stream);
void rkisp1_stream_init(struct rkisp1_device *dev, u32 id);
#endif /* _RKISP1_PATH_VIDEO_H */

View File

@ -0,0 +1,266 @@
/*
* Rockchip isp1 driver
*
* Copyright (C) 2017 Rockchip Electronics Co., Ltd.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <media/v4l2-common.h>
#include "regs.h"
void disable_dcrop(struct rkisp1_stream *stream, bool async)
{
void __iomem *base = stream->ispdev->base_addr;
void __iomem *dc_ctrl_addr = base + stream->config->dual_crop.ctrl;
u32 dc_ctrl = readl(dc_ctrl_addr);
u32 mask = ~(stream->config->dual_crop.yuvmode_mask |
stream->config->dual_crop.rawmode_mask);
u32 val = dc_ctrl & mask;
if (async)
val |= CIF_DUAL_CROP_GEN_CFG_UPD;
else
val |= CIF_DUAL_CROP_CFG_UPD;
writel(val, dc_ctrl_addr);
}
void config_dcrop(struct rkisp1_stream *stream, struct v4l2_rect *rect, bool async)
{
void __iomem *base = stream->ispdev->base_addr;
void __iomem *dc_ctrl_addr = base + stream->config->dual_crop.ctrl;
u32 dc_ctrl = readl(dc_ctrl_addr);
writel(rect->left, base + stream->config->dual_crop.h_offset);
writel(rect->top, base + stream->config->dual_crop.v_offset);
writel(rect->width, base + stream->config->dual_crop.h_size);
writel(rect->height, base + stream->config->dual_crop.v_size);
dc_ctrl |= stream->config->dual_crop.yuvmode_mask;
if (async)
dc_ctrl |= CIF_DUAL_CROP_GEN_CFG_UPD;
else
dc_ctrl |= CIF_DUAL_CROP_CFG_UPD;
writel(dc_ctrl, dc_ctrl_addr);
}
void dump_rsz_regs(struct rkisp1_stream *stream)
{
void __iomem *base = stream->ispdev->base_addr;
pr_info("RSZ_CTRL 0x%08x/0x%08x\n"
"RSZ_SCALE_HY %d/%d\n"
"RSZ_SCALE_HCB %d/%d\n"
"RSZ_SCALE_HCR %d/%d\n"
"RSZ_SCALE_VY %d/%d\n"
"RSZ_SCALE_VC %d/%d\n"
"RSZ_PHASE_HY %d/%d\n"
"RSZ_PHASE_HC %d/%d\n"
"RSZ_PHASE_VY %d/%d\n"
"RSZ_PHASE_VC %d/%d\n",
readl(base + stream->config->rsz.ctrl),
readl(base + stream->config->rsz.ctrl_shd),
readl(base + stream->config->rsz.scale_hy),
readl(base + stream->config->rsz.scale_hy_shd),
readl(base + stream->config->rsz.scale_hcb),
readl(base + stream->config->rsz.scale_hcb_shd),
readl(base + stream->config->rsz.scale_hcr),
readl(base + stream->config->rsz.scale_hcr_shd),
readl(base + stream->config->rsz.scale_vy),
readl(base + stream->config->rsz.scale_vy_shd),
readl(base + stream->config->rsz.scale_vc),
readl(base + stream->config->rsz.scale_vc_shd),
readl(base + stream->config->rsz.phase_hy),
readl(base + stream->config->rsz.phase_hy_shd),
readl(base + stream->config->rsz.phase_hc),
readl(base + stream->config->rsz.phase_hc_shd),
readl(base + stream->config->rsz.phase_vy),
readl(base + stream->config->rsz.phase_vy_shd),
readl(base + stream->config->rsz.phase_vc),
readl(base + stream->config->rsz.phase_vc_shd));
}
static void update_rsz_shadow(struct rkisp1_stream *stream, bool async)
{
void *addr = stream->ispdev->base_addr + stream->config->rsz.ctrl;
u32 ctrl_cfg = readl(addr);
if (async)
writel(CIF_RSZ_CTRL_CFG_UPD_AUTO | ctrl_cfg, addr);
else
writel(CIF_RSZ_CTRL_CFG_UPD | ctrl_cfg, addr);
}
static void set_scale(struct rkisp1_stream *stream, struct v4l2_rect *in_y,
struct v4l2_rect *in_c, struct v4l2_rect *out_y,
struct v4l2_rect *out_c)
{
void __iomem *base = stream->ispdev->base_addr;
void __iomem *scale_hy_addr = base + stream->config->rsz.scale_hy;
void __iomem *scale_hcr_addr = base + stream->config->rsz.scale_hcr;
void __iomem *scale_hcb_addr = base + stream->config->rsz.scale_hcb;
void __iomem *scale_vy_addr = base + stream->config->rsz.scale_vy;
void __iomem *scale_vc_addr = base + stream->config->rsz.scale_vc;
void __iomem *rsz_ctrl_addr = base + stream->config->rsz.ctrl;
u32 scale_hy, scale_hc, scale_vy, scale_vc, rsz_ctrl = 0;
if (in_y->width < out_y->width) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_HY_ENABLE |
CIF_RSZ_CTRL_SCALE_HY_UP;
scale_hy = ((in_y->width - 1) * CIF_RSZ_SCALER_FACTOR) /
(out_y->width - 1);
writel(scale_hy, scale_hy_addr);
} else if (in_y->width > out_y->width) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_HY_ENABLE;
scale_hy = ((out_y->width - 1) * CIF_RSZ_SCALER_FACTOR) /
(in_y->width - 1) + 1;
writel(scale_hy, scale_hy_addr);
}
if (in_c->width < out_c->width) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_HC_ENABLE |
CIF_RSZ_CTRL_SCALE_HC_UP;
scale_hc = ((in_c->width - 1) * CIF_RSZ_SCALER_FACTOR) /
(out_c->width - 1);
writel(scale_hc, scale_hcb_addr);
writel(scale_hc, scale_hcr_addr);
} else if (in_c->width > out_c->width) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_HC_ENABLE;
scale_hc = ((out_c->width - 1) * CIF_RSZ_SCALER_FACTOR) /
(in_c->width - 1) + 1;
writel(scale_hc, scale_hcb_addr);
writel(scale_hc, scale_hcr_addr);
}
if (in_y->height < out_y->height) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_VY_ENABLE |
CIF_RSZ_CTRL_SCALE_VY_UP;
scale_vy = ((in_y->height - 1) * CIF_RSZ_SCALER_FACTOR) /
(out_y->height - 1);
writel(scale_vy, scale_vy_addr);
} else if (in_y->height > out_y->height) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_VY_ENABLE;
scale_vy = ((out_y->height - 1) * CIF_RSZ_SCALER_FACTOR) /
(in_y->height - 1) + 1;
writel(scale_vy, scale_vy_addr);
}
if (in_c->height < out_c->height) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_VC_ENABLE |
CIF_RSZ_CTRL_SCALE_VC_UP;
scale_vc = ((in_c->height - 1) * CIF_RSZ_SCALER_FACTOR) /
(out_c->height - 1);
writel(scale_vc, scale_vc_addr);
} else if (in_c->height > out_c->height) {
rsz_ctrl |= CIF_RSZ_CTRL_SCALE_VC_ENABLE;
scale_vc = ((out_c->height - 1) * CIF_RSZ_SCALER_FACTOR) /
(in_c->height - 1) + 1;
writel(scale_vc, scale_vc_addr);
}
writel(rsz_ctrl, rsz_ctrl_addr);
}
void config_rsz(struct rkisp1_stream *stream, struct v4l2_rect *in_y,
struct v4l2_rect *in_c, struct v4l2_rect *out_y,
struct v4l2_rect *out_c, bool async)
{
int i = 0;
/* No phase offset */
writel(0, stream->ispdev->base_addr + stream->config->rsz.phase_hy);
writel(0, stream->ispdev->base_addr + stream->config->rsz.phase_hc);
writel(0, stream->ispdev->base_addr + stream->config->rsz.phase_vy);
writel(0, stream->ispdev->base_addr + stream->config->rsz.phase_vc);
/* Linear interpolation */
for (i = 0; i < 64; i++) {
writel(i, stream->ispdev->base_addr + stream->config->rsz.scale_lut_addr);
writel(i, stream->ispdev->base_addr + stream->config->rsz.scale_lut);
}
set_scale(stream, in_y, in_c, out_y, out_c);
update_rsz_shadow(stream, async);
}
void disable_rsz(struct rkisp1_stream *stream, bool async)
{
writel(0, stream->ispdev->base_addr + stream->config->rsz.ctrl);
if (!async)
update_rsz_shadow(stream, async);
}
void config_mi_ctrl(struct rkisp1_stream *stream)
{
void __iomem *base = stream->ispdev->base_addr;
void __iomem *addr = base + CIF_MI_CTRL;
u32 reg;
reg = readl(addr) & ~GENMASK(17, 16);
writel(reg | CIF_MI_CTRL_BURST_LEN_LUM_64, addr);
reg = readl(addr) & ~GENMASK(19, 18);
writel(reg | CIF_MI_CTRL_BURST_LEN_CHROM_64, addr);
reg = readl(addr);
writel(reg | CIF_MI_CTRL_INIT_BASE_EN, addr);
reg = readl(addr);
writel(reg | CIF_MI_CTRL_INIT_OFFSET_EN, addr);
}
void mp_clr_frame_end_int(void __iomem *base)
{
writel(CIF_MI_MP_FRAME, base + CIF_MI_ICR);
}
void sp_clr_frame_end_int(void __iomem *base)
{
writel(CIF_MI_SP_FRAME, base + CIF_MI_ICR);
}
bool mp_is_frame_end_int_masked(void __iomem *base)
{
return (mi_get_masked_int_status(base) & CIF_MI_MP_FRAME);
}
bool sp_is_frame_end_int_masked(void __iomem *base)
{
return (mi_get_masked_int_status(base) & CIF_MI_SP_FRAME);
}
bool mp_is_stream_stopped(void __iomem *base)
{
int en;
en = CIF_MI_CTRL_SHD_MP_IN_ENABLED | CIF_MI_CTRL_SHD_RAW_OUT_ENABLED;
return !(readl(base + CIF_MI_CTRL_SHD) & en);
}
bool sp_is_stream_stopped(void __iomem *base)
{
return !(readl(base + CIF_MI_CTRL_SHD) & CIF_MI_CTRL_SHD_SP_IN_ENABLED);
}

File diff suppressed because it is too large Load Diff