arm64: configs: synchronize with other 3399 config for 3399 linux
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rockchip / rk_camera.h
1 /*
2     camera.h - PXA camera driver header file
3
4     Copyright (C) 2003, Intel Corporation
5     Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef __ASM_ARCH_CAMERA_RK_H_
23 #define __ASM_ARCH_CAMERA_RK_H_
24
25 #include <linux/videodev2.h>
26 #include <media/soc_camera.h>
27 #include <linux/i2c.h>
28 #include <linux/platform_device.h>
29 #include "rk_camera_sensor_info.h"
30
31 #define RK29_CAM_PLATFORM_DEV_ID 33
32 #define RK_CAM_PLATFORM_DEV_ID_0 RK29_CAM_PLATFORM_DEV_ID
33 #define RK_CAM_PLATFORM_DEV_ID_1 (RK_CAM_PLATFORM_DEV_ID_0+1)
34 #define INVALID_VALUE -1
35 #ifndef INVALID_GPIO
36 #define INVALID_GPIO INVALID_VALUE
37 #endif
38 #define RK29_CAM_IO_SUCCESS 0
39 #define RK29_CAM_EIO_INVALID -3
40 #define RK29_CAM_EIO_REQUESTFAIL -2
41
42 #define RK29_CAM_POWERACTIVE_BITPOS     0x00
43 #define RK29_CAM_RESETACTIVE_BITPOS     0x01
44 #define RK29_CAM_POWERDNACTIVE_BITPOS 0x02
45 #define RK29_CAM_FLASHACTIVE_BITPOS     0x03
46 #define RK29_CAM_AFACTIVE_BITPOS        0x04
47
48 #define RK_CAM_SUPPORT_RESOLUTION 0x800000
49
50 #define _CONS(a,b) a##b
51 #define CONS(a,b) _CONS(a,b)
52
53 #define _CONS4(a,b,c,d) a##b##c##d
54 #define CONS4(a,b,c,d) _CONS4(a,b,c,d)
55
56 #define __STR(x) #x
57 #define _STR(x) __STR(x)
58 #define STR(x) _STR(x)
59
60  
61 /*---------------- Camera Sensor Must Define Macro Begin  ------------------------*/
62 /*
63  move to rk_camera_sensor_info.h   yzm                                    
64 */
65 /*---------------- Camera Sensor Must Define Macro End  ------------------------*/
66
67
68 //#define RK29_CAM_POWERACTIVE_BITPOS   0x00
69 #define RK29_CAM_POWERACTIVE_MASK       (1<<RK29_CAM_POWERACTIVE_BITPOS)
70 #define RK29_CAM_POWERACTIVE_H  (0x01<<RK29_CAM_POWERACTIVE_BITPOS)
71 #define RK29_CAM_POWERACTIVE_L  (0x00<<RK29_CAM_POWERACTIVE_BITPOS)
72
73 //#define RK29_CAM_RESETACTIVE_BITPOS   0x01
74 #define RK29_CAM_RESETACTIVE_MASK       (1<<RK29_CAM_RESETACTIVE_BITPOS)
75 #define RK29_CAM_RESETACTIVE_H  (0x01<<RK29_CAM_RESETACTIVE_BITPOS)
76 #define RK29_CAM_RESETACTIVE_L  (0x00<<RK29_CAM_RESETACTIVE_BITPOS)
77
78 //#define RK29_CAM_POWERDNACTIVE_BITPOS 0x02
79 #define RK29_CAM_POWERDNACTIVE_MASK     (1<<RK29_CAM_POWERDNACTIVE_BITPOS)
80 #define RK29_CAM_POWERDNACTIVE_H        (0x01<<RK29_CAM_POWERDNACTIVE_BITPOS)
81 #define RK29_CAM_POWERDNACTIVE_L        (0x00<<RK29_CAM_POWERDNACTIVE_BITPOS)
82
83 //#define RK29_CAM_FLASHACTIVE_BITPOS   0x03
84 #define RK29_CAM_FLASHACTIVE_MASK       (1<<RK29_CAM_FLASHACTIVE_BITPOS)
85 #define RK29_CAM_FLASHACTIVE_H  (0x01<<RK29_CAM_FLASHACTIVE_BITPOS)
86 #define RK29_CAM_FLASHACTIVE_L  (0x00<<RK29_CAM_FLASHACTIVE_BITPOS)
87
88
89 //#define RK29_CAM_AFACTIVE_BITPOS      0x04
90 #define RK29_CAM_AFACTIVE_MASK  (1<<RK29_CAM_AFACTIVE_BITPOS)
91 #define RK29_CAM_AFACTIVE_H     (0x01<<RK29_CAM_AFACTIVE_BITPOS)
92 #define RK29_CAM_AFACTIVE_L  (0x00<<RK29_CAM_AFACTIVE_BITPOS)
93
94
95
96 #define RK_CAM_SCALE_CROP_ARM      0
97 #define RK_CAM_SCALE_CROP_IPP      1
98 #define RK_CAM_SCALE_CROP_RGA      2
99 #define RK_CAM_SCALE_CROP_PP       3
100
101 #define RK_CAM_INPUT_FMT_YUV422    (1<<0)
102 #define RK_CAM_INPUT_FMT_RAW10     (1<<1)
103 #define RK_CAM_INPUT_FMT_RAW12     (1<<2)
104
105 /* v4l2_subdev_core_ops.ioctl  ioctl_cmd macro */
106 #define RK29_CAM_SUBDEV_ACTIVATE            0x00
107 #define RK29_CAM_SUBDEV_DEACTIVATE          0x01
108 #define RK29_CAM_SUBDEV_IOREQUEST                       0x02
109 #define RK29_CAM_SUBDEV_CB_REGISTER         0x03
110
111 #define Sensor_HasBeen_PwrOff(a)            (a&0x01)
112 #define Sensor_Support_DirectResume(a)      ((a&0x10)==0x10)
113
114 #define Sensor_CropSet(a,b)                  a->reserved[1] = b;
115 #define Sensor_CropGet(a)                    a->reserved[1]
116
117 #define RK29_CAM_SUBDEV_HDR_EXPOSURE        0x04
118
119 #define RK_VIDEOBUF_HDR_EXPOSURE_MINUS_1        0x00
120 #define RK_VIDEOBUF_HDR_EXPOSURE_NORMAL         0x01
121 #define RK_VIDEOBUF_HDR_EXPOSURE_PLUS_1         0x02
122 #define RK_VIDEOBUF_HDR_EXPOSURE_FINISH         0x03
123 #define RK_VIDEOBUF_CODE_SET(rk_code,type)  rk_code = (('R'<<24)|('K'<<16)|type)
124 #define RK_VIDEOBUF_CODE_CHK(rk_code)       ((rk_code&(('R'<<24)|('K'<<16)))==(('R'<<24)|('K'<<16)))
125
126 enum rk29camera_ioctrl_cmd
127 {
128         Cam_Power,
129         Cam_Reset,
130         Cam_PowerDown,
131         Cam_Flash,
132         Cam_Mclk,
133         Cam_Af
134 };
135
136 enum rk29sensor_power_cmd
137 {
138     Sensor_Power,
139         Sensor_Reset,
140         Sensor_PowerDown,
141         Sensor_Flash,
142         Sensor_Af
143 };
144
145 enum rk29camera_flash_cmd
146 {
147     Flash_Off,
148     Flash_On,
149     Flash_Torch
150 };
151
152 struct rk29camera_gpio_res {
153     unsigned int gpio_reset;
154     unsigned int gpio_power;
155         unsigned int gpio_powerdown;
156         unsigned int gpio_flash;
157         unsigned int gpio_af;
158         unsigned int gpio_flag;
159         unsigned int gpio_init;
160         const char *dev_name;
161 };
162
163 struct rk29camera_mem_res {
164         const char *name;
165         unsigned int start;
166         unsigned int size;
167     void __iomem *vbase;  //Ö¸ÏòIO¿Õ¼äµÄÖ¸Õ룬ΪÁËÇý¶¯³ÌÐòµÄͨÓÃÐÔ¿¼ÂÇ
168 };
169 struct rk29camera_info {
170     const char *dev_name;
171     unsigned int orientation;
172     struct v4l2_frmivalenum fival[10];
173 };
174
175 struct reginfo_t
176 {
177         u16 reg;
178         u16 val;
179         u16 reg_len;
180         u16 rev;
181 };
182 typedef struct rk_sensor_user_init_data{
183         int rk_sensor_init_width;
184         int rk_sensor_init_height;
185         unsigned long rk_sensor_init_bus_param;
186         enum v4l2_mbus_pixelcode rk_sensor_init_pixelcode;
187         struct reginfo_t * rk_sensor_init_data;
188         int rk_sensor_winseq_size;
189         struct reginfo_t * rk_sensor_init_winseq;
190         int rk_sensor_init_data_size;
191 }rk_sensor_user_init_data_s;
192
193 typedef struct rk_camera_device_register_info {
194     struct i2c_board_info i2c_cam_info;
195         struct soc_camera_desc desc_info;/*yzm*/
196     struct platform_device device_info;
197 }rk_camera_device_register_info_t;
198
199 struct rkcamera_platform_data {
200     rk_camera_device_register_info_t dev;
201     char dev_name[32];
202     struct rk29camera_gpio_res io;
203     int orientation;
204     int resolution;   
205     int mirror;       /* bit0:  0: mirror off
206                                 1: mirror on
207                          bit1:  0: flip off
208                                 1: flip on
209                       */
210     int i2c_rate;     /* 100KHz = 100000  */                    
211     bool flash;       /* true:  the sensor attached flash;
212                          false: the sensor haven't attach flash;
213
214                       */
215     int pwdn_info;    /* bit4: 1: sensor isn't need to be init after exit stanby, it can streaming directly 
216                                0: sensor must be init after exit standby;
217
218                          bit0: 1: sensor power have been turn off;
219                                0: sensor power is always on;
220                       */
221
222     long powerup_sequence;       /*  
223                                     bit0-bit3 --- power up sequence first step;
224                                     bit4-bit7 --- power up sequence second step;
225                                      .....
226                                   */
227     int mclk_rate;       /* MHz : 24/48 */ 
228     int fov_h;           /* fied of view horizontal */
229     int fov_v;           /* fied of view vertical */
230         const char *power_pmu_name1;
231         const char *power_pmu_name2;
232         const char *powerdown_pmu_name;
233         int power_pmu_voltage1;
234         int power_pmu_voltage2;
235         int powerdown_pmu_voltage;
236         struct device_node *of_node;
237         struct rkcamera_platform_data *next_camera;/*yzm*/
238                       
239 };
240
241 struct rk29camera_platform_data {
242     int (*io_init)(void);
243     int (*io_deinit)(int sensor);
244         int (*sensor_ioctrl)(struct device *dev,enum rk29camera_ioctrl_cmd cmd,int on);
245
246     int (*sensor_register)(void);
247     int (*sensor_mclk)(int cif_idx, int on, int clk_rate);
248     
249     struct rkcamera_platform_data *register_dev_new;  //sensor   
250         struct device *cif_dev;/*yzm host*/  
251         const char *rockchip_name;
252         int iommu_enabled;
253 };
254
255 struct rk29camera_platform_ioctl_cb {
256     int (*sensor_power_cb)(struct rk29camera_gpio_res *res, int on);
257     int (*sensor_reset_cb)(struct rk29camera_gpio_res *res, int on);
258     int (*sensor_powerdown_cb)(struct rk29camera_gpio_res *res, int on);
259     int (*sensor_flash_cb)(struct rk29camera_gpio_res *res, int on);
260     int (*sensor_af_cb)(struct rk29camera_gpio_res *res, int on);       
261 };
262
263 typedef struct rk29_camera_sensor_cb {
264     int (*sensor_cb)(void *arg); 
265     int (*scale_crop_cb)(struct work_struct *work);
266 }rk29_camera_sensor_cb_s;
267
268 #endif /* __ASM_ARCH_CAMERA_H_ */
269