414447c14598951f137f9bf0c3ae237c590b8849
[sfrench/cifs-2.6.git] / drivers / gpu / drm / msm / mdp / mdp5 / mdp5_kms.h
1 /*
2  * Copyright (C) 2013 Red Hat
3  * Author: Rob Clark <robdclark@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __MDP5_KMS_H__
19 #define __MDP5_KMS_H__
20
21 #include "msm_drv.h"
22 #include "msm_kms.h"
23 #include "mdp/mdp_kms.h"
24 #include "mdp5_cfg.h"   /* must be included before mdp5.xml.h */
25 #include "mdp5.xml.h"
26 #include "mdp5_ctl.h"
27 #include "mdp5_smp.h"
28
29 struct mdp5_kms {
30         struct mdp_kms base;
31
32         struct drm_device *dev;
33
34         struct mdp5_cfg_handler *cfg;
35
36         /* mapper-id used to request GEM buffer mapped for scanout: */
37         int id;
38         struct msm_mmu *mmu;
39
40         struct mdp5_smp *smp;
41         struct mdp5_ctl_manager *ctlm;
42
43         /* io/register spaces: */
44         void __iomem *mmio, *vbif;
45
46         struct regulator *vdd;
47
48         struct clk *axi_clk;
49         struct clk *ahb_clk;
50         struct clk *src_clk;
51         struct clk *core_clk;
52         struct clk *lut_clk;
53         struct clk *vsync_clk;
54
55         /*
56          * lock to protect access to global resources: ie., following register:
57          *      - REG_MDP5_DISP_INTF_SEL
58          */
59         spinlock_t resource_lock;
60
61         struct mdp_irq error_handler;
62
63         struct {
64                 volatile unsigned long enabled_mask;
65                 struct irq_domain *domain;
66         } irqcontroller;
67 };
68 #define to_mdp5_kms(x) container_of(x, struct mdp5_kms, base)
69
70 struct mdp5_overlay_info {
71         enum mdp_mixer_stage_id zorder;
72 };
73
74 static inline void mdp5_write(struct mdp5_kms *mdp5_kms, u32 reg, u32 data)
75 {
76         msm_writel(data, mdp5_kms->mmio + reg);
77 }
78
79 static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
80 {
81         return msm_readl(mdp5_kms->mmio + reg);
82 }
83
84 static inline const char *pipe2name(enum mdp5_pipe pipe)
85 {
86         static const char *names[] = {
87 #define NAME(n) [SSPP_ ## n] = #n
88                 NAME(VIG0), NAME(VIG1), NAME(VIG2),
89                 NAME(RGB0), NAME(RGB1), NAME(RGB2),
90                 NAME(DMA0), NAME(DMA1),
91                 NAME(VIG3), NAME(RGB3),
92 #undef NAME
93         };
94         return names[pipe];
95 }
96
97 static inline int pipe2nclients(enum mdp5_pipe pipe)
98 {
99         switch (pipe) {
100         case SSPP_RGB0:
101         case SSPP_RGB1:
102         case SSPP_RGB2:
103         case SSPP_RGB3:
104                 return 1;
105         default:
106                 return 3;
107         }
108 }
109
110 static inline uint32_t intf2err(int intf)
111 {
112         switch (intf) {
113         case 0:  return MDP5_IRQ_INTF0_UNDER_RUN;
114         case 1:  return MDP5_IRQ_INTF1_UNDER_RUN;
115         case 2:  return MDP5_IRQ_INTF2_UNDER_RUN;
116         case 3:  return MDP5_IRQ_INTF3_UNDER_RUN;
117         default: return 0;
118         }
119 }
120
121 static inline uint32_t intf2vblank(int intf)
122 {
123         switch (intf) {
124         case 0:  return MDP5_IRQ_INTF0_VSYNC;
125         case 1:  return MDP5_IRQ_INTF1_VSYNC;
126         case 2:  return MDP5_IRQ_INTF2_VSYNC;
127         case 3:  return MDP5_IRQ_INTF3_VSYNC;
128         default: return 0;
129         }
130 }
131
132 int mdp5_disable(struct mdp5_kms *mdp5_kms);
133 int mdp5_enable(struct mdp5_kms *mdp5_kms);
134
135 void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask);
136 void mdp5_irq_preinstall(struct msm_kms *kms);
137 int mdp5_irq_postinstall(struct msm_kms *kms);
138 void mdp5_irq_uninstall(struct msm_kms *kms);
139 irqreturn_t mdp5_irq(struct msm_kms *kms);
140 int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
141 void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
142 int mdp5_irq_domain_init(struct mdp5_kms *mdp5_kms);
143 void mdp5_irq_domain_fini(struct mdp5_kms *mdp5_kms);
144
145 static inline
146 uint32_t mdp5_get_formats(enum mdp5_pipe pipe, uint32_t *pixel_formats,
147                 uint32_t max_formats)
148 {
149         /* TODO when we have YUV, we need to filter supported formats
150          * based on pipe id..
151          */
152         return mdp_get_formats(pixel_formats, max_formats);
153 }
154
155 void mdp5_plane_install_properties(struct drm_plane *plane,
156                 struct drm_mode_object *obj);
157 void mdp5_plane_set_overlay_info(struct drm_plane *plane,
158                 const struct mdp5_overlay_info *overlay_info);
159 struct mdp5_overlay_info *mdp5_plane_get_overlay_info(struct drm_plane *plane);
160 uint32_t mdp5_plane_get_flush(struct drm_plane *plane);
161 void mdp5_plane_set_scanout(struct drm_plane *plane,
162                 struct drm_framebuffer *fb);
163 int mdp5_plane_mode_set(struct drm_plane *plane,
164                 struct drm_crtc *crtc, struct drm_framebuffer *fb,
165                 int crtc_x, int crtc_y,
166                 unsigned int crtc_w, unsigned int crtc_h,
167                 uint32_t src_x, uint32_t src_y,
168                 uint32_t src_w, uint32_t src_h);
169 void mdp5_plane_complete_flip(struct drm_plane *plane);
170 enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane);
171 struct drm_plane *mdp5_plane_init(struct drm_device *dev,
172                 enum mdp5_pipe pipe, bool private_plane, uint32_t reg_offset);
173
174 uint32_t mdp5_crtc_vblank(struct drm_crtc *crtc);
175
176 int mdp5_crtc_get_lm(struct drm_crtc *crtc);
177 void mdp5_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
178 void mdp5_crtc_set_intf(struct drm_crtc *crtc, int intf,
179                 enum mdp5_intf intf_id);
180 int  mdp5_crtc_attach(struct drm_crtc *crtc, struct drm_plane *plane);
181 void mdp5_crtc_detach(struct drm_crtc *crtc, struct drm_plane *plane);
182 struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
183                 struct drm_plane *plane, int id);
184
185 struct drm_encoder *mdp5_encoder_init(struct drm_device *dev, int intf,
186                 enum mdp5_intf intf_id);
187
188 #endif /* __MDP5_KMS_H__ */