Revert "media: rockchip: isp: rkisp1 rename to rkisp"

This reverts commit 87184fa353
Reason for old platform, so isp1 version alone

Change-Id: Ib7fa24d080f31084262d401ef3308879d0ffc99c
Signed-off-by: Cai YiWei <cyw@rock-chips.com>
This commit is contained in:
Cai YiWei
2020-05-29 10:50:14 +08:00
committed by Tao Huang
parent c492b822ca
commit f7f571cf6c
22 changed files with 12688 additions and 18 deletions

View File

@@ -138,6 +138,7 @@ source "drivers/media/platform/xilinx/Kconfig"
source "drivers/media/platform/rcar-vin/Kconfig"
source "drivers/media/platform/atmel/Kconfig"
source "drivers/media/platform/rockchip/cif/Kconfig"
source "drivers/media/platform/rockchip/isp1/Kconfig"
source "drivers/media/platform/rockchip/isp/Kconfig"
source "drivers/media/platform/rockchip/ispp/Kconfig"

View File

@@ -68,6 +68,7 @@ obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/
obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip/rga/
obj-$(CONFIG_VIDEO_ROCKCHIP_CIF) += rockchip/cif/
obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += rockchip/isp1/
obj-$(CONFIG_VIDEO_ROCKCHIP_ISP) += rockchip/isp/
obj-$(CONFIG_VIDEO_ROCKCHIP_ISPP) += rockchip/ispp/

View File

@@ -9,16 +9,4 @@ config VIDEO_ROCKCHIP_ISP
select PHY_ROCKCHIP_MIPI_RX
default n
help
Support for ISP1 on the rockchip SoC.
config VIDEO_ROCKCHIP_ISP1
tristate "Rockchip Image Signal Processing V1 Unit driver (DEPRECATED)"
depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
depends on ARCH_ROCKCHIP || COMPILE_TEST
select VIDEO_ROCKCHIP_ISP
default n
help
Support for ISP1 on the rockchip SoC.
This config option is here only for backward compatibility.
Use VIDEO_ROCKCHIP_ISP instead.
Support for ISP on the rockchip SoC.

View File

@@ -44,12 +44,7 @@
#include "isp_stats.h"
#include "isp_mipi_luma.h"
#ifdef CONFIG_VIDEO_ROCKCHIP_ISP1
#define DRIVER_NAME "rkisp1"
#else
#define DRIVER_NAME "rkisp"
#endif
#define ISP_VDEV_NAME DRIVER_NAME "_ispdev"
#define SP_VDEV_NAME DRIVER_NAME "_selfpath"
#define MP_VDEV_NAME DRIVER_NAME "_mainpath"

View File

@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
config VIDEO_ROCKCHIP_ISP1
tristate "Rockchip Image Signal Processing v1 Unit driver"
depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
depends on ARCH_ROCKCHIP || COMPILE_TEST
select VIDEOBUF2_DMA_CONTIG
select VIDEOBUF2_VMALLOC
select V4L2_FWNODE
select PHY_ROCKCHIP_MIPI_RX
default n
help
Support for ISP1 on the rockchip SoC.

View File

@@ -0,0 +1,10 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += video_rkisp1.o
video_rkisp1-objs += rkisp1.o \
dev.o \
regs.o \
isp_stats.o \
isp_params.o \
capture.o \
dmarx.o

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,219 @@
/*
* 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
};
enum rkisp1_field {
RKISP_FIELD_ODD,
RKISP_FIELD_EVEN,
RKISP_FIELD_INVAL,
};
struct rkisp1_stream_sp {
int y_stride;
int vir_offs;
enum rkisp1_sp_inp input_sel;
enum rkisp1_field field;
enum rkisp1_field field_rec;
};
struct rkisp1_stream_mp {
bool raw_enable;
};
struct rkisp1_stream_raw {
u8 pre_stop;
};
struct rkisp1_stream_dmarx {
int y_stride;
};
/* 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);
bool (*is_stream_stopped)(void __iomem *base);
void (*update_mi)(struct rkisp1_stream *stream);
};
/*
* 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 {
unsigned id:2;
unsigned interlaced:1;
struct rkisp1_device *ispdev;
struct rkisp1_vdev_node vnode;
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 streaming;
bool stopping;
bool frame_end;
wait_queue_head_t done;
unsigned int burst;
union {
struct rkisp1_stream_sp sp;
struct rkisp1_stream_mp mp;
struct rkisp1_stream_raw raw;
struct rkisp1_stream_dmarx dmarx;
} u;
};
void rkisp1_unregister_stream_vdevs(struct rkisp1_device *dev);
int rkisp1_register_stream_vdevs(struct rkisp1_device *dev);
void rkisp1_mi_isr(u32 mis_val, struct rkisp1_device *dev);
void rkisp1_stream_init(struct rkisp1_device *dev, u32 id);
void rkisp1_set_stream_def_fmt(struct rkisp1_device *dev, u32 id,
u32 width, u32 height, u32 pixelformat);
void rkisp1_mipi_dmatx0_end(u32 status, struct rkisp1_device *dev);
int fcc_xysubs(u32 fcc, u32 *xsubs, u32 *ysubs);
int rkisp1_fh_open(struct file *filp);
int rkisp1_fop_release(struct file *file);
#endif /* _RKISP1_PATH_VIDEO_H */

View File

@@ -0,0 +1,133 @@
/*
* 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_COMMON_H
#define _RKISP1_COMMON_H
#include <linux/mutex.h>
#include <linux/media.h>
#include <media/media-device.h>
#include <media/media-entity.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/videobuf2-v4l2.h>
#include <media/v4l2-mc.h>
#define RKISP1_DEFAULT_WIDTH 800
#define RKISP1_DEFAULT_HEIGHT 600
#define RKISP1_MAX_STREAM 3
#define RKISP1_STREAM_MP 0
#define RKISP1_STREAM_SP 1
#define RKISP1_STREAM_RAW 2
#define RKISP1_PLANE_Y 0
#define RKISP1_PLANE_CB 1
#define RKISP1_PLANE_CR 2
#define RKISP1_EMDDATA_FIFO_MAX 4
#define RKISP1_DMATX_CHECK 0xA5A5A5A5
#define RKISP1_RK3326_USE_OLDMIPI 0
enum rkisp1_sd_type {
RKISP1_SD_SENSOR,
RKISP1_SD_PHY_CSI,
RKISP1_SD_VCM,
RKISP1_SD_FLASH,
RKISP1_SD_MAX,
};
/* One structure per video node */
struct rkisp1_vdev_node {
struct vb2_queue buf_queue;
struct video_device vdev;
struct media_pad pad;
};
enum rkisp1_fmt_pix_type {
FMT_YUV,
FMT_RGB,
FMT_BAYER,
FMT_JPEG,
FMT_MAX
};
enum rkisp1_fmt_raw_pat_type {
RAW_RGGB = 0,
RAW_GRBG,
RAW_GBRG,
RAW_BGGR,
};
struct rkisp1_buffer {
struct vb2_v4l2_buffer vb;
struct list_head queue;
union {
u32 buff_addr[VIDEO_MAX_PLANES];
void *vaddr[VIDEO_MAX_PLANES];
};
};
struct rkisp1_dummy_buffer {
void *vaddr;
dma_addr_t dma_addr;
u32 size;
};
extern int rkisp1_debug;
static inline
struct rkisp1_vdev_node *vdev_to_node(struct video_device *vdev)
{
return container_of(vdev, struct rkisp1_vdev_node, vdev);
}
static inline struct rkisp1_vdev_node *queue_to_node(struct vb2_queue *q)
{
return container_of(q, struct rkisp1_vdev_node, buf_queue);
}
static inline struct rkisp1_buffer *to_rkisp1_buffer(struct vb2_v4l2_buffer *vb)
{
return container_of(vb, struct rkisp1_buffer, vb);
}
static inline struct vb2_queue *to_vb2_queue(struct file *file)
{
struct rkisp1_vdev_node *vnode = video_drvdata(file);
return &vnode->buf_queue;
}
#endif /* _RKISP1_COMMON_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,173 @@
/*
* 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_DEV_H
#define _RKISP1_DEV_H
#include "capture.h"
#include "dmarx.h"
#include "rkisp1.h"
#include "isp_params.h"
#include "isp_stats.h"
#define DRIVER_NAME "rkisp1"
#define ISP_VDEV_NAME DRIVER_NAME "_ispdev"
#define SP_VDEV_NAME DRIVER_NAME "_selfpath"
#define MP_VDEV_NAME DRIVER_NAME "_mainpath"
#define DMA_VDEV_NAME DRIVER_NAME "_dmapath"
#define RAW_VDEV_NAME DRIVER_NAME "_rawpath"
#define GRP_ID_SENSOR BIT(0)
#define GRP_ID_MIPIPHY BIT(1)
#define GRP_ID_ISP BIT(2)
#define GRP_ID_ISP_MP BIT(3)
#define GRP_ID_ISP_SP BIT(4)
#define GRP_ID_ISP_DMARX BIT(5)
#define RKISP1_MAX_BUS_CLK 8
#define RKISP1_MAX_SENSOR 2
#define RKISP1_MAX_PIPELINE 4
#define RKISP1_MEDIA_BUS_FMT_MASK 0xF000
#define RKISP1_MEDIA_BUS_FMT_BAYER 0x3000
#define RKISP1_CONTI_ERR_MAX 50
/* ISP_V10_1 for only support MP */
enum rkisp1_isp_ver {
ISP_V10 = 0x00,
ISP_V10_1 = 0x01,
ISP_V11 = 0x10,
ISP_V12 = 0x20,
ISP_V13 = 0x30,
};
enum rkisp1_isp_state {
ISP_STOP = 0,
ISP_START,
ISP_ERROR
};
enum rkisp1_isp_inp {
INP_INVAL = 0,
INP_CSI,
INP_DVP,
INP_DMARX_ISP,
};
/*
* struct rkisp1_pipeline - An ISP hardware pipeline
*
* Capture device call other devices via pipeline
*
* @num_subdevs: number of linked subdevs
* @power_cnt: pipeline power count
* @stream_cnt: stream power count
*/
struct rkisp1_pipeline {
struct media_pipeline pipe;
int num_subdevs;
atomic_t power_cnt;
atomic_t stream_cnt;
struct v4l2_subdev *subdevs[RKISP1_MAX_PIPELINE];
int (*open)(struct rkisp1_pipeline *p,
struct media_entity *me, bool prepare);
int (*close)(struct rkisp1_pipeline *p);
int (*set_stream)(struct rkisp1_pipeline *p, bool on);
};
/*
* struct rkisp1_sensor_info - Sensor infomations
* @mbus: media bus configuration
*/
struct rkisp1_sensor_info {
struct v4l2_subdev *sd;
struct v4l2_mbus_config mbus;
struct v4l2_subdev_format fmt;
struct v4l2_subdev_pad_config cfg;
};
/*
* struct rkisp1_device - ISP platform device
* @base_addr: base register address
* @active_sensor: sensor in-use, set when streaming on
* @isp_sdev: ISP sub-device
* @rkisp1_stream: capture video device
* @stats_vdev: ISP statistics output device
* @params_vdev: ISP input parameters device
*/
struct rkisp1_device {
struct list_head list;
struct regmap *grf;
void __iomem *base_addr;
int irq;
struct device *dev;
struct clk *clks[RKISP1_MAX_BUS_CLK];
int num_clks;
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler ctrl_handler;
struct media_device media_dev;
struct v4l2_async_notifier notifier;
struct v4l2_subdev *subdevs[RKISP1_SD_MAX];
struct rkisp1_sensor_info *active_sensor;
struct rkisp1_sensor_info sensors[RKISP1_MAX_SENSOR];
int num_sensors;
struct rkisp1_isp_subdev isp_sdev;
struct rkisp1_stream stream[RKISP1_MAX_STREAM];
struct rkisp1_isp_stats_vdev stats_vdev;
struct rkisp1_isp_params_vdev params_vdev;
struct rkisp1_dmarx_device dmarx_dev;
struct rkisp1_pipeline pipe;
struct iommu_domain *domain;
enum rkisp1_isp_ver isp_ver;
const unsigned int *clk_rate_tbl;
int num_clk_rate_tbl;
atomic_t open_cnt;
struct rkisp1_emd_data emd_data_fifo[RKISP1_EMDDATA_FIFO_MAX];
unsigned int emd_data_idx;
unsigned int emd_vc;
unsigned int emd_dt;
int vs_irq;
int mipi_irq;
struct gpio_desc *vs_irq_gpio;
struct v4l2_subdev *hdr_sensor;
enum rkisp1_isp_state isp_state;
unsigned int isp_err_cnt;
enum rkisp1_isp_inp isp_inp;
struct mutex apilock; /* mutex to serialize the calls of stream */
struct mutex iqlock; /* mutex to serialize the calls of iq */
wait_queue_head_t sync_onoff;
};
#endif

