2 * Header for M-5MOLS 8M Pixel camera sensor with ISP
4 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
5 * Author: HeungJun Kim, riverful.kim@samsung.com
7 * Copyright (C) 2009 Samsung Electronics Co., Ltd.
8 * Author: Dongsoo Nathaniel Kim, dongsoo45.kim@samsung.com
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.
19 #include <media/v4l2-subdev.h>
20 #include "m5mols_reg.h"
22 extern int m5mols_debug;
23 extern const struct v4l2_mbus_framefmt m5mols_default_ffmt[];
25 enum m5mols_i2c_size {
43 M5MOLS_FPS_MAX = M5MOLS_FPS_30,
47 M5MOLS_RESTYPE_MONITOR,
48 M5MOLS_RESTYPE_CAPTURE,
52 struct m5mols_resolution {
54 enum m5mols_restype type;
67 u16 sdr; /* Subject(object) Distance Range */
68 u16 qval; /* Not written exact meanning
72 struct m5mols_capture {
73 struct m5mols_exif exif;
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 */
95 /* User setting needed for */
96 u32 tone; /* Tone color(contrast) */
98 u32 capture_mode; /* CAPTURE mode for
99 * the Image stabilization */
100 u32 wdr; /* Wide Dynamic Range */
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 &
113 u8 af; /* AF version: seperate register */
115 #define VERSION_SIZE sizeof(struct m5mols_version)
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 */
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;
134 struct v4l2_ctrl_handler handle;
136 struct v4l2_ctrl *autoexposure;
137 struct v4l2_ctrl *exposure;
139 struct v4l2_ctrl *autowb;
140 struct v4l2_ctrl *colorfx;
141 struct v4l2_ctrl *saturation;
142 struct v4l2_ctrl *zoom;
144 struct v4l2_ctrl *autofocus;
145 struct v4l2_ctrl *focusmode;
147 struct v4l2_ctrl *focusrect_left;
148 struct v4l2_ctrl *focusrect_top;
149 struct v4l2_ctrl *focusrect_width;
150 struct v4l2_ctrl *focusrect_height;
152 struct m5mols_version ver;
153 struct m5mols_capture cap;
162 /* Saved register value */
169 /* Optional power callback function dealing with like GPIO. */
170 int (*set_power)(struct device *dev, int on);
173 /* Helper functions */
174 static inline struct m5mols_info *to_m5mols(struct v4l2_subdev *sd)
176 return container_of(sd, struct m5mols_info, sd);
179 static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
181 return &container_of(ctrl->handler, struct m5mols_info, handle)->sd;
184 static inline bool is_powered(struct m5mols_info *info)
189 static inline bool is_ctrl_synced(struct m5mols_info *info)
191 return info->ctrl_sync;
194 static inline bool is_captured(struct m5mols_info *info)
196 return info->capture;
199 static inline bool is_code(enum v4l2_mbus_pixelcode code,
200 enum m5mols_restype type)
202 return code == m5mols_default_ffmt[type].code ? 1 : 0;
205 static inline bool is_manufacturer(struct m5mols_info *info, u8 *manufacturer)
207 return (info->ver.str[0] == manufacturer[0] &&
208 info->ver.str[1] == manufacturer[1]) ?
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);
221 static inline int __must_check
222 i2c_w8_system(struct v4l2_subdev *sd, u8 cmd, u32 val)
224 return m5mols_write_reg(sd, I2C_8BIT, CAT_SYSTEM, cmd, val);
227 static inline int __must_check
228 i2c_w8_param(struct v4l2_subdev *sd, u8 cmd, u32 val)
230 return m5mols_write_reg(sd, I2C_8BIT, CAT_PARAM, cmd, val);
233 static inline int __must_check
234 i2c_w8_mon(struct v4l2_subdev *sd, u8 cmd, u32 val)
236 return m5mols_write_reg(sd, I2C_8BIT, CAT_MONITOR, cmd, val);
239 static inline int __must_check
240 i2c_w8_ae(struct v4l2_subdev *sd, u8 cmd, u32 val)
242 return m5mols_write_reg(sd, I2C_8BIT, CAT_AE, cmd, val);
245 static inline int __must_check
246 i2c_w16_ae(struct v4l2_subdev *sd, u8 cmd, u32 val)
248 return m5mols_write_reg(sd, I2C_16BIT, CAT_AE, cmd, val);
251 static inline int __must_check
252 i2c_w8_wb(struct v4l2_subdev *sd, u8 cmd, u32 val)
254 return m5mols_write_reg(sd, I2C_8BIT, CAT_WB, cmd, val);
257 static inline int __must_check
258 i2c_w8_fd(struct v4l2_subdev *sd, u8 cmd, u32 val)
260 return m5mols_write_reg(sd, I2C_8BIT, CAT_FD, cmd, val);
263 static inline int __must_check
264 i2c_w8_lens(struct v4l2_subdev *sd, u8 cmd, u32 val)
266 return m5mols_write_reg(sd, I2C_8BIT, CAT_LENS, cmd, val);
269 static inline int __must_check
270 i2c_w16_lens(struct v4l2_subdev *sd, u8 cmd, u32 val)
272 return m5mols_write_reg(sd, I2C_16BIT, CAT_LENS, cmd, val);
275 static inline int __must_check
276 i2c_w8_capt_param(struct v4l2_subdev *sd, u8 cmd, u32 val)
278 return m5mols_write_reg(sd, I2C_8BIT, CAT_CAPTURE_PARAMETER, cmd, val);
281 static inline int __must_check
282 i2c_w8_capt_ctrl(struct v4l2_subdev *sd, u8 cmd, u32 val)
284 return m5mols_write_reg(sd, I2C_8BIT, CAT_CAPTURE_CONTROL, cmd, val);
287 static inline int __must_check
288 i2c_w8_flash(struct v4l2_subdev *sd, u8 cmd, u32 val)
290 return m5mols_write_reg(sd, I2C_8BIT, CAT_FLASH, cmd, val);
293 static inline int __must_check
294 i2c_r8_system(struct v4l2_subdev *sd, u8 cmd, u32 *val)
296 return m5mols_read_reg(sd, I2C_8BIT, CAT_SYSTEM, cmd, val);
299 static inline int __must_check
300 i2c_r16_ae(struct v4l2_subdev *sd, u8 cmd, u32 *val)
302 return m5mols_read_reg(sd, I2C_16BIT, CAT_AE, cmd, val);
305 static inline int __must_check
306 i2c_r8_lens(struct v4l2_subdev *sd, u8 cmd, u32 *val)
308 return m5mols_read_reg(sd, I2C_8BIT, CAT_LENS, cmd, val);
311 static inline int __must_check
312 i2c_r32_capt_ctrl(struct v4l2_subdev *sd, u8 cmd, u32 *val)
314 return m5mols_read_reg(sd, I2C_32BIT, CAT_CAPTURE_CONTROL, cmd, val);
317 static inline int __must_check
318 i2c_r16_exif(struct v4l2_subdev *sd, u8 cmd, u32 *val)
320 return m5mols_read_reg(sd, I2C_16BIT, CAT_EXIF, cmd, val);
323 static inline int __must_check
324 i2c_r32_exif(struct v4l2_subdev *sd, u8 cmd, u32 *val)
326 return m5mols_read_reg(sd, I2C_32BIT, CAT_EXIF, cmd, val);
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);
335 /* Called by m5mols_s_ctrl(). */
336 void m5mols_focus_work(struct work_struct *work);
338 int m5mols_set_ctrl(struct v4l2_ctrl *ctrl);
340 /* The firmware function */
341 int m5mols_update_fw(struct v4l2_subdev *sd,
342 int (*set_power)(struct m5mols_info *, bool));
344 #endif /* M5MOLS_H */