PageRenderTime 52ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/media/platform/exynos/fimg2d/fimg2d.h

https://gitlab.com/SerenityS/slteskt_kernel
C Header | 612 lines | 399 code | 68 blank | 145 comment | 16 complexity | f65045e8e2abefac89d42606b1be4e39 MD5 | raw file
  1. /* linux/drivers/media/video/exynos/fimg2d/fimg2d.h
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com/
  5. *
  6. * Samsung Graphics 2D driver
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __FIMG2D_H
  13. #define __FIMG2D_H __FILE__
  14. #ifdef __KERNEL__
  15. #include <linux/clk.h>
  16. #include <linux/list.h>
  17. #include <linux/device.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/atomic.h>
  21. #include <linux/mutex.h>
  22. #include <linux/pm_qos.h>
  23. #include <plat/fimg2d.h>
  24. #define FIMG2D_MINOR (240)
  25. #define to_fimg2d_plat(d) (to_platform_device(d)->dev.platform_data)
  26. #define ip_is_g2d_5a() (fimg2d_ip_version_is() == IP_VER_G2D_5A)
  27. #define ip_is_g2d_5ar() (fimg2d_ip_version_is() == IP_VER_G2D_5AR)
  28. #define ip_is_g2d_5ar2() (fimg2d_ip_version_is() == IP_VER_G2D_5AR2)
  29. #define ip_is_g2d_5r() (fimg2d_ip_version_is() == IP_VER_G2D_5R)
  30. #define ip_is_g2d_5v() (fimg2d_ip_version_is() == IP_VER_G2D_5V)
  31. #define ip_is_g2d_5h() (fimg2d_ip_version_is() == IP_VER_G2D_5H)
  32. #define ip_is_g2d_5hp() (fimg2d_ip_version_is() == IP_VER_G2D_5HP)
  33. #define ip_is_g2d_5g() (fimg2d_ip_version_is() == IP_VER_G2D_5G)
  34. #define ip_is_g2d_4p() (fimg2d_ip_version_is() == IP_VER_G2D_4P)
  35. #ifdef DEBUG
  36. /*
  37. * g2d_debug value:
  38. * 0: no print
  39. * 1: err
  40. * 2: info
  41. * 3: perf
  42. * 4: oneline (simple)
  43. * 5: debug
  44. */
  45. extern int g2d_debug;
  46. enum debug_level {
  47. DBG_NO,
  48. DBG_ERR,
  49. DBG_INFO,
  50. DBG_PERF,
  51. DBG_ONELINE,
  52. DBG_DEBUG,
  53. };
  54. #define g2d_print(level, fmt, args...) \
  55. do { \
  56. if (g2d_debug >= level) \
  57. pr_info("[%s] " fmt, __func__, ##args); \
  58. } while (0)
  59. #define fimg2d_err(fmt, args...) g2d_print(DBG_ERR, fmt, ##args)
  60. #define fimg2d_info(fmt, args...) g2d_print(DBG_INFO, fmt, ##args)
  61. #define fimg2d_debug(fmt, args...) g2d_print(DBG_DEBUG, fmt, ##args)
  62. #else
  63. #define g2d_print(level, fmt, args...)
  64. #define fimg2d_err(fmt, args...)
  65. #define fimg2d_info(fmt, args...)
  66. #define fimg2d_debug(fmt, arg...)
  67. #endif
  68. #endif /* __KERNEL__ */
  69. /* ioctl commands */
  70. #define FIMG2D_IOCTL_MAGIC 'F'
  71. #define FIMG2D_BITBLT_BLIT _IOWR(FIMG2D_IOCTL_MAGIC, 0, struct fimg2d_blit)
  72. #define FIMG2D_BITBLT_SYNC _IOW(FIMG2D_IOCTL_MAGIC, 1, int)
  73. #define FIMG2D_BITBLT_VERSION _IOR(FIMG2D_IOCTL_MAGIC, 2, struct fimg2d_version)
  74. #define FIMG2D_BITBLT_ACTIVATE _IOW(FIMG2D_IOCTL_MAGIC, 3, enum driver_act)
  75. enum fimg2d_qos_status {
  76. FIMG2D_QOS_ON = 0,
  77. FIMG2D_QOS_OFF
  78. };
  79. enum fimg2d_qos_level {
  80. G2D_LV0 = 0,
  81. G2D_LV1,
  82. G2D_LV2,
  83. G2D_LV3,
  84. G2D_LV4,
  85. G2D_LV_END
  86. };
  87. enum fimg2d_ctx_state {
  88. CTX_READY = 0,
  89. CTX_ERROR,
  90. };
  91. enum fimg2d_pw_status {
  92. FIMG2D_PW_ON = 0,
  93. FIMG2D_PW_OFF
  94. };
  95. enum driver_act {
  96. DRV_ACT = 0,
  97. DRV_DEACT
  98. };
  99. struct fimg2d_version {
  100. unsigned int hw;
  101. unsigned int sw;
  102. };
  103. /**
  104. * @BLIT_SYNC: sync mode, to wait for blit done irq
  105. * @BLIT_ASYNC: async mode, not to wait for blit done irq
  106. */
  107. enum blit_sync {
  108. BLIT_SYNC,
  109. BLIT_ASYNC,
  110. };
  111. /**
  112. * @ADDR_PHYS: physical address
  113. * @ADDR_USER: user virtual address (physically Non-contiguous)
  114. * @ADDR_USER_CONTIG: user virtual address (physically Contiguous)
  115. * @ADDR_DEVICE: specific device virtual address
  116. */
  117. enum addr_space {
  118. ADDR_NONE,
  119. ADDR_PHYS,
  120. ADDR_KERN,
  121. ADDR_USER,
  122. ADDR_USER_CONTIG,
  123. ADDR_DEVICE,
  124. };
  125. /**
  126. * Pixel order complies with little-endian style
  127. *
  128. * DO NOT CHANGE THIS ORDER
  129. */
  130. enum pixel_order {
  131. AX_RGB = 0,
  132. RGB_AX,
  133. AX_BGR,
  134. BGR_AX,
  135. ARGB_ORDER_END,
  136. P1_CRY1CBY0,
  137. P1_CBY1CRY0,
  138. P1_Y1CRY0CB,
  139. P1_Y1CBY0CR,
  140. P1_ORDER_END,
  141. P2_CRCB,
  142. P2_CBCR,
  143. P2_ORDER_END,
  144. };
  145. /**
  146. * DO NOT CHANGE THIS ORDER
  147. */
  148. enum color_format {
  149. CF_XRGB_8888 = 0,
  150. CF_ARGB_8888,
  151. CF_RGB_565,
  152. CF_XRGB_1555,
  153. CF_ARGB_1555,
  154. CF_XRGB_4444,
  155. CF_ARGB_4444,
  156. CF_RGB_888,
  157. CF_YCBCR_444,
  158. CF_YCBCR_422,
  159. CF_YCBCR_420,
  160. CF_A8,
  161. CF_L8,
  162. SRC_DST_FORMAT_END,
  163. CF_MSK_1BIT,
  164. CF_MSK_4BIT,
  165. CF_MSK_8BIT,
  166. CF_MSK_16BIT_565,
  167. CF_MSK_16BIT_1555,
  168. CF_MSK_16BIT_4444,
  169. CF_MSK_32BIT_8888,
  170. MSK_FORMAT_END,
  171. };
  172. enum rotation {
  173. ORIGIN,
  174. ROT_90, /* clockwise */
  175. ROT_180,
  176. ROT_270,
  177. XFLIP, /* x-axis flip */
  178. YFLIP, /* y-axis flip */
  179. };
  180. /**
  181. * @NO_REPEAT: no effect
  182. * @REPEAT_NORMAL: repeat horizontally and vertically
  183. * @REPEAT_PAD: pad with pad color
  184. * @REPEAT_REFLECT: reflect horizontally and vertically
  185. * @REPEAT_CLAMP: pad with edge color of original image
  186. *
  187. * DO NOT CHANGE THIS ORDER
  188. */
  189. enum repeat {
  190. NO_REPEAT = 0,
  191. REPEAT_NORMAL, /* default setting */
  192. REPEAT_PAD,
  193. REPEAT_REFLECT, REPEAT_MIRROR = REPEAT_REFLECT,
  194. REPEAT_CLAMP,
  195. };
  196. enum scaling {
  197. NO_SCALING,
  198. SCALING_NEAREST,
  199. SCALING_BILINEAR,
  200. };
  201. /**
  202. * premultiplied alpha
  203. */
  204. enum premultiplied {
  205. PREMULTIPLIED,
  206. NON_PREMULTIPLIED,
  207. };
  208. /**
  209. * @TRANSP: discard bluescreen color
  210. * @BLUSCR: replace bluescreen color with background color
  211. */
  212. enum bluescreen {
  213. OPAQUE,
  214. TRANSP,
  215. BLUSCR,
  216. };
  217. /**
  218. * DO NOT CHANGE THIS ORDER
  219. */
  220. enum blit_op {
  221. BLIT_OP_SOLID_FILL = 0,
  222. BLIT_OP_CLR,
  223. BLIT_OP_SRC, BLIT_OP_SRC_COPY = BLIT_OP_SRC,
  224. BLIT_OP_DST,
  225. BLIT_OP_SRC_OVER,
  226. BLIT_OP_DST_OVER, BLIT_OP_OVER_REV = BLIT_OP_DST_OVER,
  227. BLIT_OP_SRC_IN,
  228. BLIT_OP_DST_IN, BLIT_OP_IN_REV = BLIT_OP_DST_IN,
  229. BLIT_OP_SRC_OUT,
  230. BLIT_OP_DST_OUT, BLIT_OP_OUT_REV = BLIT_OP_DST_OUT,
  231. BLIT_OP_SRC_ATOP,
  232. BLIT_OP_DST_ATOP, BLIT_OP_ATOP_REV = BLIT_OP_DST_ATOP,
  233. BLIT_OP_XOR,
  234. BLIT_OP_ADD,
  235. BLIT_OP_MULTIPLY,
  236. BLIT_OP_SCREEN,
  237. BLIT_OP_DARKEN,
  238. BLIT_OP_LIGHTEN,
  239. BLIT_OP_DISJ_SRC_OVER,
  240. BLIT_OP_DISJ_DST_OVER, BLIT_OP_SATURATE = BLIT_OP_DISJ_DST_OVER,
  241. BLIT_OP_DISJ_SRC_IN,
  242. BLIT_OP_DISJ_DST_IN, BLIT_OP_DISJ_IN_REV = BLIT_OP_DISJ_DST_IN,
  243. BLIT_OP_DISJ_SRC_OUT,
  244. BLIT_OP_DISJ_DST_OUT, BLIT_OP_DISJ_OUT_REV = BLIT_OP_DISJ_DST_OUT,
  245. BLIT_OP_DISJ_SRC_ATOP,
  246. BLIT_OP_DISJ_DST_ATOP, BLIT_OP_DISJ_ATOP_REV = BLIT_OP_DISJ_DST_ATOP,
  247. BLIT_OP_DISJ_XOR,
  248. BLIT_OP_CONJ_SRC_OVER,
  249. BLIT_OP_CONJ_DST_OVER, BLIT_OP_CONJ_OVER_REV = BLIT_OP_CONJ_DST_OVER,
  250. BLIT_OP_CONJ_SRC_IN,
  251. BLIT_OP_CONJ_DST_IN, BLIT_OP_CONJ_IN_REV = BLIT_OP_CONJ_DST_IN,
  252. BLIT_OP_CONJ_SRC_OUT,
  253. BLIT_OP_CONJ_DST_OUT, BLIT_OP_CONJ_OUT_REV = BLIT_OP_CONJ_DST_OUT,
  254. BLIT_OP_CONJ_SRC_ATOP,
  255. BLIT_OP_CONJ_DST_ATOP, BLIT_OP_CONJ_ATOP_REV = BLIT_OP_CONJ_DST_ATOP,
  256. BLIT_OP_CONJ_XOR,
  257. /* user select coefficient manually */
  258. BLIT_OP_USER_COEFF,
  259. BLIT_OP_USER_SRC_GA,
  260. /* Add new operation type here */
  261. /* end of blit operation */
  262. BLIT_OP_END,
  263. };
  264. #define MAX_FIMG2D_BLIT_OP ((int)BLIT_OP_END)
  265. #ifdef __KERNEL__
  266. /**
  267. * @TMP: temporary buffer for 2-step blit at a single command
  268. *
  269. * DO NOT CHANGE THIS ORDER
  270. */
  271. enum image_object {
  272. IMAGE_SRC = 0,
  273. IMAGE_MSK,
  274. IMAGE_TMP,
  275. IMAGE_DST,
  276. IMAGE_END,
  277. };
  278. #define MAX_IMAGES IMAGE_END
  279. #define ISRC IMAGE_SRC
  280. #define IMSK IMAGE_MSK
  281. #define ITMP IMAGE_TMP
  282. #define IDST IMAGE_DST
  283. /**
  284. * @size: dma size of image
  285. * @cached: cached dma size of image
  286. */
  287. struct fimg2d_dma {
  288. unsigned long addr;
  289. size_t size;
  290. size_t cached;
  291. };
  292. struct fimg2d_dma_group {
  293. struct fimg2d_dma base;
  294. struct fimg2d_dma plane2;
  295. };
  296. #endif /* __KERNEL__ */
  297. struct fimg2d_qos {
  298. unsigned int freq_int;
  299. unsigned int freq_mif;
  300. unsigned int freq_cpu;
  301. unsigned int freq_kfc;
  302. };
  303. /**
  304. * @start: start address or unique id of image
  305. */
  306. struct fimg2d_addr {
  307. enum addr_space type;
  308. unsigned long start;
  309. };
  310. struct fimg2d_rect {
  311. int x1;
  312. int y1;
  313. int x2; /* x1 + width */
  314. int y2; /* y1 + height */
  315. };
  316. /**
  317. * pixels can be different from src, dst or clip rect
  318. */
  319. struct fimg2d_scale {
  320. enum scaling mode;
  321. /* ratio in pixels */
  322. int src_w, src_h;
  323. int dst_w, dst_h;
  324. };
  325. struct fimg2d_clip {
  326. bool enable;
  327. int x1;
  328. int y1;
  329. int x2; /* x1 + width */
  330. int y2; /* y1 + height */
  331. };
  332. struct fimg2d_repeat {
  333. enum repeat mode;
  334. unsigned long pad_color;
  335. };
  336. /**
  337. * @bg_color: bg_color is valid only if bluescreen mode is BLUSCR.
  338. */
  339. struct fimg2d_bluscr {
  340. enum bluescreen mode;
  341. unsigned long bs_color;
  342. unsigned long bg_color;
  343. };
  344. /**
  345. * @plane2: address info for CbCr in YCbCr 2plane mode
  346. * @rect: crop/clip rect
  347. * @need_cacheopr: true if cache coherency is required
  348. */
  349. struct fimg2d_image {
  350. int width;
  351. int height;
  352. int stride;
  353. enum pixel_order order;
  354. enum color_format fmt;
  355. struct fimg2d_addr addr;
  356. struct fimg2d_addr plane2;
  357. struct fimg2d_rect rect;
  358. bool need_cacheopr;
  359. };
  360. /**
  361. * @solid_color:
  362. * src color instead of src image
  363. * color format and order must be ARGB8888(A is MSB).
  364. * @g_alpha: global(constant) alpha. 0xff is opaque, 0 is transparnet
  365. * @dither: dithering
  366. * @rotate: rotation degree in clockwise
  367. * @premult: alpha premultiplied mode for read & write
  368. * @scaling: common scaling info for src and mask image.
  369. * @repeat: repeat type (tile mode)
  370. * @bluscr: blue screen and transparent mode
  371. * @clipping: clipping rect within dst rect
  372. */
  373. struct fimg2d_param {
  374. unsigned long solid_color;
  375. unsigned char g_alpha;
  376. bool dither;
  377. enum rotation rotate;
  378. enum premultiplied premult;
  379. struct fimg2d_scale scaling;
  380. struct fimg2d_repeat repeat;
  381. struct fimg2d_bluscr bluscr;
  382. struct fimg2d_clip clipping;
  383. };
  384. /**
  385. * @op: blit operation mode
  386. * @src: set when using src image
  387. * @msk: set when using mask image
  388. * @tmp: set when using 2-step blit at a single command
  389. * @dst: dst must not be null
  390. * * tmp image must be the same to dst except memory address
  391. * @seq_no: user debugging info.
  392. * for example, user can set sequence number or pid.
  393. */
  394. struct fimg2d_blit {
  395. enum blit_op op;
  396. struct fimg2d_param param;
  397. struct fimg2d_image *src;
  398. struct fimg2d_image *msk;
  399. struct fimg2d_image *tmp;
  400. struct fimg2d_image *dst;
  401. enum blit_sync sync;
  402. unsigned int seq_no;
  403. enum fimg2d_qos_level qos_lv;
  404. };
  405. #ifdef __KERNEL__
  406. enum perf_desc {
  407. PERF_CACHE = 0,
  408. PERF_SFR,
  409. PERF_BLIT,
  410. PERF_UNMAP,
  411. PERF_TOTAL,
  412. PERF_END
  413. };
  414. #define MAX_PERF_DESCS PERF_END
  415. struct fimg2d_perf {
  416. unsigned int seq_no;
  417. struct timeval start;
  418. struct timeval end;
  419. };
  420. /**
  421. * @pgd: base address of arm mmu pagetable
  422. * @ncmd: request count in blit command queue
  423. * @wait_q: conext wait queue head
  424. */
  425. struct fimg2d_context {
  426. struct mm_struct *mm;
  427. atomic_t ncmd;
  428. wait_queue_head_t wait_q;
  429. struct fimg2d_perf perf[MAX_PERF_DESCS];
  430. void *vma_lock;
  431. unsigned long state;
  432. };
  433. /**
  434. * @op: blit operation mode
  435. * @sync: sync/async blit mode (currently support sync mode only)
  436. * @image: array of image object.
  437. * [0] is for src image
  438. * [1] is for mask image
  439. * [2] is for temporary buffer
  440. * set when using 2-step blit at a single command
  441. * [3] is for dst, dst must not be null
  442. * * tmp image must be the same to dst except memory address
  443. * @seq_no: user debugging info.
  444. * for example, user can set sequence number or pid.
  445. * @dma_all: total dma size of src, msk, dst
  446. * @dma: array of dma info for each src, msk, tmp and dst
  447. * @ctx: context is created when user open fimg2d device.
  448. * @node: list head of blit command queue
  449. */
  450. struct fimg2d_bltcmd {
  451. struct fimg2d_blit blt;
  452. struct fimg2d_image image[MAX_IMAGES];
  453. size_t dma_all;
  454. struct fimg2d_dma_group dma[MAX_IMAGES];
  455. struct fimg2d_context *ctx;
  456. struct list_head node;
  457. };
  458. /**
  459. * @suspended: in suspend mode
  460. * @clkon: power status for runtime pm
  461. * @mem: resource platform device
  462. * @regs: base address of hardware
  463. * @dev: pointer to device struct
  464. * @err: true if hardware is timed out while blitting
  465. * @irq: irq number
  466. * @nctx: context count
  467. * @busy: 1 if hardware is running
  468. * @bltlock: spinlock for blit
  469. * @wait_q: blit wait queue head
  470. * @cmd_q: blit command queue
  471. * @workqueue: workqueue_struct for kfimg2dd
  472. */
  473. struct fimg2d_control {
  474. struct clk *clock;
  475. struct clk *qe_clock;
  476. struct device *dev;
  477. struct resource *mem;
  478. void __iomem *regs;
  479. bool boost;
  480. atomic_t drvact;
  481. atomic_t suspended;
  482. atomic_t clkon;
  483. atomic_t nctx;
  484. atomic_t busy;
  485. spinlock_t bltlock;
  486. spinlock_t qoslock;
  487. struct mutex drvlock;
  488. int irq;
  489. wait_queue_head_t wait_q;
  490. struct list_head cmd_q;
  491. struct workqueue_struct *work_q;
  492. struct pm_qos_request exynos5_g2d_cpu_qos;
  493. struct pm_qos_request exynos5_g2d_kfc_qos;
  494. struct pm_qos_request exynos5_g2d_mif_qos;
  495. struct pm_qos_request exynos5_g2d_int_qos;
  496. struct fimg2d_platdata *pdata;
  497. struct clk *clk_osc;
  498. struct clk *clk_parn1;
  499. struct clk *clk_parn2;
  500. struct clk *clk_chld1;
  501. struct clk *clk_chld2;
  502. struct fimg2d_qos g2d_qos;
  503. enum fimg2d_qos_level qos_lv;
  504. enum fimg2d_qos_level pre_qos_lv;
  505. int (*blit)(struct fimg2d_control *ctrl);
  506. int (*configure)(struct fimg2d_control *ctrl,
  507. struct fimg2d_bltcmd *cmd);
  508. void (*run)(struct fimg2d_control *ctrl);
  509. void (*stop)(struct fimg2d_control *ctrl);
  510. void (*dump)(struct fimg2d_control *ctrl);
  511. void (*finalize)(struct fimg2d_control *ctrl);
  512. };
  513. int fimg2d_register_ops(struct fimg2d_control *ctrl);
  514. int fimg2d_ip_version_is(void);
  515. int bit_per_pixel(struct fimg2d_image *img, int plane);
  516. static inline int width2bytes(int width, int bpp)
  517. {
  518. switch (bpp) {
  519. case 32:
  520. case 24:
  521. case 16:
  522. case 8:
  523. return (width * bpp) >> 3;
  524. case 1:
  525. return (width + 7) >> 3;
  526. case 4:
  527. return (width + 1) >> 1;
  528. default:
  529. return 0;
  530. }
  531. }
  532. #ifdef BLIT_WORKQUE
  533. #define g2d_lock(x) do {} while (0)
  534. #define g2d_unlock(x) do {} while (0)
  535. #define g2d_spin_lock(x, f) spin_lock_irqsave(x, f)
  536. #define g2d_spin_unlock(x, f) spin_unlock_irqrestore(x, f)
  537. #else
  538. #define g2d_lock(x) mutex_lock(x)
  539. #define g2d_unlock(x) mutex_unlock(x)
  540. #define g2d_spin_lock(x, f) do { f = 0; } while (0)
  541. #define g2d_spin_unlock(x, f) do { f = 0; } while (0)
  542. #endif
  543. #endif /* __KERNEL__ */
  544. #endif /* __FIMG2D_H__ */