blob: 4ab8b370e6650c9cf193ee3ee2220b13d65e028b [file] [log] [blame]
HeungJun, Kimbc125102011-05-20 02:27:28 -03001/*
2 * Header for M-5MOLS 8M Pixel camera sensor with ISP
3 *
4 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
HeungJun, Kimc3070112011-06-07 02:00:58 -03005 * Author: HeungJun Kim <riverful.kim@samsung.com>
HeungJun, Kimbc125102011-05-20 02:27:28 -03006 *
7 * Copyright (C) 2009 Samsung Electronics Co., Ltd.
HeungJun, Kimc3070112011-06-07 02:00:58 -03008 * Author: Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com>
HeungJun, Kimbc125102011-05-20 02:27:28 -03009 *
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
Sylwester Nawrockiab7ef222012-09-18 06:18:43 -030022
23/* An amount of data transmitted in addition to the value
24 * determined by CAPP_JPEG_SIZE_MAX register.
25 */
26#define M5MOLS_JPEG_TAGS_SIZE 0x20000
27#define M5MOLS_MAIN_JPEG_SIZE_MAX (5 * SZ_1M)
28
HeungJun, Kimbc125102011-05-20 02:27:28 -030029extern int m5mols_debug;
30
HeungJun, Kimbc125102011-05-20 02:27:28 -030031enum m5mols_restype {
32 M5MOLS_RESTYPE_MONITOR,
33 M5MOLS_RESTYPE_CAPTURE,
34 M5MOLS_RESTYPE_MAX,
35};
36
37/**
38 * struct m5mols_resolution - structure for the resolution
39 * @type: resolution type according to the pixel code
40 * @width: width of the resolution
41 * @height: height of the resolution
42 * @reg: resolution preset register value
43 */
44struct m5mols_resolution {
45 u8 reg;
46 enum m5mols_restype type;
47 u16 width;
48 u16 height;
49};
50
51/**
52 * struct m5mols_exif - structure for the EXIF information of M-5MOLS
53 * @exposure_time: exposure time register value
54 * @shutter_speed: speed of the shutter register value
55 * @aperture: aperture register value
56 * @exposure_bias: it calls also EV bias
57 * @iso_speed: ISO register value
58 * @flash: status register value of the flash
59 * @sdr: status register value of the Subject Distance Range
60 * @qval: not written exact meaning in document
61 */
62struct m5mols_exif {
63 u32 exposure_time;
64 u32 shutter_speed;
65 u32 aperture;
66 u32 brightness;
67 u32 exposure_bias;
68 u16 iso_speed;
69 u16 flash;
70 u16 sdr;
71 u16 qval;
72};
73
74/**
75 * struct m5mols_capture - Structure for the capture capability
76 * @exif: EXIF information
Sylwester Nawrockiab7ef222012-09-18 06:18:43 -030077 * @buf_size: internal JPEG frame buffer size, in bytes
HeungJun, Kimbc125102011-05-20 02:27:28 -030078 * @main: size in bytes of the main image
79 * @thumb: size in bytes of the thumb image, if it was accompanied
80 * @total: total size in bytes of the produced image
81 */
82struct m5mols_capture {
83 struct m5mols_exif exif;
Sylwester Nawrockiab7ef222012-09-18 06:18:43 -030084 unsigned int buf_size;
HeungJun, Kimbc125102011-05-20 02:27:28 -030085 u32 main;
86 u32 thumb;
87 u32 total;
88};
89
90/**
91 * struct m5mols_scenemode - structure for the scenemode capability
92 * @metering: metering light register value
93 * @ev_bias: EV bias register value
94 * @wb_mode: mode which means the WhiteBalance is Auto or Manual
95 * @wb_preset: whitebalance preset register value in the Manual mode
96 * @chroma_en: register value whether the Chroma capability is enabled or not
97 * @chroma_lvl: chroma's level register value
98 * @edge_en: register value Whether the Edge capability is enabled or not
99 * @edge_lvl: edge's level register value
100 * @af_range: Auto Focus's range
101 * @fd_mode: Face Detection mode
102 * @mcc: Multi-axis Color Conversion which means emotion color
103 * @light: status of the Light
104 * @flash: status of the Flash
105 * @tone: Tone color which means Contrast
106 * @iso: ISO register value
107 * @capt_mode: Mode of the Image Stabilization while the camera capturing
108 * @wdr: Wide Dynamic Range register value
109 *
110 * The each value according to each scenemode is recommended in the documents.
111 */
112struct m5mols_scenemode {
HeungJun, Kim57644f52011-05-31 03:44:19 -0300113 u8 metering;
114 u8 ev_bias;
115 u8 wb_mode;
116 u8 wb_preset;
117 u8 chroma_en;
118 u8 chroma_lvl;
119 u8 edge_en;
120 u8 edge_lvl;
121 u8 af_range;
122 u8 fd_mode;
123 u8 mcc;
124 u8 light;
125 u8 flash;
126 u8 tone;
127 u8 iso;
128 u8 capt_mode;
129 u8 wdr;
HeungJun, Kimbc125102011-05-20 02:27:28 -0300130};
131
132/**
133 * struct m5mols_version - firmware version information
134 * @customer: customer information
135 * @project: version of project information according to customer
136 * @fw: firmware revision
137 * @hw: hardware revision
138 * @param: version of the parameter
139 * @awb: Auto WhiteBalance algorithm version
140 * @str: information about manufacturer and packaging vendor
141 * @af: Auto Focus version
142 *
143 * The register offset starts the customer version at 0x0, and it ends
144 * the awb version at 0x09. The customer, project information occupies 1 bytes
145 * each. And also the fw, hw, param, awb each requires 2 bytes. The str is
146 * unique string associated with firmware's version. It includes information
147 * about manufacturer and the vendor of the sensor's packaging. The least
148 * significant 2 bytes of the string indicate packaging manufacturer.
149 */
150#define VERSION_STRING_SIZE 22
151struct m5mols_version {
152 u8 customer;
153 u8 project;
154 u16 fw;
155 u16 hw;
156 u16 param;
157 u16 awb;
158 u8 str[VERSION_STRING_SIZE];
159 u8 af;
160};
HeungJun, Kimbc125102011-05-20 02:27:28 -0300161
162/**
163 * struct m5mols_info - M-5MOLS driver data structure
164 * @pdata: platform data
165 * @sd: v4l-subdev instance
166 * @pad: media pad
HeungJun, Kimbc125102011-05-20 02:27:28 -0300167 * @irq_waitq: waitqueue for the capture
Sylwester Nawrocki93464592012-05-09 11:53:09 -0300168 * @irq_done: set to 1 in the interrupt handler
HeungJun, Kimbc125102011-05-20 02:27:28 -0300169 * @handle: control handler
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300170 * @auto_exposure: auto/manual exposure control
Sylwester Nawrocki48311db2012-03-06 07:10:00 -0300171 * @exposure_bias: exposure compensation control
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300172 * @exposure: manual exposure control
Sylwester Nawrocki50d3f932012-04-09 14:51:49 -0300173 * @metering: exposure metering control
Sylwester Nawrocki44b153c2012-04-09 13:19:25 -0300174 * @auto_iso: auto/manual ISO sensitivity control
175 * @iso: manual ISO sensitivity control
Sylwester Nawrockid7a87e42012-05-08 06:56:35 -0300176 * @auto_wb: auto white balance control
Sylwester Nawrocki93464592012-05-09 11:53:09 -0300177 * @lock_3a: 3A lock control
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300178 * @colorfx: color effect control
179 * @saturation: saturation control
180 * @zoom: zoom control
Sylwester Nawrocki4eb34192012-03-06 07:10:13 -0300181 * @wdr: wide dynamic range control
Sylwester Nawrockiefcb07c2012-03-06 07:10:27 -0300182 * @stabilization: image stabilization control
Sylwester Nawrockidd9c4712012-02-28 06:29:01 -0300183 * @jpeg_quality: JPEG compression quality control
Sylwester Nawrocki5565a2a2012-09-20 08:16:45 -0300184 * @set_power: optional power callback to the board code
185 * @lock: mutex protecting the structure fields below
186 * @ffmt: current fmt according to resolution type
187 * @res_type: current resolution type
HeungJun, Kimbc125102011-05-20 02:27:28 -0300188 * @ver: information of the version
189 * @cap: the capture mode attributes
HeungJun Kim0f2ee1d2011-12-03 11:47:40 -0300190 * @isp_ready: 1 when the ISP controller has completed booting
Sylwester Nawrocki93464592012-05-09 11:53:09 -0300191 * @power: current sensor's power status
HeungJun Kim0f2ee1d2011-12-03 11:47:40 -0300192 * @ctrl_sync: 1 when the control handler state is restored in H/W
HeungJun, Kimbc125102011-05-20 02:27:28 -0300193 * @resolution: register value for current resolution
HeungJun, Kimbc125102011-05-20 02:27:28 -0300194 * @mode: register value for current operation mode
HeungJun, Kimbc125102011-05-20 02:27:28 -0300195 */
196struct m5mols_info {
197 const struct m5mols_platform_data *pdata;
198 struct v4l2_subdev sd;
199 struct media_pad pad;
Sylwester Nawrocki5d4294b2011-12-12 15:45:56 -0300200
HeungJun, Kimbc125102011-05-20 02:27:28 -0300201 wait_queue_head_t irq_waitq;
HeungJun Kimce808a42011-12-02 21:53:20 -0300202 atomic_t irq_done;
HeungJun, Kimbc125102011-05-20 02:27:28 -0300203
204 struct v4l2_ctrl_handler handle;
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300205 struct {
Sylwester Nawrocki48311db2012-03-06 07:10:00 -0300206 /* exposure/exposure bias/auto exposure cluster */
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300207 struct v4l2_ctrl *auto_exposure;
Sylwester Nawrocki48311db2012-03-06 07:10:00 -0300208 struct v4l2_ctrl *exposure_bias;
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300209 struct v4l2_ctrl *exposure;
Sylwester Nawrocki50d3f932012-04-09 14:51:49 -0300210 struct v4l2_ctrl *metering;
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300211 };
Sylwester Nawrocki44b153c2012-04-09 13:19:25 -0300212 struct {
213 /* iso/auto iso cluster */
214 struct v4l2_ctrl *auto_iso;
215 struct v4l2_ctrl *iso;
216 };
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300217 struct v4l2_ctrl *auto_wb;
Sylwester Nawrockid7a87e42012-05-08 06:56:35 -0300218
Sylwester Nawrocki93464592012-05-09 11:53:09 -0300219 struct v4l2_ctrl *lock_3a;
HeungJun, Kimbc125102011-05-20 02:27:28 -0300220 struct v4l2_ctrl *colorfx;
221 struct v4l2_ctrl *saturation;
222 struct v4l2_ctrl *zoom;
Sylwester Nawrocki4eb34192012-03-06 07:10:13 -0300223 struct v4l2_ctrl *wdr;
Sylwester Nawrockiefcb07c2012-03-06 07:10:27 -0300224 struct v4l2_ctrl *stabilization;
Sylwester Nawrockidd9c4712012-02-28 06:29:01 -0300225 struct v4l2_ctrl *jpeg_quality;
HeungJun, Kimbc125102011-05-20 02:27:28 -0300226
Sylwester Nawrocki5565a2a2012-09-20 08:16:45 -0300227 int (*set_power)(struct device *dev, int on);
228
229 struct mutex lock;
230
231 struct v4l2_mbus_framefmt ffmt[M5MOLS_RESTYPE_MAX];
232 int res_type;
233
HeungJun, Kimbc125102011-05-20 02:27:28 -0300234 struct m5mols_version ver;
235 struct m5mols_capture cap;
HeungJun Kim0f2ee1d2011-12-03 11:47:40 -0300236
237 unsigned int isp_ready:1;
238 unsigned int power:1;
239 unsigned int ctrl_sync:1;
240
HeungJun, Kimbc125102011-05-20 02:27:28 -0300241 u8 resolution;
HeungJun, Kim57644f52011-05-31 03:44:19 -0300242 u8 mode;
HeungJun, Kimbc125102011-05-20 02:27:28 -0300243};
244
HeungJun, Kimbc125102011-05-20 02:27:28 -0300245#define is_available_af(__info) (__info->ver.af)
246#define is_code(__code, __type) (__code == m5mols_default_ffmt[__type].code)
247#define is_manufacturer(__info, __manufacturer) \
248 (__info->ver.str[0] == __manufacturer[0] && \
249 __info->ver.str[1] == __manufacturer[1])
250/*
251 * I2C operation of the M-5MOLS
252 *
253 * The I2C read operation of the M-5MOLS requires 2 messages. The first
254 * message sends the information about the command, command category, and total
255 * message size. The second message is used to retrieve the data specifed in
256 * the first message
257 *
258 * 1st message 2nd message
259 * +-------+---+----------+-----+-------+ +------+------+------+------+
260 * | size1 | R | category | cmd | size2 | | d[0] | d[1] | d[2] | d[3] |
261 * +-------+---+----------+-----+-------+ +------+------+------+------+
262 * - size1: message data size(5 in this case)
263 * - size2: desired buffer size of the 2nd message
264 * - d[0..3]: according to size2
265 *
266 * The I2C write operation needs just one message. The message includes
267 * category, command, total size, and desired data.
268 *
269 * 1st message
270 * +-------+---+----------+-----+------+------+------+------+
271 * | size1 | W | category | cmd | d[0] | d[1] | d[2] | d[3] |
272 * +-------+---+----------+-----+------+------+------+------+
273 * - d[0..3]: according to size1
274 */
HeungJun, Kim57644f52011-05-31 03:44:19 -0300275int m5mols_read_u8(struct v4l2_subdev *sd, u32 reg_comb, u8 *val);
276int m5mols_read_u16(struct v4l2_subdev *sd, u32 reg_comb, u16 *val);
277int m5mols_read_u32(struct v4l2_subdev *sd, u32 reg_comb, u32 *val);
HeungJun, Kimbc125102011-05-20 02:27:28 -0300278int m5mols_write(struct v4l2_subdev *sd, u32 reg_comb, u32 val);
HeungJun Kim575d6252011-12-12 08:04:03 -0300279
280int m5mols_busy_wait(struct v4l2_subdev *sd, u32 reg, u32 value, u32 mask,
281 int timeout);
282
283/* Mask value for busy waiting until M-5MOLS I2C interface is initialized */
284#define M5MOLS_I2C_RDY_WAIT_FL (1 << 16)
285/* ISP state transition timeout, in ms */
286#define M5MOLS_MODE_CHANGE_TIMEOUT 200
287#define M5MOLS_BUSY_WAIT_DEF_TIMEOUT 250
HeungJun, Kimbc125102011-05-20 02:27:28 -0300288
289/*
290 * Mode operation of the M-5MOLS
291 *
292 * Changing the mode of the M-5MOLS is needed right executing order.
293 * There are three modes(PARAMETER, MONITOR, CAPTURE) which can be changed
294 * by user. There are various categories associated with each mode.
295 *
296 * +============================================================+
297 * | mode | category |
298 * +============================================================+
299 * | FLASH | FLASH(only after Stand-by or Power-on) |
300 * | SYSTEM | SYSTEM(only after sensor arm-booting) |
301 * | PARAMETER | PARAMETER |
302 * | MONITOR | MONITOR(preview), Auto Focus, Face Detection |
303 * | CAPTURE | Single CAPTURE, Preview(recording) |
304 * +============================================================+
305 *
306 * The available executing order between each modes are as follows:
307 * PARAMETER <---> MONITOR <---> CAPTURE
308 */
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300309int m5mols_set_mode(struct m5mols_info *info, u8 mode);
HeungJun, Kimbc125102011-05-20 02:27:28 -0300310
HeungJun, Kim57644f52011-05-31 03:44:19 -0300311int m5mols_enable_interrupt(struct v4l2_subdev *sd, u8 reg);
HeungJun Kimce808a42011-12-02 21:53:20 -0300312int m5mols_wait_interrupt(struct v4l2_subdev *sd, u8 condition, u32 timeout);
Sylwester Nawrocki5d4294b2011-12-12 15:45:56 -0300313int m5mols_restore_controls(struct m5mols_info *info);
HeungJun, Kimbc125102011-05-20 02:27:28 -0300314int m5mols_start_capture(struct m5mols_info *info);
HeungJun, Kim57644f52011-05-31 03:44:19 -0300315int m5mols_do_scenemode(struct m5mols_info *info, u8 mode);
HeungJun, Kimbc125102011-05-20 02:27:28 -0300316int m5mols_lock_3a(struct m5mols_info *info, bool lock);
317int m5mols_set_ctrl(struct v4l2_ctrl *ctrl);
Sylwester Nawrocki3c5da0b2012-04-09 13:51:56 -0300318int m5mols_init_controls(struct v4l2_subdev *sd);
HeungJun, Kimbc125102011-05-20 02:27:28 -0300319
320/* The firmware function */
321int m5mols_update_fw(struct v4l2_subdev *sd,
322 int (*set_power)(struct m5mols_info *, bool));
323
Sylwester Nawrocki91f4eb02012-03-06 07:08:56 -0300324static inline struct m5mols_info *to_m5mols(struct v4l2_subdev *subdev)
325{
326 return container_of(subdev, struct m5mols_info, sd);
327}
328
329static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
330{
331 struct m5mols_info *info = container_of(ctrl->handler,
332 struct m5mols_info, handle);
333 return &info->sd;
334}
335
Sylwester Nawrocki0373e972012-04-09 13:52:06 -0300336static inline void m5mols_set_ctrl_mode(struct v4l2_ctrl *ctrl,
337 unsigned int mode)
338{
Sylwester Nawrockie169c9b2012-08-07 04:58:35 -0300339 ctrl->priv = (void *)(uintptr_t)mode;
Sylwester Nawrocki0373e972012-04-09 13:52:06 -0300340}
341
342static inline unsigned int m5mols_get_ctrl_mode(struct v4l2_ctrl *ctrl)
343{
Sylwester Nawrockie169c9b2012-08-07 04:58:35 -0300344 return (unsigned int)(uintptr_t)ctrl->priv;
Sylwester Nawrocki0373e972012-04-09 13:52:06 -0300345}
346
HeungJun, Kimbc125102011-05-20 02:27:28 -0300347#endif /* M5MOLS_H */