fimc-core.h 20 KB

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