]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/media/platform/soc_camera/tegra_camera/common.h
c27c83cd455825a30662303af6119ab6ec40397f
[sojka/nv-tegra/linux-3.10.git] / drivers / media / platform / soc_camera / tegra_camera / common.h
1 /*
2  * Copyright (c) 2012-2015, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 #ifndef _TEGRA_CAMERA_COMMON_H_
18 #define _TEGRA_CAMERA_COMMON_H_
19
20 #include <linux/videodev2.h>
21
22 #include <media/videobuf2-dma-contig.h>
23 #include <media/soc_camera.h>
24
25 /* Buffer for one video frame */
26 struct tegra_camera_buffer {
27         struct vb2_buffer               vb; /* v4l buffer must be first */
28         struct list_head                queue;
29         struct soc_camera_device        *icd;
30         int                             output_channel;
31
32         /*
33          * Various buffer addresses shadowed so we don't have to recalculate
34          * per frame. These are calculated during videobuf_prepare.
35          */
36         dma_addr_t                      buffer_addr;
37         dma_addr_t                      buffer_addr_u;
38         dma_addr_t                      buffer_addr_v;
39         dma_addr_t                      start_addr;
40         dma_addr_t                      start_addr_u;
41         dma_addr_t                      start_addr_v;
42 };
43
44 static struct tegra_camera_buffer *to_tegra_vb(struct vb2_buffer *vb)
45 {
46         return container_of(vb, struct tegra_camera_buffer, vb);
47 }
48
49 struct tegra_camera_dev;
50
51 struct tegra_camera_clk {
52         const char      *name;
53         struct clk      *clk;
54         u32             freq;
55         int             use_devname;
56 };
57
58 struct tegra_camera_ops {
59         int (*clks_init)(struct tegra_camera_dev *cam, int port);
60         void (*clks_deinit)(struct tegra_camera_dev *cam);
61         void (*clks_enable)(struct tegra_camera_dev *cam);
62         void (*clks_disable)(struct tegra_camera_dev *cam);
63
64         void (*capture_clean)(struct tegra_camera_dev *vi2_cam);
65         int (*capture_setup)(struct tegra_camera_dev *vi2_cam);
66         int (*capture_start)(struct tegra_camera_dev *vi2_cam,
67                              struct tegra_camera_buffer *buf);
68         int (*capture_stop)(struct tegra_camera_dev *vi2_cam, int port);
69
70         void (*init_syncpts)(struct tegra_camera_dev *vi2_cam);
71         void (*free_syncpts)(struct tegra_camera_dev *vi2_cam);
72         void (*incr_syncpts)(struct tegra_camera_dev *vi2_cam);
73         void (*save_syncpts)(struct tegra_camera_dev *vi2_cam);
74
75         void (*activate)(struct tegra_camera_dev *vi2_cam);
76         void (*deactivate)(struct tegra_camera_dev *vi2_cam);
77         int (*port_is_valid)(int port);
78
79         int (*mipi_calibration)(struct tegra_camera_dev *vi2_cam);
80 };
81
82 struct tegra_camera_dev {
83         struct soc_camera_host          ici;
84         struct platform_device          *ndev;
85         struct nvhost_device_data       *ndata;
86
87         struct regulator                *reg;
88         const char                      *regulator_name;
89
90         struct tegra_camera_clk         *clks;
91         int                             num_clks;
92
93         struct tegra_camera_ops         *ops;
94
95         void __iomem                    *reg_base;
96         spinlock_t                      videobuf_queue_lock;
97         struct list_head                capture;
98         struct vb2_buffer               *active;
99         struct vb2_alloc_ctx            *alloc_ctx;
100         enum v4l2_field                 field;
101         int                             sequence_a;
102         int                             sequence_b;
103
104         struct task_struct              *kthread_capture;
105         wait_queue_head_t               wait;
106
107         /* syncpt ids */
108         u32                             syncpt_id_csi_a;
109         u32                             syncpt_id_csi_b;
110         u32                             syncpt_id_vip;
111
112         /* syncpt values */
113         u32                             syncpt_csi_a;
114         u32                             syncpt_csi_b;
115         u32                             syncpt_vip;
116
117         /* Debug */
118         int                             num_frames;
119         int                             enable_refcnt;
120
121         /* Test Pattern Generator mode */
122         int                             tpg_mode;
123
124         int                             sof;
125         int                             cal_done;
126 };
127
128 #define TC_VI_REG_RD(dev, offset) readl(dev->reg_base + offset)
129 #define TC_VI_REG_WT(dev, offset, val) writel(val, dev->reg_base + offset)
130
131 int vi2_register(struct tegra_camera_dev *cam);
132 int vi_register(struct tegra_camera_dev *cam);
133
134 #endif