GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / staging / media / atomisp / include / linux / atomisp_platform.h
1 /*
2  * Support for Medifield PNW Camera Imaging ISP subsystem.
3  *
4  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version
8  * 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  *
20  */
21 #ifndef ATOMISP_PLATFORM_H_
22 #define ATOMISP_PLATFORM_H_
23
24 #include <linux/i2c.h>
25 #include <linux/sfi.h>
26 #include <media/v4l2-subdev.h>
27 #include "atomisp.h"
28
29 #define MAX_SENSORS_PER_PORT 4
30 #define MAX_STREAMS_PER_CHANNEL 2
31
32 #define CAMERA_MODULE_ID_LEN 64
33
34 enum atomisp_bayer_order {
35         atomisp_bayer_order_grbg,
36         atomisp_bayer_order_rggb,
37         atomisp_bayer_order_bggr,
38         atomisp_bayer_order_gbrg
39 };
40
41 enum atomisp_input_stream_id {
42         ATOMISP_INPUT_STREAM_GENERAL = 0,
43         ATOMISP_INPUT_STREAM_CAPTURE = 0,
44         ATOMISP_INPUT_STREAM_POSTVIEW,
45         ATOMISP_INPUT_STREAM_PREVIEW,
46         ATOMISP_INPUT_STREAM_VIDEO,
47         ATOMISP_INPUT_STREAM_NUM
48 };
49
50 enum atomisp_input_format {
51         ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY,/* 8 bits per subpixel (legacy) */
52         ATOMISP_INPUT_FORMAT_YUV420_8, /* 8 bits per subpixel */
53         ATOMISP_INPUT_FORMAT_YUV420_10,/* 10 bits per subpixel */
54         ATOMISP_INPUT_FORMAT_YUV420_16,/* 16 bits per subpixel */
55         ATOMISP_INPUT_FORMAT_YUV422_8, /* UYVY..UVYV, 8 bits per subpixel */
56         ATOMISP_INPUT_FORMAT_YUV422_10,/* UYVY..UVYV, 10 bits per subpixel */
57         ATOMISP_INPUT_FORMAT_YUV422_16,/* UYVY..UVYV, 16 bits per subpixel */
58         ATOMISP_INPUT_FORMAT_RGB_444,  /* BGR..BGR, 4 bits per subpixel */
59         ATOMISP_INPUT_FORMAT_RGB_555,  /* BGR..BGR, 5 bits per subpixel */
60         ATOMISP_INPUT_FORMAT_RGB_565,  /* BGR..BGR, 5 bits B and R, 6 bits G */
61         ATOMISP_INPUT_FORMAT_RGB_666,  /* BGR..BGR, 6 bits per subpixel */
62         ATOMISP_INPUT_FORMAT_RGB_888,  /* BGR..BGR, 8 bits per subpixel */
63         ATOMISP_INPUT_FORMAT_RAW_6,    /* RAW data, 6 bits per pixel */
64         ATOMISP_INPUT_FORMAT_RAW_7,    /* RAW data, 7 bits per pixel */
65         ATOMISP_INPUT_FORMAT_RAW_8,    /* RAW data, 8 bits per pixel */
66         ATOMISP_INPUT_FORMAT_RAW_10,   /* RAW data, 10 bits per pixel */
67         ATOMISP_INPUT_FORMAT_RAW_12,   /* RAW data, 12 bits per pixel */
68         ATOMISP_INPUT_FORMAT_RAW_14,   /* RAW data, 14 bits per pixel */
69         ATOMISP_INPUT_FORMAT_RAW_16,   /* RAW data, 16 bits per pixel */
70         ATOMISP_INPUT_FORMAT_BINARY_8, /* Binary byte stream. */
71
72         /* CSI2-MIPI specific format: Generic short packet data. It is used to
73          * keep the timing information for the opening/closing of shutters,
74          * triggering of flashes and etc.
75          */
76         ATOMISP_INPUT_FORMAT_GENERIC_SHORT1,  /* Generic Short Packet Code 1 */
77         ATOMISP_INPUT_FORMAT_GENERIC_SHORT2,  /* Generic Short Packet Code 2 */
78         ATOMISP_INPUT_FORMAT_GENERIC_SHORT3,  /* Generic Short Packet Code 3 */
79         ATOMISP_INPUT_FORMAT_GENERIC_SHORT4,  /* Generic Short Packet Code 4 */
80         ATOMISP_INPUT_FORMAT_GENERIC_SHORT5,  /* Generic Short Packet Code 5 */
81         ATOMISP_INPUT_FORMAT_GENERIC_SHORT6,  /* Generic Short Packet Code 6 */
82         ATOMISP_INPUT_FORMAT_GENERIC_SHORT7,  /* Generic Short Packet Code 7 */
83         ATOMISP_INPUT_FORMAT_GENERIC_SHORT8,  /* Generic Short Packet Code 8 */
84
85         /* CSI2-MIPI specific format: YUV data.
86          */
87         ATOMISP_INPUT_FORMAT_YUV420_8_SHIFT,  /* YUV420 8-bit (Chroma Shifted
88                                                  Pixel Sampling) */
89         ATOMISP_INPUT_FORMAT_YUV420_10_SHIFT, /* YUV420 8-bit (Chroma Shifted
90                                                  Pixel Sampling) */
91
92         /* CSI2-MIPI specific format: Generic long packet data
93          */
94         ATOMISP_INPUT_FORMAT_EMBEDDED, /* Embedded 8-bit non Image Data */
95
96         /* CSI2-MIPI specific format: User defined byte-based data. For example,
97          * the data transmitter (e.g. the SoC sensor) can keep the JPEG data as
98          * the User Defined Data Type 4 and the MPEG data as the
99          * User Defined Data Type 7.
100          */
101         ATOMISP_INPUT_FORMAT_USER_DEF1,  /* User defined 8-bit data type 1 */
102         ATOMISP_INPUT_FORMAT_USER_DEF2,  /* User defined 8-bit data type 2 */
103         ATOMISP_INPUT_FORMAT_USER_DEF3,  /* User defined 8-bit data type 3 */
104         ATOMISP_INPUT_FORMAT_USER_DEF4,  /* User defined 8-bit data type 4 */
105         ATOMISP_INPUT_FORMAT_USER_DEF5,  /* User defined 8-bit data type 5 */
106         ATOMISP_INPUT_FORMAT_USER_DEF6,  /* User defined 8-bit data type 6 */
107         ATOMISP_INPUT_FORMAT_USER_DEF7,  /* User defined 8-bit data type 7 */
108         ATOMISP_INPUT_FORMAT_USER_DEF8,  /* User defined 8-bit data type 8 */
109 };
110
111 enum intel_v4l2_subdev_type {
112         RAW_CAMERA = 1,
113         SOC_CAMERA = 2,
114         CAMERA_MOTOR = 3,
115         LED_FLASH = 4,
116         XENON_FLASH = 5,
117         FILE_INPUT = 6,
118         TEST_PATTERN = 7,
119 };
120
121 struct intel_v4l2_subdev_id {
122         char name[17];
123         enum intel_v4l2_subdev_type type;
124         enum atomisp_camera_port    port;
125 };
126
127 struct intel_v4l2_subdev_i2c_board_info {
128         struct i2c_board_info board_info;
129         int i2c_adapter_id;
130 };
131
132 struct intel_v4l2_subdev_table {
133         struct intel_v4l2_subdev_i2c_board_info v4l2_subdev;
134         enum intel_v4l2_subdev_type type;
135         enum atomisp_camera_port port;
136         struct v4l2_subdev *subdev;
137 };
138
139 struct atomisp_platform_data {
140         struct intel_v4l2_subdev_table *subdevs;
141 };
142
143 /* Describe the capacities of one single sensor. */
144 struct atomisp_sensor_caps {
145         /* The number of streams this sensor can output. */
146         int stream_num;
147         bool is_slave;
148 };
149
150 /* Describe the capacities of sensors connected to one camera port. */
151 struct atomisp_camera_caps {
152         /* The number of sensors connected to this camera port. */
153         int sensor_num;
154         /* The capacities of each sensor. */
155         struct atomisp_sensor_caps sensor[MAX_SENSORS_PER_PORT];
156         /* Define whether stream control is required for multiple streams. */
157         bool multi_stream_ctrl;
158 };
159
160 /*
161  *  Sensor of external ISP can send multiple steams with different mipi data
162  * type in the same virtual channel. This information needs to come from the
163  * sensor or external ISP
164  */
165 struct atomisp_isys_config_info {
166         u8 input_format;
167         u16 width;
168         u16 height;
169 };
170
171 struct atomisp_input_stream_info {
172         enum atomisp_input_stream_id stream;
173         u8 enable;
174         /* Sensor driver fills ch_id with the id
175            of the virtual channel. */
176         u8 ch_id;
177         /* Tells how many streams in this virtual channel. If 0 ignore rest
178          * and the input format will be from mipi_info */
179         u8 isys_configs;
180         /*
181          * if more isys_configs is more than 0, sensor needs to configure the
182          * input format differently. width and height can be 0. If width and
183          * height is not zero, then the corresponsing data needs to be set
184          */
185         struct atomisp_isys_config_info isys_info[MAX_STREAMS_PER_CHANNEL];
186 };
187
188 struct camera_vcm_control;
189 struct camera_vcm_ops {
190         int (*power_up)(struct v4l2_subdev *sd, struct camera_vcm_control *vcm);
191         int (*power_down)(struct v4l2_subdev *sd,
192                         struct camera_vcm_control *vcm);
193         int (*queryctrl)(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc,
194                         struct camera_vcm_control *vcm);
195         int (*g_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl,
196                         struct camera_vcm_control *vcm);
197         int (*s_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl,
198                         struct camera_vcm_control *vcm);
199 };
200
201 struct camera_vcm_control {
202         char camera_module[CAMERA_MODULE_ID_LEN];
203         struct camera_vcm_ops *ops;
204         struct list_head list;
205 };
206
207 struct camera_sensor_platform_data {
208         int (*gpio_ctrl)(struct v4l2_subdev *subdev, int flag);
209         int (*flisclk_ctrl)(struct v4l2_subdev *subdev, int flag);
210         int (*power_ctrl)(struct v4l2_subdev *subdev, int flag);
211         int (*csi_cfg)(struct v4l2_subdev *subdev, int flag);
212         bool (*low_fps)(void);
213         int (*platform_init)(struct i2c_client *);
214         int (*platform_deinit)(void);
215         char *(*msr_file_name)(void);
216         struct atomisp_camera_caps *(*get_camera_caps)(void);
217         int (*gpio_intr_ctrl)(struct v4l2_subdev *subdev);
218
219         /* New G-Min power and GPIO interface, replaces
220          * power/gpio_ctrl with methods to control individual
221          * lines as implemented on all known camera modules. */
222         int (*gpio0_ctrl)(struct v4l2_subdev *subdev, int on);
223         int (*gpio1_ctrl)(struct v4l2_subdev *subdev, int on);
224         int (*v1p8_ctrl)(struct v4l2_subdev *subdev, int on);
225         int (*v2p8_ctrl)(struct v4l2_subdev *subdev, int on);
226         int (*v1p2_ctrl)(struct v4l2_subdev *subdev, int on);
227         struct camera_vcm_control * (*get_vcm_ctrl)(struct v4l2_subdev *subdev,
228                                                     char *module_id);
229 };
230
231 struct camera_af_platform_data {
232         int (*power_ctrl)(struct v4l2_subdev *subdev, int flag);
233 };
234
235 const struct camera_af_platform_data *camera_get_af_platform_data(void);
236
237 struct camera_mipi_info {
238         enum atomisp_camera_port        port;
239         unsigned int                    num_lanes;
240         enum atomisp_input_format       input_format;
241         enum atomisp_bayer_order        raw_bayer_order;
242         struct atomisp_sensor_mode_data data;
243         enum atomisp_input_format       metadata_format;
244         uint32_t                        metadata_width;
245         uint32_t                        metadata_height;
246         const uint32_t                  *metadata_effective_width;
247 };
248
249 extern const struct atomisp_platform_data *atomisp_get_platform_data(void);
250 extern const struct atomisp_camera_caps *atomisp_get_default_camera_caps(void);
251
252 /* API from old platform_camera.h, new CPUID implementation */
253 #define __IS_SOC(x) (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && \
254                      boot_cpu_data.x86 == 6 &&                       \
255                      boot_cpu_data.x86_model == x)
256
257 #define IS_MFLD __IS_SOC(0x27)
258 #define IS_BYT  __IS_SOC(0x37)
259 #define IS_CHT  __IS_SOC(0x4C)
260 #define IS_MOFD __IS_SOC(0x5A)
261
262 #endif /* ATOMISP_PLATFORM_H_ */