HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 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 | |
| 24 | #define to_m5mols(__sd) container_of(__sd, struct m5mols_info, sd) |
| 25 | |
| 26 | #define to_sd(__ctrl) \ |
| 27 | (&container_of(__ctrl->handler, struct m5mols_info, handle)->sd) |
| 28 | |
| 29 | enum m5mols_restype { |
| 30 | M5MOLS_RESTYPE_MONITOR, |
| 31 | M5MOLS_RESTYPE_CAPTURE, |
| 32 | M5MOLS_RESTYPE_MAX, |
| 33 | }; |
| 34 | |
| 35 | /** |
| 36 | * struct m5mols_resolution - structure for the resolution |
| 37 | * @type: resolution type according to the pixel code |
| 38 | * @width: width of the resolution |
| 39 | * @height: height of the resolution |
| 40 | * @reg: resolution preset register value |
| 41 | */ |
| 42 | struct m5mols_resolution { |
| 43 | u8 reg; |
| 44 | enum m5mols_restype type; |
| 45 | u16 width; |
| 46 | u16 height; |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * struct m5mols_exif - structure for the EXIF information of M-5MOLS |
| 51 | * @exposure_time: exposure time register value |
| 52 | * @shutter_speed: speed of the shutter register value |
| 53 | * @aperture: aperture register value |
| 54 | * @exposure_bias: it calls also EV bias |
| 55 | * @iso_speed: ISO register value |
| 56 | * @flash: status register value of the flash |
| 57 | * @sdr: status register value of the Subject Distance Range |
| 58 | * @qval: not written exact meaning in document |
| 59 | */ |
| 60 | struct m5mols_exif { |
| 61 | u32 exposure_time; |
| 62 | u32 shutter_speed; |
| 63 | u32 aperture; |
| 64 | u32 brightness; |
| 65 | u32 exposure_bias; |
| 66 | u16 iso_speed; |
| 67 | u16 flash; |
| 68 | u16 sdr; |
| 69 | u16 qval; |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * struct m5mols_capture - Structure for the capture capability |
| 74 | * @exif: EXIF information |
| 75 | * @main: size in bytes of the main image |
| 76 | * @thumb: size in bytes of the thumb image, if it was accompanied |
| 77 | * @total: total size in bytes of the produced image |
| 78 | */ |
| 79 | struct m5mols_capture { |
| 80 | struct m5mols_exif exif; |
| 81 | u32 main; |
| 82 | u32 thumb; |
| 83 | u32 total; |
| 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * struct m5mols_scenemode - structure for the scenemode capability |
| 88 | * @metering: metering light register value |
| 89 | * @ev_bias: EV bias register value |
| 90 | * @wb_mode: mode which means the WhiteBalance is Auto or Manual |
| 91 | * @wb_preset: whitebalance preset register value in the Manual mode |
| 92 | * @chroma_en: register value whether the Chroma capability is enabled or not |
| 93 | * @chroma_lvl: chroma's level register value |
| 94 | * @edge_en: register value Whether the Edge capability is enabled or not |
| 95 | * @edge_lvl: edge's level register value |
| 96 | * @af_range: Auto Focus's range |
| 97 | * @fd_mode: Face Detection mode |
| 98 | * @mcc: Multi-axis Color Conversion which means emotion color |
| 99 | * @light: status of the Light |
| 100 | * @flash: status of the Flash |
| 101 | * @tone: Tone color which means Contrast |
| 102 | * @iso: ISO register value |
| 103 | * @capt_mode: Mode of the Image Stabilization while the camera capturing |
| 104 | * @wdr: Wide Dynamic Range register value |
| 105 | * |
| 106 | * The each value according to each scenemode is recommended in the documents. |
| 107 | */ |
| 108 | struct m5mols_scenemode { |
| 109 | u32 metering; |
| 110 | u32 ev_bias; |
| 111 | u32 wb_mode; |
| 112 | u32 wb_preset; |
| 113 | u32 chroma_en; |
| 114 | u32 chroma_lvl; |
| 115 | u32 edge_en; |
| 116 | u32 edge_lvl; |
| 117 | u32 af_range; |
| 118 | u32 fd_mode; |
| 119 | u32 mcc; |
| 120 | u32 light; |
| 121 | u32 flash; |
| 122 | u32 tone; |
| 123 | u32 iso; |
| 124 | u32 capt_mode; |
| 125 | u32 wdr; |
| 126 | }; |
| 127 | |
| 128 | /** |
| 129 | * struct m5mols_version - firmware version information |
| 130 | * @customer: customer information |
| 131 | * @project: version of project information according to customer |
| 132 | * @fw: firmware revision |
| 133 | * @hw: hardware revision |
| 134 | * @param: version of the parameter |
| 135 | * @awb: Auto WhiteBalance algorithm version |
| 136 | * @str: information about manufacturer and packaging vendor |
| 137 | * @af: Auto Focus version |
| 138 | * |
| 139 | * The register offset starts the customer version at 0x0, and it ends |
| 140 | * the awb version at 0x09. The customer, project information occupies 1 bytes |
| 141 | * each. And also the fw, hw, param, awb each requires 2 bytes. The str is |
| 142 | * unique string associated with firmware's version. It includes information |
| 143 | * about manufacturer and the vendor of the sensor's packaging. The least |
| 144 | * significant 2 bytes of the string indicate packaging manufacturer. |
| 145 | */ |
| 146 | #define VERSION_STRING_SIZE 22 |
| 147 | struct m5mols_version { |
| 148 | u8 customer; |
| 149 | u8 project; |
| 150 | u16 fw; |
| 151 | u16 hw; |
| 152 | u16 param; |
| 153 | u16 awb; |
| 154 | u8 str[VERSION_STRING_SIZE]; |
| 155 | u8 af; |
| 156 | }; |
| 157 | #define VERSION_SIZE sizeof(struct m5mols_version) |
| 158 | |
| 159 | /** |
| 160 | * struct m5mols_info - M-5MOLS driver data structure |
| 161 | * @pdata: platform data |
| 162 | * @sd: v4l-subdev instance |
| 163 | * @pad: media pad |
| 164 | * @ffmt: current fmt according to resolution type |
| 165 | * @res_type: current resolution type |
| 166 | * @code: current code |
| 167 | * @irq_waitq: waitqueue for the capture |
| 168 | * @work_irq: workqueue for the IRQ |
| 169 | * @flags: state variable for the interrupt handler |
| 170 | * @handle: control handler |
| 171 | * @autoexposure: Auto Exposure control |
| 172 | * @exposure: Exposure control |
| 173 | * @autowb: Auto White Balance control |
| 174 | * @colorfx: Color effect control |
| 175 | * @saturation: Saturation control |
| 176 | * @zoom: Zoom control |
| 177 | * @ver: information of the version |
| 178 | * @cap: the capture mode attributes |
| 179 | * @power: current sensor's power status |
| 180 | * @ctrl_sync: true means all controls of the sensor are initialized |
| 181 | * @int_capture: true means the capture interrupt is issued once |
| 182 | * @lock_ae: true means the Auto Exposure is locked |
| 183 | * @lock_awb: true means the Aut WhiteBalance is locked |
| 184 | * @resolution: register value for current resolution |
| 185 | * @interrupt: register value for current interrupt status |
| 186 | * @mode: register value for current operation mode |
| 187 | * @mode_save: register value for current operation mode for saving |
| 188 | * @set_power: optional power callback to the board code |
| 189 | */ |
| 190 | struct m5mols_info { |
| 191 | const struct m5mols_platform_data *pdata; |
| 192 | struct v4l2_subdev sd; |
| 193 | struct media_pad pad; |
| 194 | struct v4l2_mbus_framefmt ffmt[M5MOLS_RESTYPE_MAX]; |
| 195 | int res_type; |
| 196 | enum v4l2_mbus_pixelcode code; |
| 197 | wait_queue_head_t irq_waitq; |
| 198 | struct work_struct work_irq; |
| 199 | unsigned long flags; |
| 200 | |
| 201 | struct v4l2_ctrl_handler handle; |
| 202 | /* Autoexposure/exposure control cluster */ |
| 203 | struct { |
| 204 | struct v4l2_ctrl *autoexposure; |
| 205 | struct v4l2_ctrl *exposure; |
| 206 | }; |
| 207 | struct v4l2_ctrl *autowb; |
| 208 | struct v4l2_ctrl *colorfx; |
| 209 | struct v4l2_ctrl *saturation; |
| 210 | struct v4l2_ctrl *zoom; |
| 211 | |
| 212 | struct m5mols_version ver; |
| 213 | struct m5mols_capture cap; |
| 214 | bool power; |
| 215 | bool ctrl_sync; |
| 216 | bool lock_ae; |
| 217 | bool lock_awb; |
| 218 | u8 resolution; |
| 219 | u32 interrupt; |
| 220 | u32 mode; |
| 221 | u32 mode_save; |
| 222 | int (*set_power)(struct device *dev, int on); |
| 223 | }; |
| 224 | |
| 225 | #define ST_CAPT_IRQ 0 |
| 226 | |
| 227 | #define is_powered(__info) (__info->power) |
| 228 | #define is_ctrl_synced(__info) (__info->ctrl_sync) |
| 229 | #define is_available_af(__info) (__info->ver.af) |
| 230 | #define is_code(__code, __type) (__code == m5mols_default_ffmt[__type].code) |
| 231 | #define is_manufacturer(__info, __manufacturer) \ |
| 232 | (__info->ver.str[0] == __manufacturer[0] && \ |
| 233 | __info->ver.str[1] == __manufacturer[1]) |
| 234 | /* |
| 235 | * I2C operation of the M-5MOLS |
| 236 | * |
| 237 | * The I2C read operation of the M-5MOLS requires 2 messages. The first |
| 238 | * message sends the information about the command, command category, and total |
| 239 | * message size. The second message is used to retrieve the data specifed in |
| 240 | * the first message |
| 241 | * |
| 242 | * 1st message 2nd message |
| 243 | * +-------+---+----------+-----+-------+ +------+------+------+------+ |
| 244 | * | size1 | R | category | cmd | size2 | | d[0] | d[1] | d[2] | d[3] | |
| 245 | * +-------+---+----------+-----+-------+ +------+------+------+------+ |
| 246 | * - size1: message data size(5 in this case) |
| 247 | * - size2: desired buffer size of the 2nd message |
| 248 | * - d[0..3]: according to size2 |
| 249 | * |
| 250 | * The I2C write operation needs just one message. The message includes |
| 251 | * category, command, total size, and desired data. |
| 252 | * |
| 253 | * 1st message |
| 254 | * +-------+---+----------+-----+------+------+------+------+ |
| 255 | * | size1 | W | category | cmd | d[0] | d[1] | d[2] | d[3] | |
| 256 | * +-------+---+----------+-----+------+------+------+------+ |
| 257 | * - d[0..3]: according to size1 |
| 258 | */ |
| 259 | int m5mols_read(struct v4l2_subdev *sd, u32 reg_comb, u32 *val); |
| 260 | int m5mols_write(struct v4l2_subdev *sd, u32 reg_comb, u32 val); |
| 261 | int m5mols_busy(struct v4l2_subdev *sd, u8 category, u8 cmd, u32 value); |
| 262 | |
| 263 | /* |
| 264 | * Mode operation of the M-5MOLS |
| 265 | * |
| 266 | * Changing the mode of the M-5MOLS is needed right executing order. |
| 267 | * There are three modes(PARAMETER, MONITOR, CAPTURE) which can be changed |
| 268 | * by user. There are various categories associated with each mode. |
| 269 | * |
| 270 | * +============================================================+ |
| 271 | * | mode | category | |
| 272 | * +============================================================+ |
| 273 | * | FLASH | FLASH(only after Stand-by or Power-on) | |
| 274 | * | SYSTEM | SYSTEM(only after sensor arm-booting) | |
| 275 | * | PARAMETER | PARAMETER | |
| 276 | * | MONITOR | MONITOR(preview), Auto Focus, Face Detection | |
| 277 | * | CAPTURE | Single CAPTURE, Preview(recording) | |
| 278 | * +============================================================+ |
| 279 | * |
| 280 | * The available executing order between each modes are as follows: |
| 281 | * PARAMETER <---> MONITOR <---> CAPTURE |
| 282 | */ |
| 283 | int m5mols_mode(struct m5mols_info *info, u32 mode); |
| 284 | |
| 285 | int m5mols_enable_interrupt(struct v4l2_subdev *sd, u32 reg); |
| 286 | int m5mols_sync_controls(struct m5mols_info *info); |
| 287 | int m5mols_start_capture(struct m5mols_info *info); |
| 288 | int m5mols_do_scenemode(struct m5mols_info *info, u32 mode); |
| 289 | int m5mols_lock_3a(struct m5mols_info *info, bool lock); |
| 290 | int m5mols_set_ctrl(struct v4l2_ctrl *ctrl); |
| 291 | |
| 292 | /* The firmware function */ |
| 293 | int m5mols_update_fw(struct v4l2_subdev *sd, |
| 294 | int (*set_power)(struct m5mols_info *, bool)); |
| 295 | |
| 296 | #endif /* M5MOLS_H */ |