fimc-core.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef FIMC_CORE_H_
  9. #define FIMC_CORE_H_
  10. /*#define DEBUG*/
  11. #include <linux/platform_device.h>
  12. #include <linux/sched.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/types.h>
  15. #include <linux/videodev2.h>
  16. #include <linux/io.h>
  17. #include <media/media-entity.h>
  18. #include <media/videobuf2-core.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <media/v4l2-device.h>
  21. #include <media/v4l2-mem2mem.h>
  22. #include <media/v4l2-mediabus.h>
  23. #include <media/s5p_fimc.h>
  24. #define err(fmt, args...) \
  25. printk(KERN_ERR "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
  26. #define dbg(fmt, args...) \
  27. pr_debug("%s:%d: " fmt "\n", __func__, __LINE__, ##args)
  28. /* Time to wait for next frame VSYNC interrupt while stopping operation. */
  29. #define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000)
  30. #define MAX_FIMC_CLOCKS 2
  31. #define FIMC_MODULE_NAME "s5p-fimc"
  32. #define FIMC_MAX_DEVS 4
  33. #define FIMC_MAX_OUT_BUFS 4
  34. #define SCALER_MAX_HRATIO 64
  35. #define SCALER_MAX_VRATIO 64
  36. #define DMA_MIN_SIZE 8
  37. #define FIMC_CAMIF_MAX_HEIGHT 0x2000
  38. /* indices to the clocks array */
  39. enum {
  40. CLK_BUS,
  41. CLK_GATE,
  42. };
  43. enum fimc_dev_flags {
  44. ST_LPM,
  45. /* m2m node */
  46. ST_M2M_RUN,
  47. ST_M2M_PEND,
  48. ST_M2M_SUSPENDING,
  49. ST_M2M_SUSPENDED,
  50. /* capture node */
  51. ST_CAPT_PEND,
  52. ST_CAPT_RUN,
  53. ST_CAPT_STREAM,
  54. ST_CAPT_ISP_STREAM,
  55. ST_CAPT_SUSPENDED,
  56. ST_CAPT_SHUT,
  57. ST_CAPT_BUSY,
  58. ST_CAPT_APPLY_CFG,
  59. ST_CAPT_JPEG,
  60. };
  61. #define fimc_m2m_active(dev) test_bit(ST_M2M_RUN, &(dev)->state)
  62. #define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
  63. #define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state)
  64. #define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state)
  65. #define fimc_capture_busy(dev) test_bit(ST_CAPT_BUSY, &(dev)->state)
  66. enum fimc_datapath {
  67. FIMC_CAMERA,
  68. FIMC_DMA,
  69. FIMC_LCDFIFO,
  70. FIMC_WRITEBACK
  71. };
  72. enum fimc_color_fmt {
  73. S5P_FIMC_RGB444 = 0x10,
  74. S5P_FIMC_RGB555,
  75. S5P_FIMC_RGB565,
  76. S5P_FIMC_RGB666,
  77. S5P_FIMC_RGB888,
  78. S5P_FIMC_RGB30_LOCAL,
  79. S5P_FIMC_YCBCR420 = 0x20,
  80. S5P_FIMC_YCBYCR422,
  81. S5P_FIMC_YCRYCB422,
  82. S5P_FIMC_CBYCRY422,
  83. S5P_FIMC_CRYCBY422,
  84. S5P_FIMC_YCBCR444_LOCAL,
  85. S5P_FIMC_JPEG = 0x40,
  86. };
  87. #define fimc_fmt_is_rgb(x) (!!((x) & 0x10))
  88. #define fimc_fmt_is_jpeg(x) (!!((x) & 0x40))
  89. #define IS_M2M(__strt) ((__strt) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || \
  90. __strt == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
  91. /* The hardware context state. */
  92. #define FIMC_PARAMS (1 << 0)
  93. #define FIMC_SRC_FMT (1 << 3)
  94. #define FIMC_DST_FMT (1 << 4)
  95. #define FIMC_DST_CROP (1 << 5)
  96. #define FIMC_CTX_M2M (1 << 16)
  97. #define FIMC_CTX_CAP (1 << 17)
  98. #define FIMC_CTX_SHUT (1 << 18)
  99. /* Image conversion flags */
  100. #define FIMC_IN_DMA_ACCESS_TILED (1 << 0)
  101. #define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0)
  102. #define FIMC_OUT_DMA_ACCESS_TILED (1 << 1)
  103. #define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1)
  104. #define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2)
  105. #define FIMC_SCAN_MODE_INTERLACED (1 << 2)
  106. /*
  107. * YCbCr data dynamic range for RGB-YUV color conversion.
  108. * Y/Cb/Cr: (0 ~ 255) */
  109. #define FIMC_COLOR_RANGE_WIDE (0 << 3)
  110. /* Y (16 ~ 235), Cb/Cr (16 ~ 240) */
  111. #define FIMC_COLOR_RANGE_NARROW (1 << 3)
  112. /**
  113. * struct fimc_fmt - the driver's internal color format data
  114. * @mbus_code: Media Bus pixel code, -1 if not applicable
  115. * @name: format description
  116. * @fourcc: the fourcc code for this format, 0 if not applicable
  117. * @color: the corresponding fimc_color_fmt
  118. * @memplanes: number of physically non-contiguous data planes
  119. * @colplanes: number of physically contiguous data planes
  120. * @depth: per plane driver's private 'number of bits per pixel'
  121. * @flags: flags indicating which operation mode format applies to
  122. */
  123. struct fimc_fmt {
  124. enum v4l2_mbus_pixelcode mbus_code;
  125. char *name;
  126. u32 fourcc;
  127. u32 color;
  128. u16 memplanes;
  129. u16 colplanes;
  130. u8 depth[VIDEO_MAX_PLANES];
  131. u16 flags;
  132. #define FMT_FLAGS_CAM (1 << 0)
  133. #define FMT_FLAGS_M2M_IN (1 << 1)
  134. #define FMT_FLAGS_M2M_OUT (1 << 2)
  135. #define FMT_FLAGS_M2M (1 << 1 | 1 << 2)
  136. #define FMT_HAS_ALPHA (1 << 3)
  137. };
  138. /**
  139. * struct fimc_dma_offset - pixel offset information for DMA
  140. * @y_h: y value horizontal offset
  141. * @y_v: y value vertical offset
  142. * @cb_h: cb value horizontal offset
  143. * @cb_v: cb value vertical offset
  144. * @cr_h: cr value horizontal offset
  145. * @cr_v: cr value vertical offset
  146. */
  147. struct fimc_dma_offset {
  148. int y_h;
  149. int y_v;
  150. int cb_h;
  151. int cb_v;
  152. int cr_h;
  153. int cr_v;
  154. };
  155. /**
  156. * struct fimc_effect - color effect information
  157. * @type: effect type
  158. * @pat_cb: cr value when type is "arbitrary"
  159. * @pat_cr: cr value when type is "arbitrary"
  160. */
  161. struct fimc_effect {
  162. u32 type;
  163. u8 pat_cb;
  164. u8 pat_cr;
  165. };
  166. /**
  167. * struct fimc_scaler - the configuration data for FIMC inetrnal scaler
  168. * @scaleup_h: flag indicating scaling up horizontally
  169. * @scaleup_v: flag indicating scaling up vertically
  170. * @copy_mode: flag indicating transparent DMA transfer (no scaling
  171. * and color format conversion)
  172. * @enabled: flag indicating if the scaler is used
  173. * @hfactor: horizontal shift factor
  174. * @vfactor: vertical shift factor
  175. * @pre_hratio: horizontal ratio of the prescaler
  176. * @pre_vratio: vertical ratio of the prescaler
  177. * @pre_dst_width: the prescaler's destination width
  178. * @pre_dst_height: the prescaler's destination height
  179. * @main_hratio: the main scaler's horizontal ratio
  180. * @main_vratio: the main scaler's vertical ratio
  181. * @real_width: source pixel (width - offset)
  182. * @real_height: source pixel (height - offset)
  183. */
  184. struct fimc_scaler {
  185. unsigned int scaleup_h:1;
  186. unsigned int scaleup_v:1;
  187. unsigned int copy_mode:1;
  188. unsigned int enabled:1;
  189. u32 hfactor;
  190. u32 vfactor;
  191. u32 pre_hratio;
  192. u32 pre_vratio;
  193. u32 pre_dst_width;
  194. u32 pre_dst_height;
  195. u32 main_hratio;
  196. u32 main_vratio;
  197. u32 real_width;
  198. u32 real_height;
  199. };
  200. /**
  201. * struct fimc_addr - the FIMC physical address set for DMA
  202. * @y: luminance plane physical address
  203. * @cb: Cb plane physical address
  204. * @cr: Cr plane physical address
  205. */
  206. struct fimc_addr {
  207. u32 y;
  208. u32 cb;
  209. u32 cr;
  210. };
  211. /**
  212. * struct fimc_vid_buffer - the driver's video buffer
  213. * @vb: v4l videobuf buffer
  214. * @list: linked list structure for buffer queue
  215. * @paddr: precalculated physical address set
  216. * @index: buffer index for the output DMA engine
  217. */
  218. struct fimc_vid_buffer {
  219. struct vb2_buffer vb;
  220. struct list_head list;
  221. struct fimc_addr paddr;
  222. int index;
  223. };
  224. /**
  225. * struct fimc_frame - source/target frame properties
  226. * @f_width: image full width (virtual screen size)
  227. * @f_height: image full height (virtual screen size)
  228. * @o_width: original image width as set by S_FMT
  229. * @o_height: original image height as set by S_FMT
  230. * @offs_h: image horizontal pixel offset
  231. * @offs_v: image vertical pixel offset
  232. * @width: image pixel width
  233. * @height: image pixel weight
  234. * @payload: image size in bytes (w x h x bpp)
  235. * @paddr: image frame buffer physical addresses
  236. * @dma_offset: DMA offset in bytes
  237. * @fmt: fimc color format pointer
  238. */
  239. struct fimc_frame {
  240. u32 f_width;
  241. u32 f_height;
  242. u32 o_width;
  243. u32 o_height;
  244. u32 offs_h;
  245. u32 offs_v;
  246. u32 width;
  247. u32 height;
  248. unsigned long payload[VIDEO_MAX_PLANES];
  249. struct fimc_addr paddr;
  250. struct fimc_dma_offset dma_offset;
  251. struct fimc_fmt *fmt;
  252. u8 alpha;
  253. };
  254. /**
  255. * struct fimc_m2m_device - v4l2 memory-to-memory device data
  256. * @vfd: the video device node for v4l2 m2m mode
  257. * @m2m_dev: v4l2 memory-to-memory device data
  258. * @ctx: hardware context data
  259. * @refcnt: the reference counter
  260. */
  261. struct fimc_m2m_device {
  262. struct video_device *vfd;
  263. struct v4l2_m2m_dev *m2m_dev;
  264. struct fimc_ctx *ctx;
  265. int refcnt;
  266. };
  267. #define FIMC_SD_PAD_SINK 0
  268. #define FIMC_SD_PAD_SOURCE 1
  269. #define FIMC_SD_PADS_NUM 2
  270. /**
  271. * struct fimc_vid_cap - camera capture device information
  272. * @ctx: hardware context data
  273. * @vfd: video device node for camera capture mode
  274. * @subdev: subdev exposing the FIMC processing block
  275. * @vd_pad: fimc video capture node pad
  276. * @sd_pads: fimc video processing block pads
  277. * @mf: media bus format at the FIMC camera input (and the scaler output) pad
  278. * @pending_buf_q: the pending buffer queue head
  279. * @active_buf_q: the queue head of buffers scheduled in hardware
  280. * @vbq: the capture am video buffer queue
  281. * @active_buf_cnt: number of video buffers scheduled in hardware
  282. * @buf_index: index for managing the output DMA buffers
  283. * @frame_count: the frame counter for statistics
  284. * @reqbufs_count: the number of buffers requested in REQBUFS ioctl
  285. * @input_index: input (camera sensor) index
  286. * @refcnt: driver's private reference counter
  287. * @input: capture input type, grp_id of the attached subdev
  288. * @user_subdev_api: true if subdevs are not configured by the host driver
  289. */
  290. struct fimc_vid_cap {
  291. struct fimc_ctx *ctx;
  292. struct vb2_alloc_ctx *alloc_ctx;
  293. struct video_device *vfd;
  294. struct v4l2_subdev subdev;
  295. struct media_pad vd_pad;
  296. struct v4l2_mbus_framefmt mf;
  297. struct media_pad sd_pads[FIMC_SD_PADS_NUM];
  298. struct list_head pending_buf_q;
  299. struct list_head active_buf_q;
  300. struct vb2_queue vbq;
  301. int active_buf_cnt;
  302. int buf_index;
  303. unsigned int frame_count;
  304. unsigned int reqbufs_count;
  305. int input_index;
  306. int refcnt;
  307. u32 input;
  308. bool user_subdev_api;
  309. };
  310. /**
  311. * struct fimc_pix_limit - image pixel size limits in various IP configurations
  312. *
  313. * @scaler_en_w: max input pixel width when the scaler is enabled
  314. * @scaler_dis_w: max input pixel width when the scaler is disabled
  315. * @in_rot_en_h: max input width with the input rotator is on
  316. * @in_rot_dis_w: max input width with the input rotator is off
  317. * @out_rot_en_w: max output width with the output rotator on
  318. * @out_rot_dis_w: max output width with the output rotator off
  319. */
  320. struct fimc_pix_limit {
  321. u16 scaler_en_w;
  322. u16 scaler_dis_w;
  323. u16 in_rot_en_h;
  324. u16 in_rot_dis_w;
  325. u16 out_rot_en_w;
  326. u16 out_rot_dis_w;
  327. };
  328. /**
  329. * struct samsung_fimc_variant - camera interface variant information
  330. *
  331. * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
  332. * @has_inp_rot: set if has input rotator
  333. * @has_out_rot: set if has output rotator
  334. * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision
  335. * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register
  336. * are present in this IP revision
  337. * @has_cam_if: set if this instance has a camera input interface
  338. * @pix_limit: pixel size constraints for the scaler
  339. * @min_inp_pixsize: minimum input pixel size
  340. * @min_out_pixsize: minimum output pixel size
  341. * @hor_offs_align: horizontal pixel offset aligment
  342. * @min_vsize_align: minimum vertical pixel size alignment
  343. * @out_buf_count: the number of buffers in output DMA sequence
  344. */
  345. struct samsung_fimc_variant {
  346. unsigned int pix_hoff:1;
  347. unsigned int has_inp_rot:1;
  348. unsigned int has_out_rot:1;
  349. unsigned int has_cistatus2:1;
  350. unsigned int has_mainscaler_ext:1;
  351. unsigned int has_cam_if:1;
  352. unsigned int has_alpha:1;
  353. struct fimc_pix_limit *pix_limit;
  354. u16 min_inp_pixsize;
  355. u16 min_out_pixsize;
  356. u16 hor_offs_align;
  357. u16 min_vsize_align;
  358. u16 out_buf_count;
  359. };
  360. /**
  361. * struct samsung_fimc_driverdata - per device type driver data for init time.
  362. *
  363. * @variant: the variant information for this driver.
  364. * @dev_cnt: number of fimc sub-devices available in SoC
  365. * @lclk_frequency: fimc bus clock frequency
  366. */
  367. struct samsung_fimc_driverdata {
  368. struct samsung_fimc_variant *variant[FIMC_MAX_DEVS];
  369. unsigned long lclk_frequency;
  370. int num_entities;
  371. };
  372. struct fimc_pipeline {
  373. struct media_pipeline *pipe;
  374. struct v4l2_subdev *sensor;
  375. struct v4l2_subdev *csis;
  376. };
  377. struct fimc_ctx;
  378. /**
  379. * struct fimc_dev - abstraction for FIMC entity
  380. * @slock: the spinlock protecting this data structure
  381. * @lock: the mutex protecting this data structure
  382. * @pdev: pointer to the FIMC platform device
  383. * @pdata: pointer to the device platform data
  384. * @variant: the IP variant information
  385. * @id: FIMC device index (0..FIMC_MAX_DEVS)
  386. * @clock: clocks required for FIMC operation
  387. * @regs: the mapped hardware registers
  388. * @irq_queue: interrupt handler waitqueue
  389. * @v4l2_dev: root v4l2_device
  390. * @m2m: memory-to-memory V4L2 device information
  391. * @vid_cap: camera capture device information
  392. * @state: flags used to synchronize m2m and capture mode operation
  393. * @alloc_ctx: videobuf2 memory allocator context
  394. * @pipeline: fimc video capture pipeline data structure
  395. */
  396. struct fimc_dev {
  397. spinlock_t slock;
  398. struct mutex lock;
  399. struct platform_device *pdev;
  400. struct s5p_platform_fimc *pdata;
  401. struct samsung_fimc_variant *variant;
  402. u16 id;
  403. struct clk *clock[MAX_FIMC_CLOCKS];
  404. void __iomem *regs;
  405. wait_queue_head_t irq_queue;
  406. struct v4l2_device *v4l2_dev;
  407. struct fimc_m2m_device m2m;
  408. struct fimc_vid_cap vid_cap;
  409. unsigned long state;
  410. struct vb2_alloc_ctx *alloc_ctx;
  411. struct fimc_pipeline pipeline;
  412. };
  413. /**
  414. * fimc_ctx - the device context data
  415. * @s_frame: source frame properties
  416. * @d_frame: destination frame properties
  417. * @out_order_1p: output 1-plane YCBCR order
  418. * @out_order_2p: output 2-plane YCBCR order
  419. * @in_order_1p input 1-plane YCBCR order
  420. * @in_order_2p: input 2-plane YCBCR order
  421. * @in_path: input mode (DMA or camera)
  422. * @out_path: output mode (DMA or FIFO)
  423. * @scaler: image scaler properties
  424. * @effect: image effect
  425. * @rotation: image clockwise rotation in degrees
  426. * @hflip: indicates image horizontal flip if set
  427. * @vflip: indicates image vertical flip if set
  428. * @flags: additional flags for image conversion
  429. * @state: flags to keep track of user configuration
  430. * @fimc_dev: the FIMC device this context applies to
  431. * @m2m_ctx: memory-to-memory device context
  432. * @fh: v4l2 file handle
  433. * @ctrl_handler: v4l2 controls handler
  434. * @ctrl_rotate image rotation control
  435. * @ctrl_hflip horizontal flip control
  436. * @ctrl_vflip vertical flip control
  437. * @ctrl_alpha RGB alpha control
  438. * @ctrls_rdy: true if the control handler is initialized
  439. */
  440. struct fimc_ctx {
  441. struct fimc_frame s_frame;
  442. struct fimc_frame d_frame;
  443. u32 out_order_1p;
  444. u32 out_order_2p;
  445. u32 in_order_1p;
  446. u32 in_order_2p;
  447. enum fimc_datapath in_path;
  448. enum fimc_datapath out_path;
  449. struct fimc_scaler scaler;
  450. struct fimc_effect effect;
  451. int rotation;
  452. unsigned int hflip:1;
  453. unsigned int vflip:1;
  454. u32 flags;
  455. u32 state;
  456. struct fimc_dev *fimc_dev;
  457. struct v4l2_m2m_ctx *m2m_ctx;
  458. struct v4l2_fh fh;
  459. struct v4l2_ctrl_handler ctrl_handler;
  460. struct v4l2_ctrl *ctrl_rotate;
  461. struct v4l2_ctrl *ctrl_hflip;
  462. struct v4l2_ctrl *ctrl_vflip;
  463. struct v4l2_ctrl *ctrl_alpha;
  464. bool ctrls_rdy;
  465. };
  466. #define fh_to_ctx(__fh) container_of(__fh, struct fimc_ctx, fh)
  467. static inline void set_frame_bounds(struct fimc_frame *f, u32 width, u32 height)
  468. {
  469. f->o_width = width;
  470. f->o_height = height;
  471. f->f_width = width;
  472. f->f_height = height;
  473. }
  474. static inline void set_frame_crop(struct fimc_frame *f,
  475. u32 left, u32 top, u32 width, u32 height)
  476. {
  477. f->offs_h = left;
  478. f->offs_v = top;
  479. f->width = width;
  480. f->height = height;
  481. }
  482. static inline u32 fimc_get_format_depth(struct fimc_fmt *ff)
  483. {
  484. u32 i, depth = 0;
  485. if (ff != NULL)
  486. for (i = 0; i < ff->colplanes; i++)
  487. depth += ff->depth[i];
  488. return depth;
  489. }
  490. static inline bool fimc_capture_active(struct fimc_dev *fimc)
  491. {
  492. unsigned long flags;
  493. bool ret;
  494. spin_lock_irqsave(&fimc->slock, flags);
  495. ret = !!(fimc->state & (1 << ST_CAPT_RUN) ||
  496. fimc->state & (1 << ST_CAPT_PEND));
  497. spin_unlock_irqrestore(&fimc->slock, flags);
  498. return ret;
  499. }
  500. static inline void fimc_ctx_state_set(u32 state, struct fimc_ctx *ctx)
  501. {
  502. unsigned long flags;
  503. spin_lock_irqsave(&ctx->fimc_dev->slock, flags);
  504. ctx->state |= state;
  505. spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags);
  506. }
  507. static inline bool fimc_ctx_state_is_set(u32 mask, struct fimc_ctx *ctx)
  508. {
  509. unsigned long flags;
  510. bool ret;
  511. spin_lock_irqsave(&ctx->fimc_dev->slock, flags);
  512. ret = (ctx->state & mask) == mask;
  513. spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags);
  514. return ret;
  515. }
  516. static inline int tiled_fmt(struct fimc_fmt *fmt)
  517. {
  518. return fmt->fourcc == V4L2_PIX_FMT_NV12MT;
  519. }
  520. /* Return the alpha component bit mask */
  521. static inline int fimc_get_alpha_mask(struct fimc_fmt *fmt)
  522. {
  523. switch (fmt->color) {
  524. case S5P_FIMC_RGB444: return 0x0f;
  525. case S5P_FIMC_RGB555: return 0x01;
  526. case S5P_FIMC_RGB888: return 0xff;
  527. default: return 0;
  528. };
  529. }
  530. static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
  531. enum v4l2_buf_type type)
  532. {
  533. struct fimc_frame *frame;
  534. if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) {
  535. if (fimc_ctx_state_is_set(FIMC_CTX_M2M, ctx))
  536. frame = &ctx->s_frame;
  537. else
  538. return ERR_PTR(-EINVAL);
  539. } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
  540. frame = &ctx->d_frame;
  541. } else {
  542. v4l2_err(ctx->fimc_dev->v4l2_dev,
  543. "Wrong buffer/video queue type (%d)\n", type);
  544. return ERR_PTR(-EINVAL);
  545. }
  546. return frame;
  547. }
  548. /* -----------------------------------------------------*/
  549. /* fimc-core.c */
  550. int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
  551. struct v4l2_fmtdesc *f);
  552. int fimc_ctrls_create(struct fimc_ctx *ctx);
  553. void fimc_ctrls_delete(struct fimc_ctx *ctx);
  554. void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
  555. void fimc_alpha_ctrl_update(struct fimc_ctx *ctx);
  556. int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f);
  557. void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
  558. struct v4l2_pix_format_mplane *pix);
  559. struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
  560. unsigned int mask, int index);
  561. struct fimc_fmt *fimc_get_format(unsigned int index);
  562. int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
  563. int dw, int dh, int rotation);
  564. int fimc_set_scaler_info(struct fimc_ctx *ctx);
  565. int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags);
  566. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  567. struct fimc_frame *frame, struct fimc_addr *paddr);
  568. void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f);
  569. void fimc_set_yuv_order(struct fimc_ctx *ctx);
  570. void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f);
  571. void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf);
  572. int fimc_register_m2m_device(struct fimc_dev *fimc,
  573. struct v4l2_device *v4l2_dev);
  574. void fimc_unregister_m2m_device(struct fimc_dev *fimc);
  575. int fimc_register_driver(void);
  576. void fimc_unregister_driver(void);
  577. /* -----------------------------------------------------*/
  578. /* fimc-m2m.c */
  579. void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state);
  580. /* -----------------------------------------------------*/
  581. /* fimc-capture.c */
  582. int fimc_initialize_capture_subdev(struct fimc_dev *fimc);
  583. void fimc_unregister_capture_subdev(struct fimc_dev *fimc);
  584. int fimc_capture_ctrls_create(struct fimc_dev *fimc);
  585. void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
  586. void *arg);
  587. int fimc_capture_suspend(struct fimc_dev *fimc);
  588. int fimc_capture_resume(struct fimc_dev *fimc);
  589. /*
  590. * Buffer list manipulation functions. Must be called with fimc.slock held.
  591. */
  592. /**
  593. * fimc_active_queue_add - add buffer to the capture active buffers queue
  594. * @buf: buffer to add to the active buffers list
  595. */
  596. static inline void fimc_active_queue_add(struct fimc_vid_cap *vid_cap,
  597. struct fimc_vid_buffer *buf)
  598. {
  599. list_add_tail(&buf->list, &vid_cap->active_buf_q);
  600. vid_cap->active_buf_cnt++;
  601. }
  602. /**
  603. * fimc_active_queue_pop - pop buffer from the capture active buffers queue
  604. *
  605. * The caller must assure the active_buf_q list is not empty.
  606. */
  607. static inline struct fimc_vid_buffer *fimc_active_queue_pop(
  608. struct fimc_vid_cap *vid_cap)
  609. {
  610. struct fimc_vid_buffer *buf;
  611. buf = list_entry(vid_cap->active_buf_q.next,
  612. struct fimc_vid_buffer, list);
  613. list_del(&buf->list);
  614. vid_cap->active_buf_cnt--;
  615. return buf;
  616. }
  617. /**
  618. * fimc_pending_queue_add - add buffer to the capture pending buffers queue
  619. * @buf: buffer to add to the pending buffers list
  620. */
  621. static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap,
  622. struct fimc_vid_buffer *buf)
  623. {
  624. list_add_tail(&buf->list, &vid_cap->pending_buf_q);
  625. }
  626. /**
  627. * fimc_pending_queue_pop - pop buffer from the capture pending buffers queue
  628. *
  629. * The caller must assure the pending_buf_q list is not empty.
  630. */
  631. static inline struct fimc_vid_buffer *fimc_pending_queue_pop(
  632. struct fimc_vid_cap *vid_cap)
  633. {
  634. struct fimc_vid_buffer *buf;
  635. buf = list_entry(vid_cap->pending_buf_q.next,
  636. struct fimc_vid_buffer, list);
  637. list_del(&buf->list);
  638. return buf;
  639. }
  640. #endif /* FIMC_CORE_H_ */