isp10: rockchip: v0.1.6
[firefly-linux-kernel-4.4.55.git] / drivers / media / platform / rk-isp10 / cif_isp10_isp.h
1 /*
2  *************************************************************************
3  * Rockchip driver for CIF ISP 1.0
4  * (Based on Intel driver for sofiaxxx)
5  *
6  * Copyright (C) 2015 Intel Mobile Communications GmbH
7  * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *************************************************************************
15  */
16
17 #ifndef _CIF_ISP10_ISP_H
18 #define _CIF_ISP10_ISP_H
19
20 #include <media/v4l2-common.h>
21 #include <media/videobuf-core.h>
22 #include <media/rk-isp10-ioctl.h>
23 #include <media/v4l2-controls_rockchip.h>
24
25 /*
26  * ISP device struct
27  */
28 enum cif_isp10_pix_fmt;
29
30 enum cif_isp10_pix_fmt_quantization {
31         CIF_ISP10_QUANTIZATION_DEFAULT = 0,
32         CIF_ISP10_QUANTIZATION_FULL_RANGE = 1,
33         CIF_ISP10_QUANTIZATION_LIM_RANGE = 2
34 };
35
36 struct cif_isp10_isp_other_cfgs {
37         struct cifisp_isp_other_cfg *last_or_new;
38         struct cifisp_isp_other_cfg *curr;
39         struct cifisp_isp_other_cfg cfgs[2];
40         unsigned int module_updates;
41 };
42
43 struct cif_isp10_isp_meas_cfgs {
44         struct cifisp_isp_meas_cfg *last_or_new;
45         struct cifisp_isp_meas_cfg *curr;
46         struct cifisp_isp_meas_cfg cfgs[2];
47         unsigned int module_updates;
48 };
49
50 struct cif_isp10_isp_meas_stats {
51         unsigned int g_frame_id;
52         struct cifisp_stat_buffer stat;
53 };
54
55 struct cif_isp10_isp_dev {
56         /*
57          * Purpose of mutex is to protect and serialize use
58          * of isp data structure and CIF API calls.
59          */
60         struct mutex mutex;
61         /* Current ISP parameters */
62         spinlock_t config_lock;
63         struct cif_isp10_isp_other_cfgs other_cfgs;
64         struct cif_isp10_isp_meas_cfgs meas_cfgs;
65         struct cif_isp10_isp_meas_stats meas_stats;
66
67         bool cif_ism_cropping;
68
69         enum cif_isp10_pix_fmt_quantization quantization;
70
71         /* input resolution needed for LSC param check */
72         unsigned int input_width;
73         unsigned int input_height;
74         unsigned int active_lsc_width;
75         unsigned int active_lsc_height;
76
77         /* ISP statistics related */
78         spinlock_t irq_lock;
79         /* ISP statistics related */
80         spinlock_t req_lock;
81         struct videobuf_queue vbq_stat;
82         struct list_head stat;
83         void __iomem *base_addr;    /* registers base address */
84
85         bool streamon;
86         unsigned int v_blanking_us;
87
88         unsigned int frame_id;
89         unsigned int frame_id_setexp;
90         unsigned int active_meas;
91
92         struct timeval vs_t;    /* updated each frame */
93         struct timeval fi_t;    /* updated each frame */
94         struct workqueue_struct *readout_wq;
95
96         unsigned int *dev_id;
97 };
98
99 enum cif_isp10_isp_readout_cmd {
100         CIF_ISP10_ISP_READOUT_MEAS = 0,
101         CIF_ISP10_ISP_READOUT_META = 1,
102 };
103
104 struct cif_isp10_isp_readout_work {
105         struct work_struct work;
106         struct cif_isp10_isp_dev *isp_dev;
107
108         unsigned int frame_id;
109         enum cif_isp10_isp_readout_cmd readout;
110         struct videobuf_buffer *vb;
111         unsigned int stream_id;
112 };
113
114 int register_cifisp_device(
115         struct cif_isp10_isp_dev *isp_dev,
116         struct video_device *vdev_cifisp,
117         struct v4l2_device *v4l2_dev,
118         void __iomem *cif_reg_baseaddress);
119 void unregister_cifisp_device(struct video_device *vdev_cifisp);
120 void cifisp_configure_isp(
121         struct cif_isp10_isp_dev *isp_dev,
122         enum cif_isp10_pix_fmt in_pix_fmt,
123         enum cif_isp10_pix_fmt_quantization quantization);
124 void cifisp_disable_isp(struct cif_isp10_isp_dev *isp_dev);
125 int cifisp_isp_isr(struct cif_isp10_isp_dev *isp_dev, u32 isp_mis);
126 void cifisp_v_start(struct cif_isp10_isp_dev *isp_dev,
127         const struct timeval *timestamp);
128 void cifisp_frame_in(
129         struct cif_isp10_isp_dev *isp_dev,
130         const struct timeval *fi_t);
131 void cifisp_isp_readout_work(struct work_struct *work);
132
133 #endif