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. |
HeungJun, Kim | c307011 | 2011-06-07 02:00:58 -0300 | [diff] [blame] | 5 | * Author: HeungJun Kim <riverful.kim@samsung.com> |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 2009 Samsung Electronics Co., Ltd. |
HeungJun, Kim | c307011 | 2011-06-07 02:00:58 -0300 | [diff] [blame] | 8 | * Author: Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com> |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 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 | |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 24 | enum m5mols_restype { |
| 25 | M5MOLS_RESTYPE_MONITOR, |
| 26 | M5MOLS_RESTYPE_CAPTURE, |
| 27 | M5MOLS_RESTYPE_MAX, |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * struct m5mols_resolution - structure for the resolution |
| 32 | * @type: resolution type according to the pixel code |
| 33 | * @width: width of the resolution |
| 34 | * @height: height of the resolution |
| 35 | * @reg: resolution preset register value |
| 36 | */ |
| 37 | struct m5mols_resolution { |
| 38 | u8 reg; |
| 39 | enum m5mols_restype type; |
| 40 | u16 width; |
| 41 | u16 height; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * struct m5mols_exif - structure for the EXIF information of M-5MOLS |
| 46 | * @exposure_time: exposure time register value |
| 47 | * @shutter_speed: speed of the shutter register value |
| 48 | * @aperture: aperture register value |
| 49 | * @exposure_bias: it calls also EV bias |
| 50 | * @iso_speed: ISO register value |
| 51 | * @flash: status register value of the flash |
| 52 | * @sdr: status register value of the Subject Distance Range |
| 53 | * @qval: not written exact meaning in document |
| 54 | */ |
| 55 | struct m5mols_exif { |
| 56 | u32 exposure_time; |
| 57 | u32 shutter_speed; |
| 58 | u32 aperture; |
| 59 | u32 brightness; |
| 60 | u32 exposure_bias; |
| 61 | u16 iso_speed; |
| 62 | u16 flash; |
| 63 | u16 sdr; |
| 64 | u16 qval; |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * struct m5mols_capture - Structure for the capture capability |
| 69 | * @exif: EXIF information |
| 70 | * @main: size in bytes of the main image |
| 71 | * @thumb: size in bytes of the thumb image, if it was accompanied |
| 72 | * @total: total size in bytes of the produced image |
| 73 | */ |
| 74 | struct m5mols_capture { |
| 75 | struct m5mols_exif exif; |
| 76 | u32 main; |
| 77 | u32 thumb; |
| 78 | u32 total; |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * struct m5mols_scenemode - structure for the scenemode capability |
| 83 | * @metering: metering light register value |
| 84 | * @ev_bias: EV bias register value |
| 85 | * @wb_mode: mode which means the WhiteBalance is Auto or Manual |
| 86 | * @wb_preset: whitebalance preset register value in the Manual mode |
| 87 | * @chroma_en: register value whether the Chroma capability is enabled or not |
| 88 | * @chroma_lvl: chroma's level register value |
| 89 | * @edge_en: register value Whether the Edge capability is enabled or not |
| 90 | * @edge_lvl: edge's level register value |
| 91 | * @af_range: Auto Focus's range |
| 92 | * @fd_mode: Face Detection mode |
| 93 | * @mcc: Multi-axis Color Conversion which means emotion color |
| 94 | * @light: status of the Light |
| 95 | * @flash: status of the Flash |
| 96 | * @tone: Tone color which means Contrast |
| 97 | * @iso: ISO register value |
| 98 | * @capt_mode: Mode of the Image Stabilization while the camera capturing |
| 99 | * @wdr: Wide Dynamic Range register value |
| 100 | * |
| 101 | * The each value according to each scenemode is recommended in the documents. |
| 102 | */ |
| 103 | struct m5mols_scenemode { |
HeungJun, Kim | 57644f5 | 2011-05-31 03:44:19 -0300 | [diff] [blame] | 104 | u8 metering; |
| 105 | u8 ev_bias; |
| 106 | u8 wb_mode; |
| 107 | u8 wb_preset; |
| 108 | u8 chroma_en; |
| 109 | u8 chroma_lvl; |
| 110 | u8 edge_en; |
| 111 | u8 edge_lvl; |
| 112 | u8 af_range; |
| 113 | u8 fd_mode; |
| 114 | u8 mcc; |
| 115 | u8 light; |
| 116 | u8 flash; |
| 117 | u8 tone; |
| 118 | u8 iso; |
| 119 | u8 capt_mode; |
| 120 | u8 wdr; |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /** |
| 124 | * struct m5mols_version - firmware version information |
| 125 | * @customer: customer information |
| 126 | * @project: version of project information according to customer |
| 127 | * @fw: firmware revision |
| 128 | * @hw: hardware revision |
| 129 | * @param: version of the parameter |
| 130 | * @awb: Auto WhiteBalance algorithm version |
| 131 | * @str: information about manufacturer and packaging vendor |
| 132 | * @af: Auto Focus version |
| 133 | * |
| 134 | * The register offset starts the customer version at 0x0, and it ends |
| 135 | * the awb version at 0x09. The customer, project information occupies 1 bytes |
| 136 | * each. And also the fw, hw, param, awb each requires 2 bytes. The str is |
| 137 | * unique string associated with firmware's version. It includes information |
| 138 | * about manufacturer and the vendor of the sensor's packaging. The least |
| 139 | * significant 2 bytes of the string indicate packaging manufacturer. |
| 140 | */ |
| 141 | #define VERSION_STRING_SIZE 22 |
| 142 | struct m5mols_version { |
| 143 | u8 customer; |
| 144 | u8 project; |
| 145 | u16 fw; |
| 146 | u16 hw; |
| 147 | u16 param; |
| 148 | u16 awb; |
| 149 | u8 str[VERSION_STRING_SIZE]; |
| 150 | u8 af; |
| 151 | }; |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * struct m5mols_info - M-5MOLS driver data structure |
| 155 | * @pdata: platform data |
| 156 | * @sd: v4l-subdev instance |
| 157 | * @pad: media pad |
| 158 | * @ffmt: current fmt according to resolution type |
| 159 | * @res_type: current resolution type |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 160 | * @irq_waitq: waitqueue for the capture |
Sylwester Nawrocki | 9346459 | 2012-05-09 11:53:09 -0300 | [diff] [blame] | 161 | * @irq_done: set to 1 in the interrupt handler |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 162 | * @handle: control handler |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 163 | * @auto_exposure: auto/manual exposure control |
Sylwester Nawrocki | 48311db | 2012-03-06 07:10:00 -0300 | [diff] [blame] | 164 | * @exposure_bias: exposure compensation control |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 165 | * @exposure: manual exposure control |
Sylwester Nawrocki | 50d3f93 | 2012-04-09 14:51:49 -0300 | [diff] [blame] | 166 | * @metering: exposure metering control |
Sylwester Nawrocki | 44b153c | 2012-04-09 13:19:25 -0300 | [diff] [blame] | 167 | * @auto_iso: auto/manual ISO sensitivity control |
| 168 | * @iso: manual ISO sensitivity control |
Sylwester Nawrocki | d7a87e4 | 2012-05-08 06:56:35 -0300 | [diff] [blame] | 169 | * @auto_wb: auto white balance control |
Sylwester Nawrocki | 9346459 | 2012-05-09 11:53:09 -0300 | [diff] [blame] | 170 | * @lock_3a: 3A lock control |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 171 | * @colorfx: color effect control |
| 172 | * @saturation: saturation control |
| 173 | * @zoom: zoom control |
Sylwester Nawrocki | 4eb3419 | 2012-03-06 07:10:13 -0300 | [diff] [blame] | 174 | * @wdr: wide dynamic range control |
Sylwester Nawrocki | efcb07c | 2012-03-06 07:10:27 -0300 | [diff] [blame] | 175 | * @stabilization: image stabilization control |
Sylwester Nawrocki | dd9c471 | 2012-02-28 06:29:01 -0300 | [diff] [blame] | 176 | * @jpeg_quality: JPEG compression quality control |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 177 | * @ver: information of the version |
| 178 | * @cap: the capture mode attributes |
HeungJun Kim | 0f2ee1d | 2011-12-03 11:47:40 -0300 | [diff] [blame] | 179 | * @isp_ready: 1 when the ISP controller has completed booting |
Sylwester Nawrocki | 9346459 | 2012-05-09 11:53:09 -0300 | [diff] [blame] | 180 | * @power: current sensor's power status |
HeungJun Kim | 0f2ee1d | 2011-12-03 11:47:40 -0300 | [diff] [blame] | 181 | * @ctrl_sync: 1 when the control handler state is restored in H/W |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 182 | * @resolution: register value for current resolution |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 183 | * @mode: register value for current operation mode |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 184 | * @set_power: optional power callback to the board code |
| 185 | */ |
| 186 | struct m5mols_info { |
| 187 | const struct m5mols_platform_data *pdata; |
| 188 | struct v4l2_subdev sd; |
| 189 | struct media_pad pad; |
| 190 | struct v4l2_mbus_framefmt ffmt[M5MOLS_RESTYPE_MAX]; |
| 191 | int res_type; |
Sylwester Nawrocki | 5d4294b | 2011-12-12 15:45:56 -0300 | [diff] [blame] | 192 | |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 193 | wait_queue_head_t irq_waitq; |
HeungJun Kim | ce808a4 | 2011-12-02 21:53:20 -0300 | [diff] [blame] | 194 | atomic_t irq_done; |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 195 | |
| 196 | struct v4l2_ctrl_handler handle; |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 197 | struct { |
Sylwester Nawrocki | 48311db | 2012-03-06 07:10:00 -0300 | [diff] [blame] | 198 | /* exposure/exposure bias/auto exposure cluster */ |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 199 | struct v4l2_ctrl *auto_exposure; |
Sylwester Nawrocki | 48311db | 2012-03-06 07:10:00 -0300 | [diff] [blame] | 200 | struct v4l2_ctrl *exposure_bias; |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 201 | struct v4l2_ctrl *exposure; |
Sylwester Nawrocki | 50d3f93 | 2012-04-09 14:51:49 -0300 | [diff] [blame] | 202 | struct v4l2_ctrl *metering; |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 203 | }; |
Sylwester Nawrocki | 44b153c | 2012-04-09 13:19:25 -0300 | [diff] [blame] | 204 | struct { |
| 205 | /* iso/auto iso cluster */ |
| 206 | struct v4l2_ctrl *auto_iso; |
| 207 | struct v4l2_ctrl *iso; |
| 208 | }; |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 209 | struct v4l2_ctrl *auto_wb; |
Sylwester Nawrocki | d7a87e4 | 2012-05-08 06:56:35 -0300 | [diff] [blame] | 210 | |
Sylwester Nawrocki | 9346459 | 2012-05-09 11:53:09 -0300 | [diff] [blame] | 211 | struct v4l2_ctrl *lock_3a; |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 212 | struct v4l2_ctrl *colorfx; |
| 213 | struct v4l2_ctrl *saturation; |
| 214 | struct v4l2_ctrl *zoom; |
Sylwester Nawrocki | 4eb3419 | 2012-03-06 07:10:13 -0300 | [diff] [blame] | 215 | struct v4l2_ctrl *wdr; |
Sylwester Nawrocki | efcb07c | 2012-03-06 07:10:27 -0300 | [diff] [blame] | 216 | struct v4l2_ctrl *stabilization; |
Sylwester Nawrocki | dd9c471 | 2012-02-28 06:29:01 -0300 | [diff] [blame] | 217 | struct v4l2_ctrl *jpeg_quality; |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 218 | |
| 219 | struct m5mols_version ver; |
| 220 | struct m5mols_capture cap; |
HeungJun Kim | 0f2ee1d | 2011-12-03 11:47:40 -0300 | [diff] [blame] | 221 | |
| 222 | unsigned int isp_ready:1; |
| 223 | unsigned int power:1; |
| 224 | unsigned int ctrl_sync:1; |
| 225 | |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 226 | u8 resolution; |
HeungJun, Kim | 57644f5 | 2011-05-31 03:44:19 -0300 | [diff] [blame] | 227 | u8 mode; |
Sylwester Nawrocki | 5d4294b | 2011-12-12 15:45:56 -0300 | [diff] [blame] | 228 | |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 229 | int (*set_power)(struct device *dev, int on); |
| 230 | }; |
| 231 | |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 232 | #define is_available_af(__info) (__info->ver.af) |
| 233 | #define is_code(__code, __type) (__code == m5mols_default_ffmt[__type].code) |
| 234 | #define is_manufacturer(__info, __manufacturer) \ |
| 235 | (__info->ver.str[0] == __manufacturer[0] && \ |
| 236 | __info->ver.str[1] == __manufacturer[1]) |
| 237 | /* |
| 238 | * I2C operation of the M-5MOLS |
| 239 | * |
| 240 | * The I2C read operation of the M-5MOLS requires 2 messages. The first |
| 241 | * message sends the information about the command, command category, and total |
| 242 | * message size. The second message is used to retrieve the data specifed in |
| 243 | * the first message |
| 244 | * |
| 245 | * 1st message 2nd message |
| 246 | * +-------+---+----------+-----+-------+ +------+------+------+------+ |
| 247 | * | size1 | R | category | cmd | size2 | | d[0] | d[1] | d[2] | d[3] | |
| 248 | * +-------+---+----------+-----+-------+ +------+------+------+------+ |
| 249 | * - size1: message data size(5 in this case) |
| 250 | * - size2: desired buffer size of the 2nd message |
| 251 | * - d[0..3]: according to size2 |
| 252 | * |
| 253 | * The I2C write operation needs just one message. The message includes |
| 254 | * category, command, total size, and desired data. |
| 255 | * |
| 256 | * 1st message |
| 257 | * +-------+---+----------+-----+------+------+------+------+ |
| 258 | * | size1 | W | category | cmd | d[0] | d[1] | d[2] | d[3] | |
| 259 | * +-------+---+----------+-----+------+------+------+------+ |
| 260 | * - d[0..3]: according to size1 |
| 261 | */ |
HeungJun, Kim | 57644f5 | 2011-05-31 03:44:19 -0300 | [diff] [blame] | 262 | int m5mols_read_u8(struct v4l2_subdev *sd, u32 reg_comb, u8 *val); |
| 263 | int m5mols_read_u16(struct v4l2_subdev *sd, u32 reg_comb, u16 *val); |
| 264 | int m5mols_read_u32(struct v4l2_subdev *sd, u32 reg_comb, u32 *val); |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 265 | int m5mols_write(struct v4l2_subdev *sd, u32 reg_comb, u32 val); |
HeungJun Kim | 575d625 | 2011-12-12 08:04:03 -0300 | [diff] [blame] | 266 | |
| 267 | int m5mols_busy_wait(struct v4l2_subdev *sd, u32 reg, u32 value, u32 mask, |
| 268 | int timeout); |
| 269 | |
| 270 | /* Mask value for busy waiting until M-5MOLS I2C interface is initialized */ |
| 271 | #define M5MOLS_I2C_RDY_WAIT_FL (1 << 16) |
| 272 | /* ISP state transition timeout, in ms */ |
| 273 | #define M5MOLS_MODE_CHANGE_TIMEOUT 200 |
| 274 | #define M5MOLS_BUSY_WAIT_DEF_TIMEOUT 250 |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * Mode operation of the M-5MOLS |
| 278 | * |
| 279 | * Changing the mode of the M-5MOLS is needed right executing order. |
| 280 | * There are three modes(PARAMETER, MONITOR, CAPTURE) which can be changed |
| 281 | * by user. There are various categories associated with each mode. |
| 282 | * |
| 283 | * +============================================================+ |
| 284 | * | mode | category | |
| 285 | * +============================================================+ |
| 286 | * | FLASH | FLASH(only after Stand-by or Power-on) | |
| 287 | * | SYSTEM | SYSTEM(only after sensor arm-booting) | |
| 288 | * | PARAMETER | PARAMETER | |
| 289 | * | MONITOR | MONITOR(preview), Auto Focus, Face Detection | |
| 290 | * | CAPTURE | Single CAPTURE, Preview(recording) | |
| 291 | * +============================================================+ |
| 292 | * |
| 293 | * The available executing order between each modes are as follows: |
| 294 | * PARAMETER <---> MONITOR <---> CAPTURE |
| 295 | */ |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 296 | int m5mols_set_mode(struct m5mols_info *info, u8 mode); |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 297 | |
HeungJun, Kim | 57644f5 | 2011-05-31 03:44:19 -0300 | [diff] [blame] | 298 | int m5mols_enable_interrupt(struct v4l2_subdev *sd, u8 reg); |
HeungJun Kim | ce808a4 | 2011-12-02 21:53:20 -0300 | [diff] [blame] | 299 | int m5mols_wait_interrupt(struct v4l2_subdev *sd, u8 condition, u32 timeout); |
Sylwester Nawrocki | 5d4294b | 2011-12-12 15:45:56 -0300 | [diff] [blame] | 300 | int m5mols_restore_controls(struct m5mols_info *info); |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 301 | int m5mols_start_capture(struct m5mols_info *info); |
HeungJun, Kim | 57644f5 | 2011-05-31 03:44:19 -0300 | [diff] [blame] | 302 | int m5mols_do_scenemode(struct m5mols_info *info, u8 mode); |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 303 | int m5mols_lock_3a(struct m5mols_info *info, bool lock); |
| 304 | int m5mols_set_ctrl(struct v4l2_ctrl *ctrl); |
Sylwester Nawrocki | 3c5da0b | 2012-04-09 13:51:56 -0300 | [diff] [blame] | 305 | int m5mols_init_controls(struct v4l2_subdev *sd); |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 306 | |
| 307 | /* The firmware function */ |
| 308 | int m5mols_update_fw(struct v4l2_subdev *sd, |
| 309 | int (*set_power)(struct m5mols_info *, bool)); |
| 310 | |
Sylwester Nawrocki | 91f4eb0 | 2012-03-06 07:08:56 -0300 | [diff] [blame] | 311 | static inline struct m5mols_info *to_m5mols(struct v4l2_subdev *subdev) |
| 312 | { |
| 313 | return container_of(subdev, struct m5mols_info, sd); |
| 314 | } |
| 315 | |
| 316 | static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) |
| 317 | { |
| 318 | struct m5mols_info *info = container_of(ctrl->handler, |
| 319 | struct m5mols_info, handle); |
| 320 | return &info->sd; |
| 321 | } |
| 322 | |
Sylwester Nawrocki | 0373e97 | 2012-04-09 13:52:06 -0300 | [diff] [blame] | 323 | static inline void m5mols_set_ctrl_mode(struct v4l2_ctrl *ctrl, |
| 324 | unsigned int mode) |
| 325 | { |
| 326 | ctrl->priv = (void *)mode; |
| 327 | } |
| 328 | |
| 329 | static inline unsigned int m5mols_get_ctrl_mode(struct v4l2_ctrl *ctrl) |
| 330 | { |
| 331 | return (unsigned int)ctrl->priv; |
| 332 | } |
| 333 | |
HeungJun, Kim | bc12510 | 2011-05-20 02:27:28 -0300 | [diff] [blame] | 334 | #endif /* M5MOLS_H */ |