fimc-core.h 22 KB

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