fimc-core.h 20 KB

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