m5mols.h 9.5 KB

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