upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / media / video / m5mols / m5mols.h
1 /*
2  * Header for M-5MOLS 8M Pixel camera sensor with ISP
3  *
4  * Copyright (C) 2011 Samsung Electronics Co., Ltd.
5  * Author: HeungJun Kim, riverful.kim@samsung.com
6  *
7  * Copyright (C) 2009 Samsung Electronics Co., Ltd.
8  * Author: Dongsoo Nathaniel Kim, dongsoo45.kim@samsung.com
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 #ifndef M5MOLS_H
17 #define M5MOLS_H
18
19 #include <media/v4l2-subdev.h>
20 #include "m5mols_reg.h"
21
22 extern int m5mols_debug;
23 extern const struct v4l2_mbus_framefmt m5mols_default_ffmt[];
24
25 enum m5mols_i2c_size {
26         I2C_8BIT        = 1,
27         I2C_16BIT       = 2,
28         I2C_32BIT       = 4,
29         I2C_MAX         = I2C_32BIT,
30 };
31
32 enum m5mols_fps {
33         M5MOLS_FPS_AUTO = 0,
34         M5MOLS_FPS_10   = 10,
35         M5MOLS_FPS_12   = 12,
36         M5MOLS_FPS_15   = 15,
37         M5MOLS_FPS_20   = 20,
38         M5MOLS_FPS_21   = 21,
39         M5MOLS_FPS_22   = 22,
40         M5MOLS_FPS_23   = 23,
41         M5MOLS_FPS_24   = 24,
42         M5MOLS_FPS_30   = 30,
43         M5MOLS_FPS_MAX  = M5MOLS_FPS_30,
44 };
45
46 enum m5mols_restype {
47         M5MOLS_RESTYPE_MONITOR,
48         M5MOLS_RESTYPE_CAPTURE,
49         M5MOLS_RESTYPE_MAX,
50 };
51
52 struct m5mols_resolution {
53         u8                      reg;
54         enum m5mols_restype     type;
55         u16                     width;
56         u16                     height;
57 };
58
59 struct m5mols_exif {
60         u32                     exposure_time;
61         u32                     shutter_speed;
62         u32                     aperture;
63         u32                     brightness;
64         u32                     exposure_bias;
65         u16                     iso_speed;
66         u16                     flash;
67         u16                     sdr;    /* Subject(object) Distance Range */
68         u16                     qval;   /* Not written exact meanning
69                                          * in datasheet */
70 };
71
72 struct m5mols_capture {
73         struct m5mols_exif      exif;
74         u32                     main;
75         u32                     thumb;
76         u32                     total;
77 };
78
79 struct m5mols_scenemode {       /* Recommended setting in document */
80         u32                     metering;       /* AE light metering */
81         u32                     ev_bias;        /* EV bias */
82         u32                     wb_mode;        /* WhiteBalance(Auto/Manual) */
83         u32                     wb_preset;      /* WhiteBalance Preset */
84         u32                     chroma_en;      /* Chroma Enable */
85         u32                     chroma_lvl;     /* Chroma Level */
86         u32                     edge_en;        /* Edge Enable */
87         u32                     edge_lvl;       /* Edge Level */
88         u32                     af_range;       /* Auto Focus scan range */
89         u32                     fd_mode;        /* Face Detection mode */
90         u32                     mcc;            /* Multi-axis Color Conversion:
91                                                  * (A.K.A Emotion color) */
92         u32                     light;          /* Light control */
93         u32                     flash;          /* Flash control */
94
95                                 /* User setting needed for */
96         u32                     tone;           /* Tone color(contrast) */
97         u32                     iso;            /* ISO */
98         u32                     capture_mode;   /* CAPTURE mode for
99                                                  * the Image stabilization */
100         u32                     wdr;            /* Wide Dynamic Range */
101 };
102
103 #define VERSION_STRING_SIZE     22
104 struct m5mols_version {
105         u8      customer;       /* Customer code:       bytes[0] */
106         u8      project;        /* Project code:        bytes[1] */
107         u16     fw;             /* FirmWare version:    bytes[3][2] */
108         u16     hw;             /* HardWare version:    bytes[5][4] */
109         u16     param;          /* Parameter version:   bytes[7][6] */
110         u16     awb;            /* AWB version:         bytes[9][8] */
111         u8      str[VERSION_STRING_SIZE];               /* manufacturer &
112                                                          * packging vendor */
113         u8      af;             /* AF version:          seperate register */
114 };
115 #define VERSION_SIZE            sizeof(struct m5mols_version)
116
117 /* The LSB 2 bytes of version string means packaging manufacturer */
118 #define SAMSUNG_ELECTRO         "SE"    /* Samsung Electro-Mechanics */
119 #define SAMSUNG_OPTICS          "OP"    /* Samsung Fiber-Optics */
120 #define SAMSUNG_TECHWIN         "TB"    /* Samsung Techwin */
121 #define SAMSUNG_OPTICS_SONY     "OB"    /* Samsung Fiber-Optics + Sony */
122 #define SAMSUNG_OPTICS_LSI      "OC"    /* Samsung Fiber-Optics + LSI */
123
124 struct m5mols_info {
125         const struct m5mols_platform_data       *pdata;
126         struct v4l2_subdev              sd;
127         struct v4l2_mbus_framefmt       ffmt[M5MOLS_RESTYPE_MAX];
128         enum v4l2_mbus_pixelcode        code;
129         struct v4l2_fract               fract;
130         wait_queue_head_t               wait_capture;
131         struct work_struct              work_irq;
132         struct work_struct              work_focus;
133
134         struct v4l2_ctrl_handler        handle;
135         struct {
136                 struct v4l2_ctrl        *autoexposure;
137                 struct v4l2_ctrl        *exposure;
138         };
139         struct v4l2_ctrl                *autowb;
140         struct v4l2_ctrl                *colorfx;
141         struct v4l2_ctrl                *saturation;
142         struct v4l2_ctrl                *zoom;
143         struct {
144                 struct v4l2_ctrl        *autofocus;
145                 struct v4l2_ctrl        *focusmode;
146         };
147         struct v4l2_ctrl                *focusrect_left;
148         struct v4l2_ctrl                *focusrect_top;
149         struct v4l2_ctrl                *focusrect_width;
150         struct v4l2_ctrl                *focusrect_height;
151
152         struct m5mols_version           ver;
153         struct m5mols_capture           cap;
154
155         bool                            power;
156         bool                            ctrl_sync;
157         bool                            capture;
158         bool                            lock_ae;
159         bool                            lock_awb;
160         bool                            focusing;
161
162         /* Saved register value */
163         u8                              resolution;
164         u32                             interrupt;
165         u32                             mode;
166         u32                             mode_save;
167         u8                              fps;
168
169         /* Optional power callback function dealing with like GPIO. */
170         int (*set_power)(struct device *dev, int on);
171 };
172
173 /* Helper functions */
174 static inline struct m5mols_info *to_m5mols(struct v4l2_subdev *sd)
175 {
176         return container_of(sd, struct m5mols_info, sd);
177 }
178
179 static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
180 {
181         return &container_of(ctrl->handler, struct m5mols_info, handle)->sd;
182 }
183
184 static inline bool is_powered(struct m5mols_info *info)
185 {
186         return info->power;
187 }
188
189 static inline bool is_ctrl_synced(struct m5mols_info *info)
190 {
191         return info->ctrl_sync;
192 }
193
194 static inline bool is_captured(struct m5mols_info *info)
195 {
196         return info->capture;
197 }
198
199 static inline bool is_code(enum v4l2_mbus_pixelcode code,
200                            enum m5mols_restype type)
201 {
202         return code == m5mols_default_ffmt[type].code ? 1 : 0;
203 }
204
205 static inline bool is_manufacturer(struct m5mols_info *info, u8 *manufacturer)
206 {
207         return (info->ver.str[0] == manufacturer[0] &&
208                         info->ver.str[1] == manufacturer[1]) ?
209                 true : false;
210 }
211
212 /* I2C functions - referenced by below I2C helper functions */
213 int m5mols_read_reg(struct v4l2_subdev *sd, enum m5mols_i2c_size size,
214                     u8 category, u8 cmd, u32 *val);
215 int m5mols_write_reg(struct v4l2_subdev *sd, enum m5mols_i2c_size size,
216                      u8 category, u8 cmd, u32 val);
217 int m5mols_check_busy(struct v4l2_subdev *sd,
218                       u8 category, u8 cmd, u32 value);
219 int m5mols_enable_interrupt(struct v4l2_subdev *sd, u32 reg);
220
221 static inline int __must_check
222 i2c_w8_system(struct v4l2_subdev *sd, u8 cmd, u32 val)
223 {
224         return m5mols_write_reg(sd, I2C_8BIT, CAT_SYSTEM, cmd, val);
225 }
226
227 static inline int __must_check
228 i2c_w8_param(struct v4l2_subdev *sd, u8 cmd, u32 val)
229 {
230         return m5mols_write_reg(sd, I2C_8BIT, CAT_PARAM, cmd, val);
231 }
232
233 static inline int __must_check
234 i2c_w8_mon(struct v4l2_subdev *sd, u8 cmd, u32 val)
235 {
236         return m5mols_write_reg(sd, I2C_8BIT, CAT_MONITOR, cmd, val);
237 }
238
239 static inline int __must_check
240 i2c_w8_ae(struct v4l2_subdev *sd, u8 cmd, u32 val)
241 {
242         return m5mols_write_reg(sd, I2C_8BIT, CAT_AE, cmd, val);
243 }
244
245 static inline int __must_check
246 i2c_w16_ae(struct v4l2_subdev *sd, u8 cmd, u32 val)
247 {
248         return m5mols_write_reg(sd, I2C_16BIT, CAT_AE, cmd, val);
249 }
250
251 static inline int __must_check
252 i2c_w8_wb(struct v4l2_subdev *sd, u8 cmd, u32 val)
253 {
254         return m5mols_write_reg(sd, I2C_8BIT, CAT_WB, cmd, val);
255 }
256
257 static inline int __must_check
258 i2c_w8_fd(struct v4l2_subdev *sd, u8 cmd, u32 val)
259 {
260         return m5mols_write_reg(sd, I2C_8BIT, CAT_FD, cmd, val);
261 }
262
263 static inline int __must_check
264 i2c_w8_lens(struct v4l2_subdev *sd, u8 cmd, u32 val)
265 {
266         return m5mols_write_reg(sd, I2C_8BIT, CAT_LENS, cmd, val);
267 }
268
269 static inline int __must_check
270 i2c_w16_lens(struct v4l2_subdev *sd, u8 cmd, u32 val)
271 {
272         return m5mols_write_reg(sd, I2C_16BIT, CAT_LENS, cmd, val);
273 }
274
275 static inline int __must_check
276 i2c_w8_capt_param(struct v4l2_subdev *sd, u8 cmd, u32 val)
277 {
278         return m5mols_write_reg(sd, I2C_8BIT, CAT_CAPTURE_PARAMETER, cmd, val);
279 }
280
281 static inline int __must_check
282 i2c_w8_capt_ctrl(struct v4l2_subdev *sd, u8 cmd, u32 val)
283 {
284         return m5mols_write_reg(sd, I2C_8BIT, CAT_CAPTURE_CONTROL, cmd, val);
285 }
286
287 static inline int __must_check
288 i2c_w8_flash(struct v4l2_subdev *sd, u8 cmd, u32 val)
289 {
290         return m5mols_write_reg(sd, I2C_8BIT, CAT_FLASH, cmd, val);
291 }
292
293 static inline int __must_check
294 i2c_r8_system(struct v4l2_subdev *sd, u8 cmd, u32 *val)
295 {
296         return m5mols_read_reg(sd, I2C_8BIT, CAT_SYSTEM, cmd, val);
297 }
298
299 static inline int __must_check
300 i2c_r16_ae(struct v4l2_subdev *sd, u8 cmd, u32 *val)
301 {
302         return m5mols_read_reg(sd, I2C_16BIT, CAT_AE, cmd, val);
303 }
304
305 static inline int __must_check
306 i2c_r8_lens(struct v4l2_subdev *sd, u8 cmd, u32 *val)
307 {
308         return m5mols_read_reg(sd, I2C_8BIT, CAT_LENS, cmd, val);
309 }
310
311 static inline int __must_check
312 i2c_r32_capt_ctrl(struct v4l2_subdev *sd, u8 cmd, u32 *val)
313 {
314         return m5mols_read_reg(sd, I2C_32BIT, CAT_CAPTURE_CONTROL, cmd, val);
315 }
316
317 static inline int __must_check
318 i2c_r16_exif(struct v4l2_subdev *sd, u8 cmd, u32 *val)
319 {
320         return m5mols_read_reg(sd, I2C_16BIT, CAT_EXIF, cmd, val);
321 }
322
323 static inline int __must_check
324 i2c_r32_exif(struct v4l2_subdev *sd, u8 cmd, u32 *val)
325 {
326         return m5mols_read_reg(sd, I2C_32BIT, CAT_EXIF, cmd, val);
327 }
328
329 int m5mols_change_mode(struct m5mols_info *info, u32 mode);
330 int m5mols_change_scenemode(struct m5mols_info *info, u32 mode);
331 int m5mols_start_capture(struct m5mols_info *info);
332 int m5mols_sync_control(struct m5mols_info *info);
333 int m5mols_lock_3a(struct m5mols_info *info, bool lock);
334
335 /* Called by m5mols_s_ctrl(). */
336 void m5mols_focus_work(struct work_struct *work);
337
338 int m5mols_set_ctrl(struct v4l2_ctrl *ctrl);
339
340 /* The firmware function */
341 int m5mols_update_fw(struct v4l2_subdev *sd,
342                      int (*set_power)(struct m5mols_info *, bool));
343
344 #endif  /* M5MOLS_H */