521331acbf40f646117779ed71902fe72ad77ef7
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / rockchip / rockchip_drm_drv.h
1 /*
2  * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
3  * Author:Mark Yao <mark.yao@rock-chips.com>
4  *
5  * based on exynos_drm_drv.h
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 #ifndef _ROCKCHIP_DRM_DRV_H
18 #define _ROCKCHIP_DRM_DRV_H
19
20 #include <drm/drm_fb_helper.h>
21 #include <drm/drm_atomic_helper.h>
22 #include <drm/drm_gem.h>
23
24 #include <linux/module.h>
25 #include <linux/component.h>
26
27 #define ROCKCHIP_MAX_FB_BUFFER  3
28 #define ROCKCHIP_MAX_CONNECTOR  2
29 #define ROCKCHIP_MAX_CRTC       2
30
31 struct drm_device;
32 struct drm_connector;
33 struct iommu_domain;
34
35 /*
36  * Rockchip drm private crtc funcs.
37  * @loader_protect: protect loader logo crtc's power
38  * @enable_vblank: enable crtc vblank irq.
39  * @disable_vblank: disable crtc vblank irq.
40  */
41 struct rockchip_crtc_funcs {
42         int (*loader_protect)(struct drm_crtc *crtc, bool on);
43         int (*enable_vblank)(struct drm_crtc *crtc);
44         void (*disable_vblank)(struct drm_crtc *crtc);
45         void (*wait_for_update)(struct drm_crtc *crtc);
46         void (*cancel_pending_vblank)(struct drm_crtc *crtc, struct drm_file *file_priv);
47         int (*debugfs_dump)(struct drm_crtc *crtc, struct seq_file *s);
48         enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
49                                            const struct drm_display_mode *mode,
50                                            int output_type);
51 };
52
53 struct drm_rockchip_subdrv {
54         struct list_head list;
55         struct device *dev;
56         struct drm_device *drm_dev;
57
58         int (*open)(struct drm_device *drm_dev, struct device *dev,
59                     struct drm_file *file);
60         void (*close)(struct drm_device *drm_dev, struct device *dev,
61                       struct drm_file *file);
62 };
63
64 struct rockchip_atomic_commit {
65         struct work_struct      work;
66         struct drm_atomic_state *state;
67         struct drm_device *dev;
68         struct mutex lock;
69 };
70
71 struct rockchip_crtc_state {
72         struct drm_crtc_state base;
73         int left_margin;
74         int right_margin;
75         int top_margin;
76         int bottom_margin;
77         int afbdc_win_format;
78         int afbdc_win_width;
79         int afbdc_win_height;
80         int afbdc_win_ptr;
81         int afbdc_win_id;
82         int afbdc_en;
83         int dsp_layer_sel;
84         int output_type;
85         int output_mode;
86         int bus_format;
87 };
88
89 #define to_rockchip_crtc_state(s) \
90                 container_of(s, struct rockchip_crtc_state, base)
91
92 /*
93  * Rockchip drm_file private structure.
94  *
95  * @gem_cpu_acquire_list: list of GEM objects we hold acquires on
96  */
97 struct rockchip_drm_file_private {
98         struct list_head                gem_cpu_acquire_list;
99         struct rockchip_drm_rga_private *rga_priv;
100 };
101
102 struct rockchip_logo {
103         struct sg_table *sgt;
104         struct drm_mm_node mm;
105         dma_addr_t dma_addr;
106         phys_addr_t start;
107         phys_addr_t size;
108         size_t iommu_map_size;
109         int count;
110 };
111
112 /*
113  * Rockchip drm private structure.
114  *
115  * @crtc: array of enabled CRTCs, used to map from "pipe" to drm_crtc.
116  * @num_pipe: number of pipes for this device.
117  * @cpu_fence_context: fence context used for CPU acquire/release
118  * @cpu_fence_seqno: fence sequence number
119  */
120 struct rockchip_drm_private {
121         struct rockchip_logo *logo;
122         struct drm_fb_helper *fbdev_helper;
123         struct drm_gem_object *fbdev_bo;
124         const struct rockchip_crtc_funcs *crtc_funcs[ROCKCHIP_MAX_CRTC];
125         struct drm_atomic_state *state;
126
127         struct rockchip_atomic_commit commit;
128         struct iommu_domain *domain;
129 #ifdef CONFIG_DRM_DMA_SYNC
130         unsigned int cpu_fence_context;
131         atomic_t cpu_fence_seqno;
132 #endif
133         /* protect drm_mm on multi-threads */
134         struct mutex mm_lock;
135         struct drm_mm mm;
136 };
137
138 void rockchip_drm_atomic_work(struct work_struct *work);
139 int rockchip_register_crtc_funcs(struct drm_crtc *crtc,
140                                  const struct rockchip_crtc_funcs *crtc_funcs);
141 void rockchip_unregister_crtc_funcs(struct drm_crtc *crtc);
142 int rockchip_drm_dma_attach_device(struct drm_device *drm_dev,
143                                    struct device *dev);
144 void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
145                                     struct device *dev);
146 int rockchip_drm_wait_line_flag(struct drm_crtc *crtc, unsigned int line_num,
147                                 unsigned int mstimeout);
148
149 int rockchip_drm_register_subdrv(struct drm_rockchip_subdrv *subdrv);
150 int rockchip_drm_unregister_subdrv(struct drm_rockchip_subdrv *subdrv);
151
152 #endif /* _ROCKCHIP_DRM_DRV_H_ */