fimc-core.h 21 KB

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