]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - drivers/media/platform/tegra/camera/csi/csi.h
drivers: camera: Fix Mipi Calibration sequence
[hercules2020/nv-tegra/linux-4.4.git] / drivers / media / platform / tegra / camera / csi / csi.h
1 /*
2  * NVIDIA Tegra CSI Device Header
3  *
4  * Copyright (c) 2015-2017, NVIDIA CORPORATION.  All rights reserved.
5  *
6  * Author: Bryan Wu <pengw@nvidia.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #ifndef __CSI_H_
14 #define __CSI_H_
15
16 #include <media/media-entity.h>
17 #include <media/v4l2-async.h>
18 #include <media/v4l2-ctrls.h>
19 #include <media/v4l2-subdev.h>
20 #include <linux/platform_device.h>
21
22 #include <media/camera_common.h>
23 #include <linux/platform_device.h>
24
25 #include "camera/vi/registers.h"
26 #include "camera/csi/csi4_registers.h"
27
28 #define MAX_CSI_BLOCK_LANES 4
29
30 enum tegra_csi_port_num {
31         PORT_A = 0,
32         PORT_B = 1,
33         PORT_C = 2,
34         PORT_D = 3,
35         PORT_E = 4,
36         PORT_F = 5,
37 };
38
39 #define csi_port_is_valid(port) (port > PORT_F ? 0 : 1)
40
41 enum camera_gang_mode {
42         CAMERA_NO_GANG_MODE = 0,
43         CAMERA_GANG_L_R = 1,
44         CAMERA_GANG_T_B,
45         CAMERA_GANG_R_L,
46         CAMERA_GANG_B_T
47 };
48
49 struct tegra_channel;
50
51 struct tpg_frmfmt {
52         struct v4l2_frmsize_discrete frmsize;
53         int pixel_format;
54         int framerate;
55         int h_blank;
56         int v_blank;
57 };
58
59 struct tegra_csi_port {
60         void __iomem *pixel_parser;
61         void __iomem *cil;
62         void __iomem *tpg;
63
64         /* One pair of sink/source pad has one format */
65         struct v4l2_mbus_framefmt format;
66         const struct tegra_video_format *core_format;
67         unsigned int lanes;
68         unsigned int framerate;
69         unsigned int h_blank;
70         unsigned int v_blank;
71
72         enum tegra_csi_port_num num;
73 };
74
75 struct tegra_csi_device {
76         struct device *dev;
77         struct platform_device *pdev;
78         char devname[32];
79         void __iomem *iomem_base;
80         void __iomem *iomem[3];
81         struct clk *plld_dsi;
82         struct clk *plld;
83
84         struct camera_common_data s_data[6];
85         struct tegra_csi_port *ports;
86         struct media_pad *pads;
87
88         unsigned int clk_freq;
89         int num_ports;
90         int num_channels;
91         struct list_head csi_chans;
92         struct tegra_csi_channel *tpg_start;
93         const struct tegra_csi_fops *fops;
94         const struct tpg_frmfmt *tpg_frmfmt_table;
95         unsigned int tpg_frmfmt_table_size;
96         atomic_t power_ref;
97
98         struct dentry *debugdir;
99         struct mutex source_update;
100         int tpg_active;
101         int sensor_active;
102 };
103
104 /*
105  * subdev: channel subdev
106  * numports: Number of CSI ports in use for this channel
107  * numlanes: Number of CIL lanes in use
108  */
109 struct tegra_csi_channel {
110         struct list_head list;
111         struct v4l2_subdev subdev;
112         struct media_pad *pads;
113         struct media_pipeline pipe;
114
115         struct tegra_csi_device *csi;
116         struct tegra_csi_port *ports;
117         unsigned char port[TEGRA_CSI_BLOCKS];
118         struct mutex format_lock;
119         unsigned int numports;
120         unsigned int numlanes;
121         unsigned int pg_mode;
122         struct camera_common_data *s_data;
123         unsigned int id;
124         atomic_t is_streaming;
125
126         struct device_node *of_node;
127 };
128
129 static inline struct tegra_csi_channel *to_csi_chan(struct v4l2_subdev *subdev)
130 {
131         return container_of(subdev, struct tegra_csi_channel, subdev);
132 }
133
134 static inline struct tegra_csi_device *to_csi(struct v4l2_subdev *subdev)
135 {
136         struct tegra_csi_channel *chan = to_csi_chan(subdev);
137
138         return chan->csi;
139 }
140
141 struct tegra_csi_device *tegra_get_mc_csi(void);
142 void set_csi_portinfo(struct tegra_csi_device *csi,
143         unsigned int port, unsigned int numlanes);
144 void tegra_csi_status(struct tegra_csi_channel *chan,
145                         enum tegra_csi_port_num port_num);
146 int tegra_csi_error(struct tegra_csi_channel *chan,
147                         enum tegra_csi_port_num port_num);
148 int tegra_csi_start_streaming(struct tegra_csi_channel *chan,
149                                 enum tegra_csi_port_num port_num);
150 void tegra_csi_stop_streaming(struct tegra_csi_channel *chan,
151                                 enum tegra_csi_port_num port_num);
152 void tegra_csi_error_recover(struct tegra_csi_channel *chan,
153                                 enum tegra_csi_port_num port_num);
154 int tegra_csi_mipi_calibrate(struct tegra_csi_device *csi,
155                                 bool on);
156 int tegra_csi_init(struct tegra_csi_device *csi,
157                 struct platform_device *pdev);
158 int tegra_csi_media_controller_init(struct tegra_csi_device *csi,
159                                 struct platform_device *pdev);
160 int tegra_csi_media_controller_remove(struct tegra_csi_device *csi);
161 int tpg_csi_media_controller_init(struct tegra_csi_device *csi, int pg_mode);
162 void tpg_csi_media_controller_cleanup(struct tegra_csi_device *csi);
163
164 /* helper functions to calculate clock setting times */
165 unsigned int tegra_csi_clk_settling_time(
166         struct tegra_csi_device *csi,
167         const unsigned int csicil_clk_mhz);
168 unsigned int tegra_csi_ths_settling_time(
169         struct tegra_csi_device *csi,
170         const unsigned int csicil_clk_mhz,
171         const unsigned int mipi_clk_mhz);
172 #endif