fimc-core.h 20 KB

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