m5mols.h 11 KB

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