fimc-core.h 21 KB

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