rga.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
  3. * Author: Jacob Chen <jacob-chen@iotwrt.com>
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __RGA_H__
  15. #define __RGA_H__
  16. #include <linux/platform_device.h>
  17. #include <media/videobuf2-v4l2.h>
  18. #include <media/v4l2-ctrls.h>
  19. #include <media/v4l2-device.h>
  20. #define RGA_NAME "rockchip-rga"
  21. struct rga_fmt {
  22. u32 fourcc;
  23. int depth;
  24. u8 uv_factor;
  25. u8 y_div;
  26. u8 x_div;
  27. u8 color_swap;
  28. u8 hw_format;
  29. };
  30. struct rga_frame {
  31. /* Original dimensions */
  32. u32 width;
  33. u32 height;
  34. u32 colorspace;
  35. /* Crop */
  36. struct v4l2_rect crop;
  37. /* Image format */
  38. struct rga_fmt *fmt;
  39. /* Variables that can calculated once and reused */
  40. u32 stride;
  41. u32 size;
  42. };
  43. struct rockchip_rga_version {
  44. u32 major;
  45. u32 minor;
  46. };
  47. struct rga_ctx {
  48. struct v4l2_fh fh;
  49. struct rockchip_rga *rga;
  50. struct rga_frame in;
  51. struct rga_frame out;
  52. struct v4l2_ctrl_handler ctrl_handler;
  53. /* Control values */
  54. u32 op;
  55. u32 hflip;
  56. u32 vflip;
  57. u32 rotate;
  58. u32 fill_color;
  59. };
  60. struct rockchip_rga {
  61. struct v4l2_device v4l2_dev;
  62. struct v4l2_m2m_dev *m2m_dev;
  63. struct video_device *vfd;
  64. struct device *dev;
  65. struct regmap *grf;
  66. void __iomem *regs;
  67. struct clk *sclk;
  68. struct clk *aclk;
  69. struct clk *hclk;
  70. struct rockchip_rga_version version;
  71. /* vfd lock */
  72. struct mutex mutex;
  73. /* ctrl parm lock */
  74. spinlock_t ctrl_lock;
  75. struct rga_ctx *curr;
  76. dma_addr_t cmdbuf_phy;
  77. void *cmdbuf_virt;
  78. unsigned int *src_mmu_pages;
  79. unsigned int *dst_mmu_pages;
  80. };
  81. struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type type);
  82. /* RGA Buffers Manage */
  83. extern const struct vb2_ops rga_qops;
  84. void rga_buf_map(struct vb2_buffer *vb);
  85. /* RGA Hardware */
  86. static inline void rga_write(struct rockchip_rga *rga, u32 reg, u32 value)
  87. {
  88. writel(value, rga->regs + reg);
  89. };
  90. static inline u32 rga_read(struct rockchip_rga *rga, u32 reg)
  91. {
  92. return readl(rga->regs + reg);
  93. };
  94. static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask)
  95. {
  96. u32 temp = rga_read(rga, reg) & ~(mask);
  97. temp |= val & mask;
  98. rga_write(rga, reg, temp);
  99. };
  100. void rga_hw_start(struct rockchip_rga *rga);
  101. #endif