fimc-core.h 24 KB

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