fimc-core.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Copyright (c) 2010 Samsung Electronics
  3. *
  4. * Sylwester Nawrocki, <s.nawrocki@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef FIMC_CORE_H_
  11. #define FIMC_CORE_H_
  12. /*#define DEBUG*/
  13. #include <linux/sched.h>
  14. #include <linux/types.h>
  15. #include <linux/videodev2.h>
  16. #include <linux/io.h>
  17. #include <media/videobuf2-core.h>
  18. #include <media/v4l2-device.h>
  19. #include <media/v4l2-mem2mem.h>
  20. #include <media/v4l2-mediabus.h>
  21. #include <media/s5p_fimc.h>
  22. #include "regs-fimc.h"
  23. #define err(fmt, args...) \
  24. printk(KERN_ERR "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
  25. #ifdef DEBUG
  26. #define dbg(fmt, args...) \
  27. printk(KERN_DEBUG "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
  28. #else
  29. #define dbg(fmt, args...)
  30. #endif
  31. /* Time to wait for next frame VSYNC interrupt while stopping operation. */
  32. #define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000)
  33. #define MAX_FIMC_CLOCKS 3
  34. #define MODULE_NAME "s5p-fimc"
  35. #define FIMC_MAX_DEVS 4
  36. #define FIMC_MAX_OUT_BUFS 4
  37. #define SCALER_MAX_HRATIO 64
  38. #define SCALER_MAX_VRATIO 64
  39. #define DMA_MIN_SIZE 8
  40. /* indices to the clocks array */
  41. enum {
  42. CLK_BUS,
  43. CLK_GATE,
  44. CLK_CAM,
  45. };
  46. enum fimc_dev_flags {
  47. /* for m2m node */
  48. ST_IDLE,
  49. ST_OUTDMA_RUN,
  50. ST_M2M_PEND,
  51. /* for capture node */
  52. ST_CAPT_PEND,
  53. ST_CAPT_RUN,
  54. ST_CAPT_STREAM,
  55. ST_CAPT_SHUT,
  56. };
  57. #define fimc_m2m_active(dev) test_bit(ST_OUTDMA_RUN, &(dev)->state)
  58. #define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
  59. #define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state)
  60. #define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state)
  61. #define fimc_capture_active(dev) \
  62. (test_bit(ST_CAPT_RUN, &(dev)->state) || \
  63. test_bit(ST_CAPT_PEND, &(dev)->state))
  64. #define fimc_capture_streaming(dev) \
  65. test_bit(ST_CAPT_STREAM, &(dev)->state)
  66. enum fimc_datapath {
  67. FIMC_CAMERA,
  68. FIMC_DMA,
  69. FIMC_LCDFIFO,
  70. FIMC_WRITEBACK
  71. };
  72. enum fimc_color_fmt {
  73. S5P_FIMC_RGB565 = 0x10,
  74. S5P_FIMC_RGB666,
  75. S5P_FIMC_RGB888,
  76. S5P_FIMC_RGB30_LOCAL,
  77. S5P_FIMC_YCBCR420 = 0x20,
  78. S5P_FIMC_YCBYCR422,
  79. S5P_FIMC_YCRYCB422,
  80. S5P_FIMC_CBYCRY422,
  81. S5P_FIMC_CRYCBY422,
  82. S5P_FIMC_YCBCR444_LOCAL,
  83. };
  84. #define fimc_fmt_is_rgb(x) ((x) & 0x10)
  85. /* Cb/Cr chrominance components order for 2 plane Y/CbCr 4:2:2 formats. */
  86. #define S5P_FIMC_LSB_CRCB S5P_CIOCTRL_ORDER422_2P_LSB_CRCB
  87. /* The embedded image effect selection */
  88. #define S5P_FIMC_EFFECT_ORIGINAL S5P_CIIMGEFF_FIN_BYPASS
  89. #define S5P_FIMC_EFFECT_ARBITRARY S5P_CIIMGEFF_FIN_ARBITRARY
  90. #define S5P_FIMC_EFFECT_NEGATIVE S5P_CIIMGEFF_FIN_NEGATIVE
  91. #define S5P_FIMC_EFFECT_ARTFREEZE S5P_CIIMGEFF_FIN_ARTFREEZE
  92. #define S5P_FIMC_EFFECT_EMBOSSING S5P_CIIMGEFF_FIN_EMBOSSING
  93. #define S5P_FIMC_EFFECT_SIKHOUETTE S5P_CIIMGEFF_FIN_SILHOUETTE
  94. /* The hardware context state. */
  95. #define FIMC_PARAMS (1 << 0)
  96. #define FIMC_SRC_ADDR (1 << 1)
  97. #define FIMC_DST_ADDR (1 << 2)
  98. #define FIMC_SRC_FMT (1 << 3)
  99. #define FIMC_DST_FMT (1 << 4)
  100. #define FIMC_CTX_M2M (1 << 5)
  101. #define FIMC_CTX_CAP (1 << 6)
  102. /* Image conversion flags */
  103. #define FIMC_IN_DMA_ACCESS_TILED (1 << 0)
  104. #define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0)
  105. #define FIMC_OUT_DMA_ACCESS_TILED (1 << 1)
  106. #define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1)
  107. #define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2)
  108. #define FIMC_SCAN_MODE_INTERLACED (1 << 2)
  109. /*
  110. * YCbCr data dynamic range for RGB-YUV color conversion.
  111. * Y/Cb/Cr: (0 ~ 255) */
  112. #define FIMC_COLOR_RANGE_WIDE (0 << 3)
  113. /* Y (16 ~ 235), Cb/Cr (16 ~ 240) */
  114. #define FIMC_COLOR_RANGE_NARROW (1 << 3)
  115. #define FLIP_NONE 0
  116. #define FLIP_X_AXIS 1
  117. #define FLIP_Y_AXIS 2
  118. #define FLIP_XY_AXIS (FLIP_X_AXIS | FLIP_Y_AXIS)
  119. /**
  120. * struct fimc_fmt - the driver's internal color format data
  121. * @mbus_code: Media Bus pixel code, -1 if not applicable
  122. * @name: format description
  123. * @fourcc: the fourcc code for this format, 0 if not applicable
  124. * @color: the corresponding fimc_color_fmt
  125. * @depth: per plane driver's private 'number of bits per pixel'
  126. * @memplanes: number of physically non-contiguous data planes
  127. * @colplanes: number of physically contiguous data planes
  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 (1 << 1)
  140. };
  141. /**
  142. * struct fimc_dma_offset - pixel offset information for DMA
  143. * @y_h: y value horizontal offset
  144. * @y_v: y value vertical offset
  145. * @cb_h: cb value horizontal offset
  146. * @cb_v: cb value vertical offset
  147. * @cr_h: cr value horizontal offset
  148. * @cr_v: cr value vertical offset
  149. */
  150. struct fimc_dma_offset {
  151. int y_h;
  152. int y_v;
  153. int cb_h;
  154. int cb_v;
  155. int cr_h;
  156. int cr_v;
  157. };
  158. /**
  159. * struct fimc_effect - the configuration data for the "Arbitrary" image effect
  160. * @type: effect type
  161. * @pat_cb: cr value when type is "arbitrary"
  162. * @pat_cr: cr value when type is "arbitrary"
  163. */
  164. struct fimc_effect {
  165. u32 type;
  166. u8 pat_cb;
  167. u8 pat_cr;
  168. };
  169. /**
  170. * struct fimc_scaler - the configuration data for FIMC inetrnal scaler
  171. *
  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. *
  207. * @y: luminance plane physical address
  208. * @cb: Cb plane physical address
  209. * @cr: Cr plane physical address
  210. */
  211. struct fimc_addr {
  212. u32 y;
  213. u32 cb;
  214. u32 cr;
  215. };
  216. /**
  217. * struct fimc_vid_buffer - the driver's video buffer
  218. * @vb: v4l videobuf buffer
  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. * @paddr: image frame buffer physical addresses
  239. * @buf_cnt: number of buffers depending on a color format
  240. * @payload: image size in bytes (w x h x bpp)
  241. * @color: color format
  242. * @dma_offset: DMA offset in bytes
  243. */
  244. struct fimc_frame {
  245. u32 f_width;
  246. u32 f_height;
  247. u32 o_width;
  248. u32 o_height;
  249. u32 offs_h;
  250. u32 offs_v;
  251. u32 width;
  252. u32 height;
  253. unsigned long payload[VIDEO_MAX_PLANES];
  254. struct fimc_addr paddr;
  255. struct fimc_dma_offset dma_offset;
  256. struct fimc_fmt *fmt;
  257. };
  258. /**
  259. * struct fimc_m2m_device - v4l2 memory-to-memory device data
  260. * @vfd: the video device node for v4l2 m2m mode
  261. * @v4l2_dev: v4l2 device for m2m mode
  262. * @m2m_dev: v4l2 memory-to-memory device data
  263. * @ctx: hardware context data
  264. * @refcnt: the reference counter
  265. */
  266. struct fimc_m2m_device {
  267. struct video_device *vfd;
  268. struct v4l2_device v4l2_dev;
  269. struct v4l2_m2m_dev *m2m_dev;
  270. struct fimc_ctx *ctx;
  271. int refcnt;
  272. };
  273. /**
  274. * struct fimc_vid_cap - camera capture device information
  275. * @ctx: hardware context data
  276. * @vfd: video device node for camera capture mode
  277. * @v4l2_dev: v4l2_device struct to manage subdevs
  278. * @sd: pointer to camera sensor subdevice currently in use
  279. * @fmt: Media Bus format configured at selected image sensor
  280. * @pending_buf_q: the pending buffer queue head
  281. * @active_buf_q: the queue head of buffers scheduled in hardware
  282. * @vbq: the capture am video buffer queue
  283. * @active_buf_cnt: number of video buffers scheduled in hardware
  284. * @buf_index: index for managing the output DMA buffers
  285. * @frame_count: the frame counter for statistics
  286. * @reqbufs_count: the number of buffers requested in REQBUFS ioctl
  287. * @input_index: input (camera sensor) index
  288. * @refcnt: driver's private reference counter
  289. */
  290. struct fimc_vid_cap {
  291. struct fimc_ctx *ctx;
  292. struct vb2_alloc_ctx *alloc_ctx;
  293. struct video_device *vfd;
  294. struct v4l2_device v4l2_dev;
  295. struct v4l2_subdev *sd;;
  296. struct v4l2_mbus_framefmt fmt;
  297. struct list_head pending_buf_q;
  298. struct list_head active_buf_q;
  299. struct vb2_queue vbq;
  300. int active_buf_cnt;
  301. int buf_index;
  302. unsigned int frame_count;
  303. unsigned int reqbufs_count;
  304. int input_index;
  305. int refcnt;
  306. };
  307. /**
  308. * struct fimc_pix_limit - image pixel size limits in various IP configurations
  309. *
  310. * @scaler_en_w: max input pixel width when the scaler is enabled
  311. * @scaler_dis_w: max input pixel width when the scaler is disabled
  312. * @in_rot_en_h: max input width with the input rotator is on
  313. * @in_rot_dis_w: max input width with the input rotator is off
  314. * @out_rot_en_w: max output width with the output rotator on
  315. * @out_rot_dis_w: max output width with the output rotator off
  316. */
  317. struct fimc_pix_limit {
  318. u16 scaler_en_w;
  319. u16 scaler_dis_w;
  320. u16 in_rot_en_h;
  321. u16 in_rot_dis_w;
  322. u16 out_rot_en_w;
  323. u16 out_rot_dis_w;
  324. };
  325. /**
  326. * struct samsung_fimc_variant - camera interface variant information
  327. *
  328. * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
  329. * @has_inp_rot: set if has input rotator
  330. * @has_out_rot: set if has output rotator
  331. * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision
  332. * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register
  333. * are present in this IP revision
  334. * @pix_limit: pixel size constraints for the scaler
  335. * @min_inp_pixsize: minimum input pixel size
  336. * @min_out_pixsize: minimum output pixel size
  337. * @hor_offs_align: horizontal pixel offset aligment
  338. * @out_buf_count: the number of buffers in output DMA sequence
  339. */
  340. struct samsung_fimc_variant {
  341. unsigned int pix_hoff:1;
  342. unsigned int has_inp_rot:1;
  343. unsigned int has_out_rot:1;
  344. unsigned int has_cistatus2:1;
  345. unsigned int has_mainscaler_ext:1;
  346. struct fimc_pix_limit *pix_limit;
  347. u16 min_inp_pixsize;
  348. u16 min_out_pixsize;
  349. u16 hor_offs_align;
  350. u16 out_buf_count;
  351. };
  352. /**
  353. * struct samsung_fimc_driverdata - per device type driver data for init time.
  354. *
  355. * @variant: the variant information for this driver.
  356. * @dev_cnt: number of fimc sub-devices available in SoC
  357. * @lclk_frequency: fimc bus clock frequency
  358. */
  359. struct samsung_fimc_driverdata {
  360. struct samsung_fimc_variant *variant[FIMC_MAX_DEVS];
  361. unsigned long lclk_frequency;
  362. int num_entities;
  363. };
  364. struct fimc_ctx;
  365. /**
  366. * struct fimc_dev - abstraction for FIMC entity
  367. *
  368. * @slock: the spinlock protecting this data structure
  369. * @lock: the mutex protecting this data structure
  370. * @pdev: pointer to the FIMC platform device
  371. * @pdata: pointer to the device platform data
  372. * @id: FIMC device index (0..FIMC_MAX_DEVS)
  373. * @num_clocks: the number of clocks managed by this device instance
  374. * @clock[]: the clocks required for FIMC operation
  375. * @regs: the mapped hardware registers
  376. * @regs_res: the resource claimed for IO registers
  377. * @irq: interrupt number of the FIMC subdevice
  378. * @irq_queue:
  379. * @m2m: memory-to-memory V4L2 device information
  380. * @vid_cap: camera capture device information
  381. * @state: flags used to synchronize m2m and capture mode operation
  382. */
  383. struct fimc_dev {
  384. spinlock_t slock;
  385. struct mutex lock;
  386. struct platform_device *pdev;
  387. struct s5p_platform_fimc *pdata;
  388. struct samsung_fimc_variant *variant;
  389. u16 id;
  390. u16 num_clocks;
  391. struct clk *clock[MAX_FIMC_CLOCKS];
  392. void __iomem *regs;
  393. struct resource *regs_res;
  394. int irq;
  395. wait_queue_head_t irq_queue;
  396. struct fimc_m2m_device m2m;
  397. struct fimc_vid_cap vid_cap;
  398. unsigned long state;
  399. struct vb2_alloc_ctx *alloc_ctx;
  400. };
  401. /**
  402. * fimc_ctx - the device context data
  403. *
  404. * @lock: mutex protecting this data structure
  405. * @s_frame: source frame properties
  406. * @d_frame: destination frame properties
  407. * @out_order_1p: output 1-plane YCBCR order
  408. * @out_order_2p: output 2-plane YCBCR order
  409. * @in_order_1p input 1-plane YCBCR order
  410. * @in_order_2p: input 2-plane YCBCR order
  411. * @in_path: input mode (DMA or camera)
  412. * @out_path: output mode (DMA or FIFO)
  413. * @scaler: image scaler properties
  414. * @effect: image effect
  415. * @rotation: image clockwise rotation in degrees
  416. * @flip: image flip mode
  417. * @flags: additional flags for image conversion
  418. * @state: flags to keep track of user configuration
  419. * @fimc_dev: the FIMC device this context applies to
  420. * @m2m_ctx: memory-to-memory device context
  421. */
  422. struct fimc_ctx {
  423. spinlock_t slock;
  424. struct fimc_frame s_frame;
  425. struct fimc_frame d_frame;
  426. u32 out_order_1p;
  427. u32 out_order_2p;
  428. u32 in_order_1p;
  429. u32 in_order_2p;
  430. enum fimc_datapath in_path;
  431. enum fimc_datapath out_path;
  432. struct fimc_scaler scaler;
  433. struct fimc_effect effect;
  434. int rotation;
  435. u32 flip;
  436. u32 flags;
  437. u32 state;
  438. struct fimc_dev *fimc_dev;
  439. struct v4l2_m2m_ctx *m2m_ctx;
  440. };
  441. static inline int tiled_fmt(struct fimc_fmt *fmt)
  442. {
  443. return fmt->fourcc == V4L2_PIX_FMT_NV12MT;
  444. }
  445. static inline void fimc_hw_clear_irq(struct fimc_dev *dev)
  446. {
  447. u32 cfg = readl(dev->regs + S5P_CIGCTRL);
  448. cfg |= S5P_CIGCTRL_IRQ_CLR;
  449. writel(cfg, dev->regs + S5P_CIGCTRL);
  450. }
  451. static inline void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on)
  452. {
  453. u32 cfg = readl(dev->regs + S5P_CISCCTRL);
  454. if (on)
  455. cfg |= S5P_CISCCTRL_SCALERSTART;
  456. else
  457. cfg &= ~S5P_CISCCTRL_SCALERSTART;
  458. writel(cfg, dev->regs + S5P_CISCCTRL);
  459. }
  460. static inline void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on)
  461. {
  462. u32 cfg = readl(dev->regs + S5P_MSCTRL);
  463. if (on)
  464. cfg |= S5P_MSCTRL_ENVID;
  465. else
  466. cfg &= ~S5P_MSCTRL_ENVID;
  467. writel(cfg, dev->regs + S5P_MSCTRL);
  468. }
  469. static inline void fimc_hw_dis_capture(struct fimc_dev *dev)
  470. {
  471. u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
  472. cfg &= ~(S5P_CIIMGCPT_IMGCPTEN | S5P_CIIMGCPT_IMGCPTEN_SC);
  473. writel(cfg, dev->regs + S5P_CIIMGCPT);
  474. }
  475. /**
  476. * fimc_hw_set_dma_seq - configure output DMA buffer sequence
  477. * @mask: each bit corresponds to one of 32 output buffer registers set
  478. * 1 to include buffer in the sequence, 0 to disable
  479. *
  480. * This function mask output DMA ring buffers, i.e. it allows to configure
  481. * which of the output buffer address registers will be used by the DMA
  482. * engine.
  483. */
  484. static inline void fimc_hw_set_dma_seq(struct fimc_dev *dev, u32 mask)
  485. {
  486. writel(mask, dev->regs + S5P_CIFCNTSEQ);
  487. }
  488. static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
  489. enum v4l2_buf_type type)
  490. {
  491. struct fimc_frame *frame;
  492. if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) {
  493. if (ctx->state & FIMC_CTX_M2M)
  494. frame = &ctx->s_frame;
  495. else
  496. return ERR_PTR(-EINVAL);
  497. } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
  498. frame = &ctx->d_frame;
  499. } else {
  500. v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
  501. "Wrong buffer/video queue type (%d)\n", type);
  502. return ERR_PTR(-EINVAL);
  503. }
  504. return frame;
  505. }
  506. /* Return an index to the buffer actually being written. */
  507. static inline u32 fimc_hw_get_frame_index(struct fimc_dev *dev)
  508. {
  509. u32 reg;
  510. if (dev->variant->has_cistatus2) {
  511. reg = readl(dev->regs + S5P_CISTATUS2) & 0x3F;
  512. return reg > 0 ? --reg : reg;
  513. } else {
  514. reg = readl(dev->regs + S5P_CISTATUS);
  515. return (reg & S5P_CISTATUS_FRAMECNT_MASK) >>
  516. S5P_CISTATUS_FRAMECNT_SHIFT;
  517. }
  518. }
  519. /* -----------------------------------------------------*/
  520. /* fimc-reg.c */
  521. void fimc_hw_reset(struct fimc_dev *fimc);
  522. void fimc_hw_set_rotation(struct fimc_ctx *ctx);
  523. void fimc_hw_set_target_format(struct fimc_ctx *ctx);
  524. void fimc_hw_set_out_dma(struct fimc_ctx *ctx);
  525. void fimc_hw_en_lastirq(struct fimc_dev *fimc, int enable);
  526. void fimc_hw_en_irq(struct fimc_dev *fimc, int enable);
  527. void fimc_hw_set_prescaler(struct fimc_ctx *ctx);
  528. void fimc_hw_set_mainscaler(struct fimc_ctx *ctx);
  529. void fimc_hw_en_capture(struct fimc_ctx *ctx);
  530. void fimc_hw_set_effect(struct fimc_ctx *ctx);
  531. void fimc_hw_set_in_dma(struct fimc_ctx *ctx);
  532. void fimc_hw_set_input_path(struct fimc_ctx *ctx);
  533. void fimc_hw_set_output_path(struct fimc_ctx *ctx);
  534. void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *paddr);
  535. void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr,
  536. int index);
  537. int fimc_hw_set_camera_source(struct fimc_dev *fimc,
  538. struct s5p_fimc_isp_info *cam);
  539. int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f);
  540. int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
  541. struct s5p_fimc_isp_info *cam);
  542. int fimc_hw_set_camera_type(struct fimc_dev *fimc,
  543. struct s5p_fimc_isp_info *cam);
  544. /* -----------------------------------------------------*/
  545. /* fimc-core.c */
  546. int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
  547. struct v4l2_fmtdesc *f);
  548. int fimc_vidioc_g_fmt_mplane(struct file *file, void *priv,
  549. struct v4l2_format *f);
  550. int fimc_vidioc_try_fmt_mplane(struct file *file, void *priv,
  551. struct v4l2_format *f);
  552. int fimc_vidioc_queryctrl(struct file *file, void *priv,
  553. struct v4l2_queryctrl *qc);
  554. int fimc_vidioc_g_ctrl(struct file *file, void *priv,
  555. struct v4l2_control *ctrl);
  556. int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr);
  557. int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl);
  558. int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl);
  559. struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask);
  560. struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f,
  561. unsigned int mask);
  562. int fimc_check_scaler_ratio(int sw, int sh, int dw, int dh, int rot);
  563. int fimc_set_scaler_info(struct fimc_ctx *ctx);
  564. int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags);
  565. int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
  566. struct fimc_frame *frame, struct fimc_addr *paddr);
  567. /* -----------------------------------------------------*/
  568. /* fimc-capture.c */
  569. int fimc_register_capture_device(struct fimc_dev *fimc);
  570. void fimc_unregister_capture_device(struct fimc_dev *fimc);
  571. int fimc_sensor_sd_init(struct fimc_dev *fimc, int index);
  572. int fimc_vid_cap_buf_queue(struct fimc_dev *fimc,
  573. struct fimc_vid_buffer *fimc_vb);
  574. /* Locking: the caller holds fimc->slock */
  575. static inline void fimc_activate_capture(struct fimc_ctx *ctx)
  576. {
  577. fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled);
  578. fimc_hw_en_capture(ctx);
  579. }
  580. static inline void fimc_deactivate_capture(struct fimc_dev *fimc)
  581. {
  582. fimc_hw_en_lastirq(fimc, true);
  583. fimc_hw_dis_capture(fimc);
  584. fimc_hw_enable_scaler(fimc, false);
  585. fimc_hw_en_lastirq(fimc, false);
  586. }
  587. /*
  588. * Add buf to the capture active buffers queue.
  589. * Locking: Need to be called with fimc_dev::slock held.
  590. */
  591. static inline void active_queue_add(struct fimc_vid_cap *vid_cap,
  592. struct fimc_vid_buffer *buf)
  593. {
  594. list_add_tail(&buf->list, &vid_cap->active_buf_q);
  595. vid_cap->active_buf_cnt++;
  596. }
  597. /*
  598. * Pop a video buffer from the capture active buffers queue
  599. * Locking: Need to be called with fimc_dev::slock held.
  600. */
  601. static inline struct fimc_vid_buffer *
  602. active_queue_pop(struct fimc_vid_cap *vid_cap)
  603. {
  604. struct fimc_vid_buffer *buf;
  605. buf = list_entry(vid_cap->active_buf_q.next,
  606. struct fimc_vid_buffer, list);
  607. list_del(&buf->list);
  608. vid_cap->active_buf_cnt--;
  609. return buf;
  610. }
  611. /* Add video buffer to the capture pending buffers queue */
  612. static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap,
  613. struct fimc_vid_buffer *buf)
  614. {
  615. list_add_tail(&buf->list, &vid_cap->pending_buf_q);
  616. }
  617. /* Add video buffer to the capture pending buffers queue */
  618. static inline struct fimc_vid_buffer *
  619. pending_queue_pop(struct fimc_vid_cap *vid_cap)
  620. {
  621. struct fimc_vid_buffer *buf;
  622. buf = list_entry(vid_cap->pending_buf_q.next,
  623. struct fimc_vid_buffer, list);
  624. list_del(&buf->list);
  625. return buf;
  626. }
  627. #endif /* FIMC_CORE_H_ */