View File

@@ -0,0 +1,691 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd. */
#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <media/v4l2-common.h>
#include <media/v4l2-event.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-subdev.h>
#include <media/videobuf2-dma-contig.h>
#include <linux/dma-iommu.h>
#include "dev.h"
#include "regs.h"
#define CIF_ISP_REQ_BUFS_MIN 1
static const struct capture_fmt dmarx_fmts[] = {
/* bayer raw */
{
.fourcc = V4L2_PIX_FMT_SRGGB8,
.mbus_code = MEDIA_BUS_FMT_SRGGB8_1X8,
.fmt_type = FMT_BAYER,
.bpp = { 8 },
.mplanes = 1,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_RGB_BAYER_8BIT,
}, {
.fourcc = V4L2_PIX_FMT_SGRBG8,
.mbus_code = MEDIA_BUS_FMT_SGRBG8_1X8,
.fmt_type = FMT_BAYER,
.bpp = { 8 },
.mplanes = 1,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_RGB_BAYER_8BIT,
}, {
.fourcc = V4L2_PIX_FMT_SGBRG8,
.mbus_code = MEDIA_BUS_FMT_SGBRG8_1X8,
.fmt_type = FMT_BAYER,
.bpp = { 8 },
.mplanes = 1,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_RGB_BAYER_8BIT,
}, {
.fourcc = V4L2_PIX_FMT_SBGGR8,
.mbus_code = MEDIA_BUS_FMT_SBGGR8_1X8,
.fmt_type = FMT_BAYER,
.bpp = { 8 },
.mplanes = 1,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_RGB_BAYER_8BIT,
}, { /* 12bit used, 4 lower bits of LSB unused */
.fourcc = V4L2_PIX_FMT_SBGGR16,
.mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12,
.fmt_type = FMT_BAYER,
.bpp = { 16 },
.mplanes = 1,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_RGB_BAYER_16BIT,
}, {
.fourcc = V4L2_PIX_FMT_YUYV,
.mbus_code = MEDIA_BUS_FMT_YUYV8_2X8,
.fmt_type = FMT_YUV,
.bpp = { 16 },
.cplanes = 1,
.mplanes = 1,
.uv_swap = 0,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_FMT_YUV422,
}, {
.fourcc = V4L2_PIX_FMT_YVYU,
.mbus_code = MEDIA_BUS_FMT_YVYU8_2X8,
.fmt_type = FMT_YUV,
.bpp = { 16 },
.cplanes = 1,
.mplanes = 1,
.uv_swap = 0,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_FMT_YUV422,
}, {
.fourcc = V4L2_PIX_FMT_UYVY,
.mbus_code = MEDIA_BUS_FMT_UYVY8_2X8,
.fmt_type = FMT_YUV,
.bpp = { 16 },
.cplanes = 1,
.mplanes = 1,
.uv_swap = 0,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_FMT_YUV422,
}, {
.fourcc = V4L2_PIX_FMT_VYUY,
.mbus_code = MEDIA_BUS_FMT_VYUY8_2X8,
.fmt_type = FMT_YUV,
.bpp = { 16 },
.cplanes = 1,
.mplanes = 1,
.uv_swap = 0,
.write_format = CIF_MI_DMA_CTRL_READ_FMT_PACKED,
.output_format = CIF_MI_DMA_CTRL_FMT_YUV422,
}
};
static struct stream_config rkisp1_dmarx_stream_config = {
.fmts = dmarx_fmts,
.fmt_size = ARRAY_SIZE(dmarx_fmts),
.mi = {
.y_size_init = CIF_MI_DMA_Y_PIC_SIZE,
.y_base_ad_init = CIF_MI_DMA_Y_PIC_START_AD,
.cb_base_ad_init = CIF_MI_DMA_CB_PIC_START_AD,
.cr_base_ad_init = CIF_MI_DMA_CR_PIC_START_AD,
},
};
static const
struct capture_fmt *find_fmt(struct rkisp1_stream *stream,
const u32 pixelfmt)
{
const struct capture_fmt *fmt;
int i;
for (i = 0; i < stream->config->fmt_size; i++) {
fmt = &stream->config->fmts[i];
if (fmt->fourcc == pixelfmt)
return fmt;
}
return NULL;
}
static int dmarx_config_mi(struct rkisp1_stream *stream)
{
struct rkisp1_device *dev = stream->ispdev;
void __iomem *base = dev->base_addr;
struct capture_fmt *dmarx_in_fmt = &stream->out_isp_fmt;
v4l2_dbg(1, rkisp1_debug, &dev->v4l2_dev,
"%s %dx%x y_stride:%d\n", __func__,
stream->out_fmt.width,
stream->out_fmt.height,
stream->u.dmarx.y_stride);
mi_set_y_size(stream, stream->out_fmt.width *
stream->out_fmt.height);
dmarx_set_y_width(base, stream->out_fmt.width);
dmarx_set_y_line_length(base, stream->u.dmarx.y_stride);
mi_dmarx_ready_enable(stream);
if (dmarx_in_fmt->uv_swap)
dmarx_set_uv_swap(base);
dmarx_ctrl(base,
dmarx_in_fmt->write_format |
dmarx_in_fmt->output_format |
CIF_MI_DMA_CTRL_BURST_LEN_LUM_16 |
CIF_MI_DMA_CTRL_BURST_LEN_CHROM_16);
return 0;
}
static void update_dmarx(struct rkisp1_stream *stream)
{
void __iomem *base = stream->ispdev->base_addr;
if (stream->curr_buf) {
mi_set_y_addr(stream,
stream->curr_buf->buff_addr[RKISP1_PLANE_Y]);
mi_set_cb_addr(stream,
stream->curr_buf->buff_addr[RKISP1_PLANE_CB]);
mi_set_cr_addr(stream,
stream->curr_buf->buff_addr[RKISP1_PLANE_CR]);
mi_dmarx_start(base);
stream->frame_end = false;
}
}
static void dmarx_stop_mi(struct rkisp1_stream *stream)
{
mi_dmarx_ready_disable(stream);
}
static struct streams_ops rkisp1_dmarx_streams_ops = {
.config_mi = dmarx_config_mi,
.stop_mi = dmarx_stop_mi,
.update_mi = update_dmarx,
};
static int dmarx_frame_end(struct rkisp1_stream *stream)
{
unsigned long lock_flags = 0;
if (stream->curr_buf) {
vb2_buffer_done(&stream->curr_buf->vb.vb2_buf,
VB2_BUF_STATE_DONE);
stream->curr_buf = NULL;
}
spin_lock_irqsave(&stream->vbq_lock, lock_flags);
if (!list_empty(&stream->buf_queue)) {
stream->curr_buf =
list_first_entry(&stream->buf_queue,
struct rkisp1_buffer,
queue);
list_del(&stream->curr_buf->queue);
}
spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
stream->ops->update_mi(stream);
return 0;
}
/***************************** vb2 operations*******************************/
static void dmarx_stop(struct rkisp1_stream *stream)
{
struct rkisp1_device *dev = stream->ispdev;
struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
int ret = 0;
stream->stopping = true;
if (dev->isp_state == ISP_START &&
!stream->frame_end) {
ret = wait_event_timeout(stream->done,
!stream->streaming,
msecs_to_jiffies(500));
if (!ret)
v4l2_warn(v4l2_dev,
"dmarx:%d waiting on event return error %d\n",
stream->id, ret);
}
if (stream->ops->stop_mi)
stream->ops->stop_mi(stream);
stream->stopping = false;
stream->streaming = false;
stream->frame_end = false;
}
static int dmarx_start(struct rkisp1_stream *stream)
{
int ret;
ret = stream->ops->config_mi(stream);
if (ret)
return ret;
stream->curr_buf = NULL;
dmarx_frame_end(stream);
stream->streaming = true;
return 0;
}
static int rkisp1_queue_setup(struct vb2_queue *queue,
unsigned int *num_buffers,
unsigned int *num_planes,
unsigned int sizes[],
struct device *alloc_ctxs[])
{
struct rkisp1_stream *stream = queue->drv_priv;
struct rkisp1_device *dev = stream->ispdev;
const struct v4l2_pix_format_mplane *pixm = NULL;
const struct capture_fmt *isp_fmt = NULL;
u32 i;
pixm = &stream->out_fmt;
isp_fmt = &stream->out_isp_fmt;
*num_planes = isp_fmt->mplanes;
for (i = 0; i < isp_fmt->mplanes; i++) {
const struct v4l2_plane_pix_format *plane_fmt;
plane_fmt = &pixm->plane_fmt[i];
sizes[i] = plane_fmt->sizeimage;
}
v4l2_dbg(1, rkisp1_debug, &dev->v4l2_dev, "%s count %d, size %d\n",
v4l2_type_names[queue->type], *num_buffers, sizes[0]);
return 0;
}
/*
* The vb2_buffer are stored in rkisp1_buffer, in order to unify
* mplane buffer and none-mplane buffer.
*/
static void rkisp1_buf_queue(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct rkisp1_buffer *ispbuf = to_rkisp1_buffer(vbuf);
struct vb2_queue *queue = vb->vb2_queue;
struct rkisp1_stream *stream = queue->drv_priv;
unsigned long lock_flags = 0;
struct v4l2_pix_format_mplane *pixm = &stream->out_fmt;
struct capture_fmt *isp_fmt = &stream->out_isp_fmt;
int i;
memset(ispbuf->buff_addr, 0, sizeof(ispbuf->buff_addr));
for (i = 0; i < isp_fmt->mplanes; i++)
ispbuf->buff_addr[i] = vb2_dma_contig_plane_dma_addr(vb, i);
/*
* NOTE: plane_fmt[0].sizeimage is total size of all planes for single
* memory plane formats, so calculate the size explicitly.
*/
if (isp_fmt->mplanes == 1) {
for (i = 0; i < isp_fmt->cplanes - 1; i++) {
ispbuf->buff_addr[i + 1] = (i == 0) ?
ispbuf->buff_addr[i] +
pixm->plane_fmt[i].bytesperline *
pixm->height :
ispbuf->buff_addr[i] +
pixm->plane_fmt[i].sizeimage;
}
}
spin_lock_irqsave(&stream->vbq_lock, lock_flags);
if (stream->streaming &&
list_empty(&stream->buf_queue) &&
!stream->curr_buf) {
stream->curr_buf = ispbuf;
stream->ops->update_mi(stream);
} else {
list_add_tail(&ispbuf->queue, &stream->buf_queue);
}
spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
}
static void dmarx_stop_streaming(struct vb2_queue *queue)
{
struct rkisp1_stream *stream = queue->drv_priv;
struct rkisp1_buffer *buf;
unsigned long lock_flags = 0;
dmarx_stop(stream);
spin_lock_irqsave(&stream->vbq_lock, lock_flags);
if (stream->curr_buf) {
list_add_tail(&stream->curr_buf->queue, &stream->buf_queue);
stream->curr_buf = NULL;
}
while (!list_empty(&stream->buf_queue)) {
buf = list_first_entry(&stream->buf_queue,
struct rkisp1_buffer, queue);
list_del(&buf->queue);
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
}
spin_unlock_irqrestore(&stream->vbq_lock, lock_flags);
}
static int dmarx_start_streaming(struct vb2_queue *queue,
unsigned int count)
{
struct rkisp1_stream *stream = queue->drv_priv;
struct rkisp1_device *dev = stream->ispdev;
struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
int ret = 0;
if (atomic_read(&dev->open_cnt) < 2) {
v4l2_err(v4l2_dev,
"other stream should enable first\n");
return -EINVAL;
}
if (WARN_ON(stream->streaming))
return -EBUSY;
ret = dmarx_start(stream);
if (ret < 0)
v4l2_err(v4l2_dev,
"start dmarx stream:%d failed\n",
stream->id);
return ret;
}
static struct vb2_ops dmarx_vb2_ops = {
.queue_setup = rkisp1_queue_setup,
.buf_queue = rkisp1_buf_queue,
.wait_prepare = vb2_ops_wait_prepare,
.wait_finish = vb2_ops_wait_finish,
.stop_streaming = dmarx_stop_streaming,
.start_streaming = dmarx_start_streaming,
};
static int rkisp_init_vb2_queue(struct vb2_queue *q,
struct rkisp1_stream *stream,
enum v4l2_buf_type buf_type)
{
struct rkisp1_vdev_node *node;
node = queue_to_node(q);
q->type = buf_type;
q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_USERPTR;
q->drv_priv = stream;
q->ops = &dmarx_vb2_ops;
q->mem_ops = &vb2_dma_contig_memops;
q->buf_struct_size = sizeof(struct rkisp1_buffer);
q->min_buffers_needed = CIF_ISP_REQ_BUFS_MIN;
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->lock = &stream->ispdev->apilock;
return vb2_queue_init(q);
}
static int rkisp1_set_fmt(struct rkisp1_stream *stream,
struct v4l2_pix_format_mplane *pixm,
bool try)
{
const struct capture_fmt *fmt;
unsigned int imagsize = 0;
unsigned int planes;
u32 xsubs = 1, ysubs = 1;
unsigned int i;
fmt = find_fmt(stream, pixm->pixelformat);
if (!fmt) {
v4l2_err(&stream->ispdev->v4l2_dev,
"nonsupport pixelformat:%c%c%c%c\n",
pixm->pixelformat,
pixm->pixelformat >> 8,
pixm->pixelformat >> 16,
pixm->pixelformat >> 24);
return -EINVAL;
}
pixm->num_planes = fmt->mplanes;
pixm->field = V4L2_FIELD_NONE;
if (!pixm->quantization)
pixm->quantization = V4L2_QUANTIZATION_FULL_RANGE;
/* calculate size */
fcc_xysubs(fmt->fourcc, &xsubs, &ysubs);
planes = fmt->cplanes ? fmt->cplanes : fmt->mplanes;
for (i = 0; i < planes; i++) {
struct v4l2_plane_pix_format *plane_fmt;
unsigned int width, height, bytesperline;
plane_fmt = pixm->plane_fmt + i;
if (i == 0) {
width = pixm->width;
height = pixm->height;
} else {
width = pixm->width / xsubs;
height = pixm->height / ysubs;
}
bytesperline = width * DIV_ROUND_UP(fmt->bpp[i], 8);
/* stride is only available for sp stream and y plane */
if (i != 0 ||
plane_fmt->bytesperline < bytesperline)
plane_fmt->bytesperline = bytesperline;
plane_fmt->sizeimage = plane_fmt->bytesperline * height;
imagsize += plane_fmt->sizeimage;
}
/* convert to non-MPLANE format.
* it's important since we want to unify none-MPLANE
* and MPLANE.
*/
if (fmt->mplanes == 1)
pixm->plane_fmt[0].sizeimage = imagsize;
if (!try) {
stream->out_isp_fmt = *fmt;
stream->out_fmt = *pixm;
stream->u.dmarx.y_stride =
pixm->plane_fmt[0].bytesperline /
DIV_ROUND_UP(fmt->bpp[0], 8);
v4l2_dbg(1, rkisp1_debug, &stream->ispdev->v4l2_dev,
"%s: stream: %d req(%d, %d) out(%d, %d)\n", __func__,
stream->id, pixm->width, pixm->height,
stream->out_fmt.width, stream->out_fmt.height);
}
return 0;
}
/************************* v4l2_file_operations***************************/
static const struct v4l2_file_operations rkisp1_fops = {
.open = rkisp1_fh_open,
.release = rkisp1_fop_release,
.unlocked_ioctl = video_ioctl2,
.poll = vb2_fop_poll,
.mmap = vb2_fop_mmap,
};
static int rkisp1_try_fmt_vid_out_mplane(struct file *file, void *fh,
struct v4l2_format *f)
{
struct rkisp1_stream *stream = video_drvdata(file);
return rkisp1_set_fmt(stream, &f->fmt.pix_mp, true);
}
static int rkisp1_enum_fmt_vid_out_mplane(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
struct rkisp1_stream *stream = video_drvdata(file);
const struct capture_fmt *fmt = NULL;
if (f->index >= stream->config->fmt_size)
return -EINVAL;
fmt = &stream->config->fmts[f->index];
f->pixelformat = fmt->fourcc;
return 0;
}
static int rkisp1_s_fmt_vid_out_mplane(struct file *file,
void *priv, struct v4l2_format *f)
{
struct rkisp1_stream *stream = video_drvdata(file);
struct video_device *vdev = &stream->vnode.vdev;
struct rkisp1_vdev_node *node = vdev_to_node(vdev);
struct rkisp1_device *dev = stream->ispdev;
if (vb2_is_busy(&node->buf_queue)) {
v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__);
return -EBUSY;
}
return rkisp1_set_fmt(stream, &f->fmt.pix_mp, false);
}
static int rkisp1_g_fmt_vid_out_mplane(struct file *file, void *fh,
struct v4l2_format *f)
{
struct rkisp1_stream *stream = video_drvdata(file);
f->fmt.pix_mp = stream->out_fmt;
return 0;
}
static int rkisp1_querycap(struct file *file, void *priv,
struct v4l2_capability *cap)
{
struct rkisp1_stream *stream = video_drvdata(file);
struct device *dev = stream->ispdev->dev;
struct video_device *vdev = video_devdata(file);
strlcpy(cap->card, vdev->name, sizeof(cap->card));
snprintf(cap->driver, sizeof(cap->driver),
"%s_v%d", dev->driver->name,
stream->ispdev->isp_ver >> 4);
snprintf(cap->bus_info, sizeof(cap->bus_info),
"platform:%s", dev_name(dev));
return 0;
}
static const struct v4l2_ioctl_ops rkisp1_dmarx_ioctl = {
.vidioc_reqbufs = vb2_ioctl_reqbufs,
.vidioc_querybuf = vb2_ioctl_querybuf,
.vidioc_create_bufs = vb2_ioctl_create_bufs,
.vidioc_qbuf = vb2_ioctl_qbuf,
.vidioc_expbuf = vb2_ioctl_expbuf,
.vidioc_dqbuf = vb2_ioctl_dqbuf,
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
.vidioc_streamon = vb2_ioctl_streamon,
.vidioc_streamoff = vb2_ioctl_streamoff,
.vidioc_try_fmt_vid_out_mplane = rkisp1_try_fmt_vid_out_mplane,
.vidioc_enum_fmt_vid_out_mplane = rkisp1_enum_fmt_vid_out_mplane,
.vidioc_s_fmt_vid_out_mplane = rkisp1_s_fmt_vid_out_mplane,
.vidioc_g_fmt_vid_out_mplane = rkisp1_g_fmt_vid_out_mplane,
.vidioc_querycap = rkisp1_querycap,
};
static void rkisp1_unregister_dmarx_video(struct rkisp1_stream *stream)
{
media_entity_cleanup(&stream->vnode.vdev.entity);
video_unregister_device(&stream->vnode.vdev);
}
static int rkisp1_register_dmarx_video(struct rkisp1_stream *stream)
{
struct rkisp1_device *dev = stream->ispdev;
struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
struct video_device *vdev = &stream->vnode.vdev;
struct rkisp1_vdev_node *node;
int ret = 0;
node = vdev_to_node(vdev);
vdev->release = video_device_release_empty;
vdev->fops = &rkisp1_fops;
vdev->minor = -1;
vdev->v4l2_dev = v4l2_dev;
vdev->lock = &dev->apilock;
video_set_drvdata(vdev, stream);
vdev->ioctl_ops = &rkisp1_dmarx_ioctl;
vdev->device_caps = V4L2_CAP_VIDEO_OUTPUT_MPLANE |
V4L2_CAP_STREAMING;
vdev->vfl_dir = VFL_DIR_TX;
node->pad.flags = MEDIA_PAD_FL_SOURCE;
rkisp_init_vb2_queue(&node->buf_queue, stream,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
vdev->queue = &node->buf_queue;
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
if (ret < 0) {
v4l2_err(v4l2_dev,
"video register failed with error %d\n", ret);
return ret;
}
ret = media_entity_pads_init(&vdev->entity, 1, &node->pad);
if (ret < 0)
goto unreg;
return 0;
unreg:
video_unregister_device(vdev);
return ret;
}
/**************** Interrupter Handler ****************/
void rkisp1_dmarx_isr(u32 mis_val, struct rkisp1_device *dev)
{
void __iomem *base = dev->base_addr;
struct rkisp1_stream *stream;
if (mis_val & CIF_MI_DMA_READY) {
stream = &dev->dmarx_dev.stream[RKISP1_STREAM_DMARX];
stream->frame_end = true;
writel(CIF_MI_DMA_READY, base + CIF_MI_ICR);
if (stream->stopping) {
stream->stopping = false;
stream->streaming = false;
wake_up(&stream->done);
} else {
dmarx_frame_end(stream);
}
}
}
int rkisp1_register_dmarx_vdev(struct rkisp1_device *dev)
{
struct rkisp1_dmarx_device *dmarx_dev = &dev->dmarx_dev;
struct rkisp1_stream *stream;
struct video_device *vdev;
struct media_entity *source, *sink;
int ret = 0;
memset(dmarx_dev, 0, sizeof(*dmarx_dev));
dmarx_dev->ispdev = dev;
if (dev->isp_ver <= ISP_V13) {
stream = &dmarx_dev->stream[RKISP1_STREAM_DMARX];
INIT_LIST_HEAD(&stream->buf_queue);
init_waitqueue_head(&stream->done);
spin_lock_init(&stream->vbq_lock);
stream->id = RKISP1_STREAM_DMARX;
stream->ispdev = dev;
stream->ops = &rkisp1_dmarx_streams_ops;
stream->config = &rkisp1_dmarx_stream_config;
vdev = &stream->vnode.vdev;
strlcpy(vdev->name, DMA_VDEV_NAME, sizeof(vdev->name));
ret = rkisp1_register_dmarx_video(stream);
if (ret < 0)
return ret;
/* dmarx links -> isp subdev */
source = &vdev->entity;
sink = &dev->isp_sdev.sd.entity;
ret = media_create_pad_link(source, 0,
sink, RKISP1_ISP_PAD_SINK, 0);
}
return ret;
}
void rkisp1_unregister_dmarx_vdev(struct rkisp1_device *dev)
{
struct rkisp1_dmarx_device *dmarx_dev = &dev->dmarx_dev;
struct rkisp1_stream *stream;
if (dev->isp_ver <= ISP_V13) {
stream = &dmarx_dev->stream[RKISP1_STREAM_DMARX];
rkisp1_unregister_dmarx_video(stream);
}
}

View File

@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd. */
#ifndef _RKISP1_DMARX_H
#define _RKISP1_DMARX_H
#include "capture.h"
#include "common.h"
#define RKISP1_STREAM_DMARX 0
#define RKISP1_MAX_DMARX_STREAM 1
struct rkisp1_dmarx_device;
enum rkisp1_dmarx_pad {
RKISP1_DMARX_PAD_SINK,
RKISP1_DMARX_PAD_SOURCE,
RKISP1_DMARX_PAD_MAX
};
struct rkisp1_dmarx_device {
struct rkisp1_device *ispdev;
struct rkisp1_stream stream[RKISP1_MAX_DMARX_STREAM];
};
void rkisp1_dmarx_isr(u32 mis_val, struct rkisp1_device *dev);
void rkisp1_unregister_dmarx_vdev(struct rkisp1_device *dev);
int rkisp1_register_dmarx_vdev(struct rkisp1_device *dev);
#endif /* _RKISP1_DMARX_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
/*
* 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_ISP_H
#define _RKISP1_ISP_H
#include <linux/rkisp1-config.h>
#include <linux/rk-preisp.h>
#include "common.h"
struct rkisp1_isp_params_vdev;
struct rkisp1_isp_params_ops {
void (*dpcc_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_dpcc_config *arg);
void (*bls_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_bls_config *arg);
void (*lsc_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_lsc_config *arg);
void (*lsc_matrix_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_lsc_config *pconfig);
void (*flt_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_flt_config *arg);
void (*bdm_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_bdm_config *arg);
void (*sdg_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_sdg_config *arg);
void (*goc_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_goc_config *arg);
void (*ctk_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_ctk_config *arg);
void (*ctk_enable)(struct rkisp1_isp_params_vdev *params_vdev,
bool en);
void (*awb_meas_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_awb_meas_config *arg);
void (*awb_meas_enable)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_awb_meas_config *arg,
bool en);
void (*awb_gain_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_awb_gain_config *arg);
void (*aec_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_aec_config *arg);
void (*cproc_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_cproc_config *arg);
void (*hst_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_hst_config *arg);
void (*hst_enable)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_hst_config *arg, bool en);
void (*afm_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_afc_config *arg);
void (*ie_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_ie_config *arg);
void (*ie_enable)(struct rkisp1_isp_params_vdev *params_vdev,
bool en);
void (*csm_config)(struct rkisp1_isp_params_vdev *params_vdev,
bool full_range);
void (*dpf_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_dpf_config *arg);
void (*dpf_strength_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_dpf_strength_config *arg);
void (*wdr_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_wdr_config *arg);
void (*wdr_enable)(struct rkisp1_isp_params_vdev *params_vdev,
bool en);
void (*demosaiclp_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_demosaiclp_config *arg);
void (*demosaiclp_enable)(struct rkisp1_isp_params_vdev *params_vdev,
bool en);
void (*rkiesharp_config)(struct rkisp1_isp_params_vdev *params_vdev,
const struct cifisp_rkiesharp_config *arg);
void (*rkiesharp_enable)(struct rkisp1_isp_params_vdev *params_vdev,
bool en);
};
struct rkisp1_isp_params_config {
const int gamma_out_max_samples;
const int hst_weight_grids_size;
};
/*
* struct rkisp1_isp_subdev - ISP input parameters device
*
* @cur_params: Current ISP parameters
* @first_params: the first params should take effect immediately
*/
struct rkisp1_isp_params_vdev {
struct rkisp1_vdev_node vnode;
struct rkisp1_device *dev;
spinlock_t config_lock;
struct list_head params;
struct rkisp1_isp_params_cfg cur_params;
struct v4l2_format vdev_fmt;
bool streamon;
bool first_params;
enum v4l2_quantization quantization;
enum rkisp1_fmt_raw_pat_type raw_type;
u32 in_mbus_code;
struct preisp_hdrae_para_s hdrae_para;
struct rkisp1_isp_params_ops *ops;
struct rkisp1_isp_params_config *config;
};
/* config params before ISP streaming */
void rkisp1_params_configure_isp(struct rkisp1_isp_params_vdev *params_vdev,
struct ispsd_in_fmt *in_fmt,
enum v4l2_quantization quantization);
void rkisp1_params_disable_isp(struct rkisp1_isp_params_vdev *params_vdev);
int rkisp1_register_params_vdev(struct rkisp1_isp_params_vdev *params_vdev,
struct v4l2_device *v4l2_dev,
struct rkisp1_device *dev);
void rkisp1_unregister_params_vdev(struct rkisp1_isp_params_vdev *params_vdev);
void rkisp1_params_isr(struct rkisp1_isp_params_vdev *params_vdev, u32 isp_mis);
#endif /* _RKISP1_ISP_H */

View File

@@ -0,0 +1,688 @@
/*
* 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 <linux/kfifo.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-vmalloc.h> /* for ISP statistics */
#include "dev.h"
#include "regs.h"
#define RKISP1_ISP_STATS_REQ_BUFS_MIN 2
#define RKISP1_ISP_STATS_REQ_BUFS_MAX 8
static int rkisp1_stats_enum_fmt_meta_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
struct video_device *video = video_devdata(file);
struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
if (f->index > 0 || f->type != video->queue->type)
return -EINVAL;
f->pixelformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
return 0;
}
static int rkisp1_stats_g_fmt_meta_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct video_device *video = video_devdata(file);
struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(video);
struct v4l2_meta_format *meta = &f->fmt.meta;
if (f->type != video->queue->type)
return -EINVAL;
memset(meta, 0, sizeof(*meta));
meta->dataformat = stats_vdev->vdev_fmt.fmt.meta.dataformat;
meta->buffersize = stats_vdev->vdev_fmt.fmt.meta.buffersize;
return 0;
}
static int rkisp1_stats_querycap(struct file *file,
void *priv, struct v4l2_capability *cap)
{
struct video_device *vdev = video_devdata(file);
struct rkisp1_isp_stats_vdev *stats_vdev = video_get_drvdata(vdev);
strcpy(cap->driver, DRIVER_NAME);
snprintf(cap->driver, sizeof(cap->driver),
"%s_v%d", DRIVER_NAME,
stats_vdev->dev->isp_ver >> 4);
strlcpy(cap->card, vdev->name, sizeof(cap->card));
strlcpy(cap->bus_info, "platform: " DRIVER_NAME, sizeof(cap->bus_info));
return 0;
}
/* ISP video device IOCTLs */
static const struct v4l2_ioctl_ops rkisp1_stats_ioctl = {
.vidioc_reqbufs = vb2_ioctl_reqbufs,
.vidioc_querybuf = vb2_ioctl_querybuf,
.vidioc_create_bufs = vb2_ioctl_create_bufs,
.vidioc_qbuf = vb2_ioctl_qbuf,
.vidioc_dqbuf = vb2_ioctl_dqbuf,
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
.vidioc_expbuf = vb2_ioctl_expbuf,
.vidioc_streamon = vb2_ioctl_streamon,
.vidioc_streamoff = vb2_ioctl_streamoff,
.vidioc_enum_fmt_meta_cap = rkisp1_stats_enum_fmt_meta_cap,
.vidioc_g_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
.vidioc_s_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
.vidioc_try_fmt_meta_cap = rkisp1_stats_g_fmt_meta_cap,
.vidioc_querycap = rkisp1_stats_querycap
};
struct v4l2_file_operations rkisp1_stats_fops = {
.mmap = vb2_fop_mmap,
.unlocked_ioctl = video_ioctl2,
.poll = vb2_fop_poll,
.open = v4l2_fh_open,
.release = vb2_fop_release
};
static int rkisp1_stats_vb2_queue_setup(struct vb2_queue *vq,
unsigned int *num_buffers,
unsigned int *num_planes,
unsigned int sizes[],
struct device *alloc_ctxs[])
{
struct rkisp1_isp_stats_vdev *stats_vdev = vq->drv_priv;
*num_planes = 1;
*num_buffers = clamp_t(u32, *num_buffers, RKISP1_ISP_STATS_REQ_BUFS_MIN,
RKISP1_ISP_STATS_REQ_BUFS_MAX);
sizes[0] = sizeof(struct rkisp1_stat_buffer);
INIT_LIST_HEAD(&stats_vdev->stat);
return 0;
}
static void rkisp1_stats_vb2_buf_queue(struct vb2_buffer *vb)
{
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
struct rkisp1_buffer *stats_buf = to_rkisp1_buffer(vbuf);
struct vb2_queue *vq = vb->vb2_queue;
struct rkisp1_isp_stats_vdev *stats_dev = vq->drv_priv;
stats_buf->vaddr[0] = vb2_plane_vaddr(vb, 0);
spin_lock_bh(&stats_dev->rd_lock);
list_add_tail(&stats_buf->queue, &stats_dev->stat);
spin_unlock_bh(&stats_dev->rd_lock);
}
static void rkisp1_stats_vb2_stop_streaming(struct vb2_queue *vq)
{
struct rkisp1_isp_stats_vdev *stats_vdev = vq->drv_priv;
struct rkisp1_buffer *buf;
unsigned long flags;
int i;
/* Make sure no new work queued in isr before draining wq */
spin_lock_irqsave(&stats_vdev->irq_lock, flags);
stats_vdev->streamon = false;
spin_unlock_irqrestore(&stats_vdev->irq_lock, flags);
tasklet_disable(&stats_vdev->rd_tasklet);
spin_lock_bh(&stats_vdev->rd_lock);
for (i = 0; i < RKISP1_ISP_STATS_REQ_BUFS_MAX; i++) {
if (list_empty(&stats_vdev->stat))
break;
buf = list_first_entry(&stats_vdev->stat,
struct rkisp1_buffer, queue);
list_del(&buf->queue);
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
}
spin_unlock_bh(&stats_vdev->rd_lock);
}
static int
rkisp1_stats_vb2_start_streaming(struct vb2_queue *queue,
unsigned int count)
{
struct rkisp1_isp_stats_vdev *stats_vdev = queue->drv_priv;
stats_vdev->streamon = true;
kfifo_reset(&stats_vdev->rd_kfifo);
tasklet_enable(&stats_vdev->rd_tasklet);
return 0;
}
static struct vb2_ops rkisp1_stats_vb2_ops = {
.queue_setup = rkisp1_stats_vb2_queue_setup,
.buf_queue = rkisp1_stats_vb2_buf_queue,
.wait_prepare = vb2_ops_wait_prepare,
.wait_finish = vb2_ops_wait_finish,
.stop_streaming = rkisp1_stats_vb2_stop_streaming,
.start_streaming = rkisp1_stats_vb2_start_streaming,
};
static int rkisp1_stats_init_vb2_queue(struct vb2_queue *q,
struct rkisp1_isp_stats_vdev *stats_vdev)
{
struct rkisp1_vdev_node *node;
node = queue_to_node(q);
q->type = V4L2_BUF_TYPE_META_CAPTURE;
q->io_modes = VB2_MMAP | VB2_USERPTR;
q->drv_priv = stats_vdev;
q->ops = &rkisp1_stats_vb2_ops;
q->mem_ops = &vb2_vmalloc_memops;
q->buf_struct_size = sizeof(struct rkisp1_buffer);
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->lock = &stats_vdev->dev->iqlock;
q->dev = stats_vdev->dev->dev;
return vb2_queue_init(q);
}
static void rkisp1_stats_get_awb_meas_v10(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
/* Protect against concurrent access from ISR? */
u32 reg_val;
pbuf->meas_type |= CIFISP_STAT_AWB;
reg_val = readl(stats_vdev->dev->base_addr + CIF_ISP_AWB_WHITE_CNT_V10);
pbuf->params.awb.awb_mean[0].cnt = CIF_ISP_AWB_GET_PIXEL_CNT(reg_val);
reg_val = readl(stats_vdev->dev->base_addr + CIF_ISP_AWB_MEAN_V10);
pbuf->params.awb.awb_mean[0].mean_cr_or_r =
CIF_ISP_AWB_GET_MEAN_CR_R(reg_val);
pbuf->params.awb.awb_mean[0].mean_cb_or_b =
CIF_ISP_AWB_GET_MEAN_CB_B(reg_val);
pbuf->params.awb.awb_mean[0].mean_y_or_g =
CIF_ISP_AWB_GET_MEAN_Y_G(reg_val);
}
static void rkisp1_stats_get_awb_meas_v12(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
/* Protect against concurrent access from ISR? */
u32 reg_val;
pbuf->meas_type |= CIFISP_STAT_AWB;
reg_val = readl(stats_vdev->dev->base_addr + CIF_ISP_AWB_WHITE_CNT_V12);
pbuf->params.awb.awb_mean[0].cnt = CIF_ISP_AWB_GET_PIXEL_CNT(reg_val);
reg_val = readl(stats_vdev->dev->base_addr + CIF_ISP_AWB_MEAN_V12);
pbuf->params.awb.awb_mean[0].mean_cr_or_r =
CIF_ISP_AWB_GET_MEAN_CR_R(reg_val);
pbuf->params.awb.awb_mean[0].mean_cb_or_b =
CIF_ISP_AWB_GET_MEAN_CB_B(reg_val);
pbuf->params.awb.awb_mean[0].mean_y_or_g =
CIF_ISP_AWB_GET_MEAN_Y_G(reg_val);
}
static void rkisp1_stats_get_aec_meas_v10(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
unsigned int i;
void __iomem *addr = stats_vdev->dev->base_addr + CIF_ISP_EXP_MEAN_00_V10;
pbuf->meas_type |= CIFISP_STAT_AUTOEXP;
for (i = 0; i < stats_vdev->config->ae_mean_max; i++)
pbuf->params.ae.exp_mean[i] = (u8)readl(addr + i * 4);
}
static void rkisp1_stats_get_aec_meas_v12(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
int i;
void __iomem *addr = stats_vdev->dev->base_addr + CIF_ISP_EXP_MEAN_V12;
u32 value;
pbuf->meas_type |= CIFISP_STAT_AUTOEXP;
for (i = 0; i < stats_vdev->config->ae_mean_max / 4; i++) {
value = readl(addr + i * 4);
pbuf->params.ae.exp_mean[4 * i + 0] = CIF_ISP_EXP_GET_MEAN_xy0_V12(value);
pbuf->params.ae.exp_mean[4 * i + 1] = CIF_ISP_EXP_GET_MEAN_xy1_V12(value);
pbuf->params.ae.exp_mean[4 * i + 2] = CIF_ISP_EXP_GET_MEAN_xy2_V12(value);
pbuf->params.ae.exp_mean[4 * i + 3] = CIF_ISP_EXP_GET_MEAN_xy3_V12(value);
}
value = readl(addr + i * 4);
pbuf->params.ae.exp_mean[4 * i + 0] = CIF_ISP_EXP_GET_MEAN_xy0_V12(value);
}
static void rkisp1_stats_get_afc_meas(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
void __iomem *base_addr;
struct cifisp_af_stat *af;
pbuf->meas_type |= CIFISP_STAT_AFM_FIN;
af = &pbuf->params.af;
base_addr = stats_vdev->dev->base_addr;
af->window[0].sum = readl(base_addr + CIF_ISP_AFM_SUM_A);
af->window[0].lum = readl(base_addr + CIF_ISP_AFM_LUM_A);
af->window[1].sum = readl(base_addr + CIF_ISP_AFM_SUM_B);
af->window[1].lum = readl(base_addr + CIF_ISP_AFM_LUM_B);
af->window[2].sum = readl(base_addr + CIF_ISP_AFM_SUM_C);
af->window[2].lum = readl(base_addr + CIF_ISP_AFM_LUM_C);
}
static void rkisp1_stats_get_hst_meas_v10(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
int i;
void __iomem *addr = stats_vdev->dev->base_addr + CIF_ISP_HIST_BIN_0_V10;
pbuf->meas_type |= CIFISP_STAT_HIST;
for (i = 0; i < stats_vdev->config->hist_bin_n_max; i++)
pbuf->params.hist.hist_bins[i] = readl(addr + (i * 4));
}
static void rkisp1_stats_get_hst_meas_v12(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
int i;
void __iomem *addr = stats_vdev->dev->base_addr + CIF_ISP_HIST_BIN_V12;
u32 value;
pbuf->meas_type |= CIFISP_STAT_HIST;
for (i = 0; i < stats_vdev->config->hist_bin_n_max / 2; i++) {
value = readl(addr + (i * 4));
pbuf->params.hist.hist_bins[2 * i] = CIF_ISP_HIST_GET_BIN0_V12(value);
pbuf->params.hist.hist_bins[2 * i + 1] = CIF_ISP_HIST_GET_BIN1_V12(value);
}
}
static void rkisp1_stats_get_bls_meas(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
struct rkisp1_device *dev = stats_vdev->dev;
const struct ispsd_in_fmt *in_fmt =
rkisp1_get_ispsd_in_fmt(&dev->isp_sdev);
void __iomem *base = stats_vdev->dev->base_addr;
struct cifisp_bls_meas_val *bls_val;
bls_val = &pbuf->params.ae.bls_val;
if (in_fmt->bayer_pat == RAW_BGGR) {
bls_val->meas_b = readl(base + CIF_ISP_BLS_A_MEASURED);
bls_val->meas_gb = readl(base + CIF_ISP_BLS_B_MEASURED);
bls_val->meas_gr = readl(base + CIF_ISP_BLS_C_MEASURED);
bls_val->meas_r = readl(base + CIF_ISP_BLS_D_MEASURED);
} else if (in_fmt->bayer_pat == RAW_GBRG) {
bls_val->meas_gb = readl(base + CIF_ISP_BLS_A_MEASURED);
bls_val->meas_b = readl(base + CIF_ISP_BLS_B_MEASURED);
bls_val->meas_r = readl(base + CIF_ISP_BLS_C_MEASURED);
bls_val->meas_gr = readl(base + CIF_ISP_BLS_D_MEASURED);
} else if (in_fmt->bayer_pat == RAW_GRBG) {
bls_val->meas_gr = readl(base + CIF_ISP_BLS_A_MEASURED);
bls_val->meas_r = readl(base + CIF_ISP_BLS_B_MEASURED);
bls_val->meas_b = readl(base + CIF_ISP_BLS_C_MEASURED);
bls_val->meas_gb = readl(base + CIF_ISP_BLS_D_MEASURED);
} else if (in_fmt->bayer_pat == RAW_RGGB) {
bls_val->meas_r = readl(base + CIF_ISP_BLS_A_MEASURED);
bls_val->meas_gr = readl(base + CIF_ISP_BLS_B_MEASURED);
bls_val->meas_gb = readl(base + CIF_ISP_BLS_C_MEASURED);
bls_val->meas_b = readl(base + CIF_ISP_BLS_D_MEASURED);
}
}
static void rkisp1_stats_get_emb_data(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf)
{
unsigned int i;
struct rkisp1_device *dev = stats_vdev->dev;
unsigned int ph = 0, out = 0, packet_len = 0, playload_len = 0;
unsigned int mipi_kfifo_len;
unsigned int idx;
unsigned char *fifo_data;
idx = RKISP1_EMDDATA_FIFO_MAX;
for (i = 0; i < RKISP1_EMDDATA_FIFO_MAX; i++) {
if (dev->emd_data_fifo[i].frame_id == pbuf->frame_id) {
idx = i;
break;
}
}
if (idx == RKISP1_EMDDATA_FIFO_MAX)
return;
if (kfifo_is_empty(&dev->emd_data_fifo[idx].mipi_kfifo))
return;
mipi_kfifo_len = dev->emd_data_fifo[idx].data_len;
fifo_data = &pbuf->params.emd.data[0];
for (i = 0; i < mipi_kfifo_len;) {
/* handle the package header */
out = kfifo_out(&dev->emd_data_fifo[idx].mipi_kfifo,
&ph, sizeof(ph));
if (!out)
break;
packet_len = (ph >> 8) & 0xfff;
i += sizeof(ph);
/* handle the package data */
out = kfifo_out(&dev->emd_data_fifo[idx].mipi_kfifo,
fifo_data, packet_len);
if (!out)
break;
i += packet_len;
playload_len += packet_len;
fifo_data += packet_len;
v4l2_dbg(1, rkisp1_debug, &dev->v4l2_dev,
"packet_len: 0x%x, ph: 0x%x\n",
packet_len, ph);
}
pbuf->meas_type |= CIFISP_STAT_EMB_DATA;
v4l2_dbg(1, rkisp1_debug, &dev->v4l2_dev,
"playload_len: %d, pbuf->frame_id %d\n",
playload_len, pbuf->frame_id);
}
static struct rkisp1_stats_ops rkisp1_v10_stats_ops = {
.get_awb_meas = rkisp1_stats_get_awb_meas_v10,
.get_aec_meas = rkisp1_stats_get_aec_meas_v10,
.get_afc_meas = rkisp1_stats_get_afc_meas,
.get_hst_meas = rkisp1_stats_get_hst_meas_v10,
.get_bls_meas = rkisp1_stats_get_bls_meas,
.get_emb_data = rkisp1_stats_get_emb_data,
};
static struct rkisp1_stats_ops rkisp1_v12_stats_ops = {
.get_awb_meas = rkisp1_stats_get_awb_meas_v12,
.get_aec_meas = rkisp1_stats_get_aec_meas_v12,
.get_afc_meas = rkisp1_stats_get_afc_meas,
.get_hst_meas = rkisp1_stats_get_hst_meas_v12,
.get_bls_meas = rkisp1_stats_get_bls_meas,
};
static struct rkisp1_stats_config rkisp1_v10_stats_config = {
.ae_mean_max = 25,
.hist_bin_n_max = 16,
};
static struct rkisp1_stats_config rkisp1_v12_stats_config = {
.ae_mean_max = 81,
.hist_bin_n_max = 32,
};
static void
rkisp1_stats_send_measurement(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_isp_readout_work *meas_work)
{
unsigned int cur_frame_id = -1;
struct rkisp1_stat_buffer *cur_stat_buf;
struct rkisp1_buffer *cur_buf = NULL;
struct rkisp1_stats_ops *ops = stats_vdev->ops;
cur_frame_id = atomic_read(&stats_vdev->dev->isp_sdev.frm_sync_seq) - 1;
if (cur_frame_id != meas_work->frame_id) {
v4l2_warn(stats_vdev->vnode.vdev.v4l2_dev,
"Measurement late(%d, %d)\n",
cur_frame_id, meas_work->frame_id);
cur_frame_id = meas_work->frame_id;
}
spin_lock(&stats_vdev->rd_lock);
/* get one empty buffer */
if (!list_empty(&stats_vdev->stat)) {
cur_buf = list_first_entry(&stats_vdev->stat,
struct rkisp1_buffer, queue);
list_del(&cur_buf->queue);
}
spin_unlock(&stats_vdev->rd_lock);
if (!cur_buf)
return;
cur_stat_buf =
(struct rkisp1_stat_buffer *)(cur_buf->vaddr[0]);
memset(cur_stat_buf, 0, sizeof(*cur_stat_buf));
cur_stat_buf->frame_id = cur_frame_id;
if (meas_work->isp_ris & CIF_ISP_AWB_DONE) {
ops->get_awb_meas(stats_vdev, cur_stat_buf);
cur_stat_buf->meas_type |= CIFISP_STAT_AWB;
}
if (meas_work->isp_ris & CIF_ISP_AFM_FIN) {
ops->get_afc_meas(stats_vdev, cur_stat_buf);
cur_stat_buf->meas_type |= CIFISP_STAT_AFM_FIN;
}
if (meas_work->isp_ris & CIF_ISP_EXP_END) {
ops->get_aec_meas(stats_vdev, cur_stat_buf);
ops->get_bls_meas(stats_vdev, cur_stat_buf);
cur_stat_buf->meas_type |= CIFISP_STAT_AUTOEXP;
}
if (meas_work->isp_ris & CIF_ISP_HIST_MEASURE_RDY) {
ops->get_hst_meas(stats_vdev, cur_stat_buf);
cur_stat_buf->meas_type |= CIFISP_STAT_HIST;
}
if ((meas_work->isp_ris & CIF_ISP_FRAME) &&
ops->get_emb_data)
ops->get_emb_data(stats_vdev, cur_stat_buf);
vb2_set_plane_payload(&cur_buf->vb.vb2_buf, 0,
sizeof(struct rkisp1_stat_buffer));
cur_buf->vb.sequence = cur_frame_id;
cur_buf->vb.vb2_buf.timestamp = meas_work->timestamp;
vb2_buffer_done(&cur_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
}
static void rkisp1_stats_readout_task(unsigned long data)
{
unsigned int out = 0;
struct rkisp1_isp_readout_work work;
struct rkisp1_isp_stats_vdev *vdev =
(struct rkisp1_isp_stats_vdev *)data;
while (!kfifo_is_empty(&vdev->rd_kfifo)) {
out = kfifo_out(&vdev->rd_kfifo,
&work, sizeof(work));
if (!out)
break;
if (work.readout == RKISP1_ISP_READOUT_MEAS)
rkisp1_stats_send_measurement(vdev, &work);
}
}
int rkisp1_stats_isr(struct rkisp1_isp_stats_vdev *stats_vdev, u32 isp_ris)
{
unsigned int isp_mis_tmp = 0;
struct rkisp1_isp_readout_work work;
unsigned int cur_frame_id =
atomic_read(&stats_vdev->dev->isp_sdev.frm_sync_seq) - 1;
#ifdef LOG_ISR_EXE_TIME
ktime_t in_t = ktime_get();
#endif
spin_lock(&stats_vdev->irq_lock);
isp_mis_tmp = isp_ris & (CIF_ISP_AWB_DONE | CIF_ISP_AFM_FIN |
CIF_ISP_EXP_END | CIF_ISP_HIST_MEASURE_RDY);
if (isp_mis_tmp) {
writel(isp_mis_tmp,
stats_vdev->dev->base_addr + CIF_ISP_ICR);
isp_mis_tmp &= readl(stats_vdev->dev->base_addr + CIF_ISP_MIS);
if (isp_mis_tmp)
v4l2_err(stats_vdev->vnode.vdev.v4l2_dev,
"isp icr 3A info err: 0x%x 0x%x\n",
isp_mis_tmp, isp_ris);
}
if (!stats_vdev->streamon)
goto unlock;
if (isp_ris & (CIF_ISP_FRAME | CIF_ISP_AWB_DONE |
CIF_ISP_AFM_FIN | CIF_ISP_EXP_END |
CIF_ISP_HIST_MEASURE_RDY)) {
work.readout = RKISP1_ISP_READOUT_MEAS;
work.frame_id = cur_frame_id;
work.isp_ris = isp_ris;
work.timestamp = ktime_get_ns();
if (!kfifo_is_full(&stats_vdev->rd_kfifo))
kfifo_in(&stats_vdev->rd_kfifo,
&work, sizeof(work));
else
v4l2_err(stats_vdev->vnode.vdev.v4l2_dev,
"stats kfifo is full\n");
tasklet_schedule(&stats_vdev->rd_tasklet);
}
#ifdef LOG_ISR_EXE_TIME
if (isp_ris & (CIF_ISP_EXP_END | CIF_ISP_AWB_DONE |
CIF_ISP_FRAME | CIF_ISP_HIST_MEASURE_RDY)) {
unsigned int diff_us =
ktime_to_us(ktime_sub(ktime_get(), in_t));
if (diff_us > g_longest_isr_time)
g_longest_isr_time = diff_us;
v4l2_info(stats_vdev->vnode.vdev.v4l2_dev,
"isp_isr time %d %d\n", diff_us, g_longest_isr_time);
}
#endif
unlock:
spin_unlock(&stats_vdev->irq_lock);
return 0;
}
static void rkisp1_init_stats_vdev(struct rkisp1_isp_stats_vdev *stats_vdev)
{
stats_vdev->vdev_fmt.fmt.meta.dataformat =
V4L2_META_FMT_RK_ISP1_STAT_3A;
stats_vdev->vdev_fmt.fmt.meta.buffersize =
sizeof(struct rkisp1_stat_buffer);
if (stats_vdev->dev->isp_ver == ISP_V12 ||
stats_vdev->dev->isp_ver == ISP_V13) {
stats_vdev->ops = &rkisp1_v12_stats_ops;
stats_vdev->config = &rkisp1_v12_stats_config;
} else {
stats_vdev->ops = &rkisp1_v10_stats_ops;
stats_vdev->config = &rkisp1_v10_stats_config;
}
}
int rkisp1_register_stats_vdev(struct rkisp1_isp_stats_vdev *stats_vdev,
struct v4l2_device *v4l2_dev,
struct rkisp1_device *dev)
{
int ret;
struct rkisp1_vdev_node *node = &stats_vdev->vnode;
struct video_device *vdev = &node->vdev;
stats_vdev->dev = dev;
INIT_LIST_HEAD(&stats_vdev->stat);
spin_lock_init(&stats_vdev->irq_lock);
spin_lock_init(&stats_vdev->rd_lock);
strlcpy(vdev->name, "rkisp1-statistics", sizeof(vdev->name));
video_set_drvdata(vdev, stats_vdev);
vdev->ioctl_ops = &rkisp1_stats_ioctl;
vdev->fops = &rkisp1_stats_fops;
vdev->release = video_device_release_empty;
vdev->lock = &dev->iqlock;
vdev->v4l2_dev = v4l2_dev;
vdev->queue = &node->buf_queue;
vdev->device_caps = V4L2_CAP_META_CAPTURE | V4L2_CAP_STREAMING;
vdev->vfl_dir = VFL_DIR_RX;
rkisp1_stats_init_vb2_queue(vdev->queue, stats_vdev);
rkisp1_init_stats_vdev(stats_vdev);
video_set_drvdata(vdev, stats_vdev);
node->pad.flags = MEDIA_PAD_FL_SINK;
ret = media_entity_pads_init(&vdev->entity, 1, &node->pad);
if (ret < 0)
goto err_release_queue;
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
if (ret < 0) {
dev_err(&vdev->dev,
"could not register Video for Linux device\n");
goto err_cleanup_media_entity;
}
ret = kfifo_alloc(&stats_vdev->rd_kfifo,
RKISP1_READOUT_WORK_SIZE,
GFP_KERNEL);
if (ret) {
dev_err(&vdev->dev,
"kfifo_alloc failed with error %d\n",
ret);
goto err_cleanup_media_entity;
}
tasklet_init(&stats_vdev->rd_tasklet,
rkisp1_stats_readout_task,
(unsigned long)stats_vdev);
tasklet_disable(&stats_vdev->rd_tasklet);
return 0;
err_cleanup_media_entity:
media_entity_cleanup(&vdev->entity);
err_release_queue:
vb2_queue_release(vdev->queue);
return ret;
}
void rkisp1_unregister_stats_vdev(struct rkisp1_isp_stats_vdev *stats_vdev)
{
struct rkisp1_vdev_node *node = &stats_vdev->vnode;
struct video_device *vdev = &node->vdev;
kfifo_free(&stats_vdev->rd_kfifo);
tasklet_kill(&stats_vdev->rd_tasklet);
video_unregister_device(vdev);
media_entity_cleanup(&vdev->entity);
vb2_queue_release(vdev->queue);
}

View File

@@ -0,0 +1,112 @@
/*
* 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_ISP_STATS_H
#define _RKISP1_ISP_STATS_H
#include <linux/rkisp1-config.h>
#include <linux/interrupt.h>
#include <linux/kfifo.h>
#include "common.h"
#define RKISP1_READOUT_WORK_SIZE \
(8 * sizeof(struct rkisp1_isp_readout_work))
struct rkisp1_isp_stats_vdev;
enum rkisp1_isp_readout_cmd {
RKISP1_ISP_READOUT_MEAS,
RKISP1_ISP_READOUT_META,
};
struct rkisp1_isp_readout_work {
unsigned int frame_id;
unsigned int isp_ris;
enum rkisp1_isp_readout_cmd readout;
unsigned long long timestamp;
};
struct rkisp1_stats_ops {
void (*get_awb_meas)(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf);
void (*get_aec_meas)(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf);
void (*get_afc_meas)(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf);
void (*get_hst_meas)(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf);
void (*get_bls_meas)(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf);
void (*get_emb_data)(struct rkisp1_isp_stats_vdev *stats_vdev,
struct rkisp1_stat_buffer *pbuf);
};
struct rkisp1_stats_config {
const int ae_mean_max;
const int hist_bin_n_max;
};
/*
* struct rkisp1_isp_stats_vdev - ISP Statistics device
*
* @irq_lock: buffer queue lock
* @stat: stats buffer list
* @readout_wq: workqueue for statistics information read
*/
struct rkisp1_isp_stats_vdev {
struct rkisp1_vdev_node vnode;
struct rkisp1_device *dev;
spinlock_t irq_lock;
struct list_head stat;
struct v4l2_format vdev_fmt;
bool streamon;
spinlock_t rd_lock;
struct kfifo rd_kfifo;
struct tasklet_struct rd_tasklet;
struct rkisp1_stats_ops *ops;
struct rkisp1_stats_config *config;
};
int rkisp1_stats_isr(struct rkisp1_isp_stats_vdev *stats_vdev, u32 isp_ris);
int rkisp1_register_stats_vdev(struct rkisp1_isp_stats_vdev *stats_vdev,
struct v4l2_device *v4l2_dev,
struct rkisp1_device *dev);
void rkisp1_unregister_stats_vdev(struct rkisp1_isp_stats_vdev *stats_vdev);
#endif /* _RKISP1_ISP_STATS_H */

View File

@@ -0,0 +1,244 @@
/*
* 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, u32 burst)
{
void __iomem *base = stream->ispdev->base_addr;
void __iomem *addr = base + CIF_MI_CTRL;
u32 reg;
reg = readl(addr) & ~GENMASK(19, 16);
writel(reg | burst, 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);
}
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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,163 @@
/*
* 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_H
#define _RKISP1_H
#include <linux/kfifo.h>
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include <media/v4l2-fwnode.h>
#include "common.h"
#define CIF_ISP_INPUT_W_MAX 4416
#define CIF_ISP_INPUT_H_MAX 3312
#define CIF_ISP_INPUT_W_MAX_V12 3264
#define CIF_ISP_INPUT_H_MAX_V12 2448
#define CIF_ISP_INPUT_W_MAX_V13 1920
#define CIF_ISP_INPUT_H_MAX_V13 1080
#define CIF_ISP_INPUT_W_MIN 32
#define CIF_ISP_INPUT_H_MIN 16
#define CIF_ISP_OUTPUT_W_MAX CIF_ISP_INPUT_W_MAX
#define CIF_ISP_OUTPUT_H_MAX CIF_ISP_INPUT_H_MAX
#define CIF_ISP_OUTPUT_W_MIN CIF_ISP_INPUT_W_MIN
#define CIF_ISP_OUTPUT_H_MIN CIF_ISP_INPUT_H_MIN
#define CIF_ISP_ADD_DATA_VC_MAX 3
struct rkisp1_stream;
/*
* struct ispsd_in_fmt - ISP intput-pad format
*
* Translate mbus_code to hardware format values
*
* @bus_width: used for parallel
*/
struct ispsd_in_fmt {
u32 mbus_code;
u8 fmt_type;
u32 mipi_dt;
u32 yuv_seq;
enum rkisp1_fmt_raw_pat_type bayer_pat;
u8 bus_width;
};
struct ispsd_out_fmt {
u32 mbus_code;
u8 fmt_type;
};
struct rkisp1_ie_config {
unsigned int effect;
};
enum rkisp1_isp_pad {
RKISP1_ISP_PAD_SINK,
RKISP1_ISP_PAD_SINK_PARAMS,
RKISP1_ISP_PAD_SOURCE_PATH,
RKISP1_ISP_PAD_SOURCE_STATS,
RKISP1_ISP_PAD_MAX
};
/*
* struct rkisp1_isp_subdev - ISP sub-device
*
* See Cropping regions of ISP in rkisp1.c for details
* @in_frm: input size, don't have to be equal to sensor size
* @in_fmt: intput format
* @in_crop: crop for sink pad
* @out_fmt: output format
* @out_crop: output size
*
* @dphy_errctrl_disabled: if dphy errctrl is disabled(avoid endless interrupt)
* @frm_sync_seq: frame sequence, to sync frame_id between video devices.
* @quantization: output quantization
*/
struct rkisp1_isp_subdev {
struct v4l2_subdev sd;
struct media_pad pads[RKISP1_ISP_PAD_MAX];
struct v4l2_ctrl_handler ctrl_handler;
struct v4l2_mbus_framefmt in_frm;
struct ispsd_in_fmt in_fmt;
struct v4l2_rect in_crop;
struct ispsd_out_fmt out_fmt;
struct v4l2_rect out_crop;
bool dphy_errctrl_disabled;
atomic_t frm_sync_seq;
enum v4l2_quantization quantization;
};
struct rkisp1_emd_data {
struct kfifo mipi_kfifo;
unsigned int data_len;
unsigned int frame_id;
};
int rkisp1_register_isp_subdev(struct rkisp1_device *isp_dev,
struct v4l2_device *v4l2_dev);
void rkisp1_unregister_isp_subdev(struct rkisp1_device *isp_dev);
void rkisp1_mipi_isr(unsigned int mipi_mis, struct rkisp1_device *dev);
void rkisp1_mipi_v13_isr(unsigned int err1, unsigned int err2,
unsigned int err3, struct rkisp1_device *dev);
void rkisp1_isp_isr(unsigned int isp_mis, struct rkisp1_device *dev);
irqreturn_t rkisp1_vs_isr_handler(int irq, void *ctx);
int rkisp1_update_sensor_info(struct rkisp1_device *dev);
u32 rkisp1_mbus_pixelcode_to_v4l2(u32 pixelcode);
static inline
struct ispsd_out_fmt *rkisp1_get_ispsd_out_fmt(struct rkisp1_isp_subdev *isp_sdev)
{
return &isp_sdev->out_fmt;
}
static inline
struct ispsd_in_fmt *rkisp1_get_ispsd_in_fmt(struct rkisp1_isp_subdev *isp_sdev)
{
return &isp_sdev->in_fmt;
}
static inline
struct v4l2_rect *rkisp1_get_isp_sd_win(struct rkisp1_isp_subdev *isp_sdev)
{
return &isp_sdev->out_crop;
}
#endif /* _RKISP1_H */

View File

@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd. */
#ifndef _RKISP1_VERSION_H
#define _RKISP1_VERSION_H
#include <linux/version.h>
/*
*RKISP1 DRIVER VERSION NOTE
*
*v0.1.0:
*1. First version;
*
*v0.1.1:
*1. request isp irqs independently for rk3326/rk1808;
*2. fix demosaic is not bypass for grey sensor;
*3. rk3326 use csi2host instead of old mipi host;
*4. isp v12/v13 add raw stream;
*5. selfpath support interlace input;
*6. speed up stream off;
*7. support for RK3368;
*8. fix dvp data width config;
*9. fix sp rgb output format;
*10. del nonsupport yuv format;
*11. fix high fps preview blurred bug;
*12. support otp information;
*13. add module and lens name to match iq file;
*14. change vm149c driver and add vm149c dts node;
*15. support iesharp/demosaiclp/wdr for isp v12/v13;
*16. check first iq param is set or not;
*17. add macro to switch between old mipi and new mipi;
*18. stop isp when too many errors are reported;
*19. use tasklet to get 3A states;
*20. stop mipi with shutdown lan;
*21. check for capture S_FMT;
*22. raw patch with default sensor fmt&size;
*
*v0.1.2:
*1. fix reset on too high isp_clk rate will result in bus dead;
*2. add RKMODULE_LSC_CFG ioctl;
*
*v0.1.3:
*1. fix wrong RG10 format
*2. clear unready subdevice when kernel boot complete
*3. fix diff isp ver to get frame num
*4. enable af awb irq
*
*v0.1.4:
*1. add dmarx patch;
*2. fix get zero data when start stream again;
*3. add pipeline power management;
*
*v0.1.5:
*1. fix kernel reboot in monkey test;
*2. fix raw patch wrong RG10 format;
*3. fix isp iommu work after suspend;
*/
#define RKISP1_DRIVER_VERSION KERNEL_VERSION(0, 1, 0x5)
#endif