fimc-core.h 21 KB

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