fimc-core.h 20 KB

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