linux/drivers/media/platform/rockchip/rga/rga.h
<<
>>
Prefs
   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
  17#include <linux/platform_device.h>
  18#include <media/videobuf2-v4l2.h>
  19#include <media/v4l2-ctrls.h>
  20#include <media/v4l2-device.h>
  21
  22#define RGA_NAME "rockchip-rga"
  23
  24struct rga_fmt {
  25        u32 fourcc;
  26        int depth;
  27        u8 uv_factor;
  28        u8 y_div;
  29        u8 x_div;
  30        u8 color_swap;
  31        u8 hw_format;
  32};
  33
  34struct rga_frame {
  35        /* Original dimensions */
  36        u32 width;
  37        u32 height;
  38        u32 colorspace;
  39
  40        /* Crop */
  41        struct v4l2_rect crop;
  42
  43        /* Image format */
  44        struct rga_fmt *fmt;
  45
  46        /* Variables that can calculated once and reused */
  47        u32 stride;
  48        u32 size;
  49};
  50
  51struct rockchip_rga_version {
  52        u32 major;
  53        u32 minor;
  54};
  55
  56struct rga_ctx {
  57        struct v4l2_fh fh;
  58        struct rockchip_rga *rga;
  59        struct rga_frame in;
  60        struct rga_frame out;
  61        struct v4l2_ctrl_handler ctrl_handler;
  62
  63        /* Control values */
  64        u32 op;
  65        u32 hflip;
  66        u32 vflip;
  67        u32 rotate;
  68        u32 fill_color;
  69};
  70
  71struct rockchip_rga {
  72        struct v4l2_device v4l2_dev;
  73        struct v4l2_m2m_dev *m2m_dev;
  74        struct video_device *vfd;
  75
  76        struct device *dev;
  77        struct regmap *grf;
  78        void __iomem *regs;
  79        struct clk *sclk;
  80        struct clk *aclk;
  81        struct clk *hclk;
  82        struct rockchip_rga_version version;
  83
  84        /* vfd lock */
  85        struct mutex mutex;
  86        /* ctrl parm lock */
  87        spinlock_t ctrl_lock;
  88
  89        struct rga_ctx *curr;
  90        dma_addr_t cmdbuf_phy;
  91        void *cmdbuf_virt;
  92        unsigned int *src_mmu_pages;
  93        unsigned int *dst_mmu_pages;
  94};
  95
  96struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type type);
  97
  98/* RGA Buffers Manage */
  99extern const struct vb2_ops rga_qops;
 100void rga_buf_map(struct vb2_buffer *vb);
 101
 102/* RGA Hardware */
 103static inline void rga_write(struct rockchip_rga *rga, u32 reg, u32 value)
 104{
 105        writel(value, rga->regs + reg);
 106};
 107
 108static inline u32 rga_read(struct rockchip_rga *rga, u32 reg)
 109{
 110        return readl(rga->regs + reg);
 111};
 112
 113static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask)
 114{
 115        u32 temp = rga_read(rga, reg) & ~(mask);
 116
 117        temp |= val & mask;
 118        rga_write(rga, reg, temp);
 119};
 120
 121void rga_hw_start(struct rockchip_rga *rga);
 122
 123#endif
 124