blob: c5e225f0cc3843b9bc4aabaa0855e464c3635ee5 [file] [log] [blame]
Narendra Muppalla1b0b3352015-09-29 10:16:51 -07001/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef __SDE_KMS_H__
14#define __SDE_KMS_H__
15
16#include "msm_drv.h"
17#include "msm_kms.h"
18#include "mdp/mdp_kms.h"
19#include "sde_hw_catalog.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040020#include "sde_hw_mdp_ctl.h"
21#include "sde_hw_lm.h"
Ben Chan78647cd2016-06-26 22:02:47 -040022#include "sde_hw_interrupts.h"
23
24/*
25 * struct sde_irq_callback - IRQ callback handlers
26 * @func: intr handler
27 * @arg: argument for the handler
28 */
29struct sde_irq_callback {
30 void (*func)(void *arg, int irq_idx);
31 void *arg;
32};
33
34/**
35 * struct sde_irq: IRQ structure contains callback registration info
36 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
37 * @irq_cb_tbl: array of IRQ callbacks setting
38 * @cb_lock: callback lock
39 */
40struct sde_irq {
41 u32 total_irqs;
42 struct sde_irq_callback *irq_cb_tbl;
43 spinlock_t cb_lock;
44};
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070045
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040046/**
47 * struct sde_hw_res_map : Default resource table identifying default
48 * hw resource map. Primarily used for forcing DSI to use CTL_0/1
49 * and Pingpong 0/1, if the field is set to SDE_NONE means any HW
50 * intstance for that tpye is allowed as long as it is unused.
51 */
52struct sde_hw_res_map {
53 enum sde_intf intf;
54 enum sde_lm lm;
55 enum sde_pingpong pp;
56 enum sde_ctl ctl;
57};
58
59/* struct sde_hw_resource_manager : Resource mananger maintains the current
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -040060 * default platform config and manages shared
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040061 * hw resources ex:ctl_path hw driver context
62 * is needed by CRTCs/PLANEs/ENCODERs
63 * @ctl : table of control path hw driver contexts allocated
64 * @mixer : list of mixer hw drivers contexts allocated
65 * @intr : pointer to hw interrupt context
66 * @res_table : pointer to default hw_res table for this platform
67 * @feature_map :BIT map for default enabled features ex:specifies if PP_SPLIT
68 * is enabled/disabled by defalt for this platform
69 */
70struct sde_hw_resource_manager {
71 struct sde_hw_ctl *ctl[CTL_MAX];
72 struct sde_hw_mixer *mixer[LM_MAX];
73 struct sde_hw_intr *intr;
74 const struct sde_hw_res_map *res_table;
75 bool feature_map;
76};
77
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070078struct sde_kms {
Ben Chan78647cd2016-06-26 22:02:47 -040079 struct msm_kms base;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070080 struct drm_device *dev;
81 int rev;
82 struct sde_mdss_cfg *catalog;
83
84 struct msm_mmu *mmu;
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -040085 int mmu_id;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070086
87 /* io/register spaces: */
88 void __iomem *mmio, *vbif;
89
90 struct regulator *vdd;
91 struct regulator *mmagic;
92 struct regulator *venus;
93
94 struct clk *axi_clk;
95 struct clk *ahb_clk;
96 struct clk *src_clk;
97 struct clk *core_clk;
98 struct clk *lut_clk;
99 struct clk *mmagic_clk;
100 struct clk *iommu_clk;
101 struct clk *vsync_clk;
102
103 struct {
104 unsigned long enabled_mask;
105 struct irq_domain *domain;
106 } irqcontroller;
Ben Chan78647cd2016-06-26 22:02:47 -0400107
108 struct sde_hw_intr *hw_intr;
109 struct sde_irq irq_obj;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400110 struct sde_hw_resource_manager hw_res;
Ben Chan78647cd2016-06-26 22:02:47 -0400111};
112
113struct vsync_info {
114 u32 frame_count;
115 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700116};
117
118#define to_sde_kms(x) container_of(x, struct sde_kms, base)
119
120struct sde_plane_state {
121 struct drm_plane_state base;
122
123 /* aligned with property */
Clarence Ipe78efb72016-06-24 18:35:21 -0400124 uint64_t property_values[PLANE_PROP_COUNT];
125
126 /* blob properties */
127 struct drm_property_blob *property_blobs[PLANE_PROP_BLOBCOUNT];
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700128
129 /* assigned by crtc blender */
130 enum sde_stage stage;
131
132 /* some additional transactional status to help us know in the
133 * apply path whether we need to update SMP allocation, and
134 * whether current update is still pending:
135 */
136 bool mode_changed : 1;
137 bool pending : 1;
138};
139
140#define to_sde_plane_state(x) \
141 container_of(x, struct sde_plane_state, base)
142
143int sde_disable(struct sde_kms *sde_kms);
144int sde_enable(struct sde_kms *sde_kms);
145
Ben Chan78647cd2016-06-26 22:02:47 -0400146/**
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400147 * HW resource manager functions
148 * @sde_rm_acquire_ctl_path : Allocates control path
149 * @sde_rm_get_ctl_path : returns control path driver context for already
150 * acquired ctl path
151 * @sde_rm_release_ctl_path : Frees control path driver context
152 * @sde_rm_acquire_mixer : Allocates mixer hw driver context
153 * @sde_rm_get_mixer : returns mixer context for already
154 * acquired mixer
155 * @sde_rm_release_mixer : Frees mixer hw driver context
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -0400156 * @sde_rm_acquire_intr : Allocate hw intr context
157 * @sde_rm_get_intr : Returns already acquired intr context
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400158 * @sde_rm_get_hw_res_map : Returns map for the passed INTF
159 */
160struct sde_hw_ctl *sde_rm_acquire_ctl_path(struct sde_kms *sde_kms,
161 enum sde_ctl idx);
162struct sde_hw_ctl *sde_rm_get_ctl_path(struct sde_kms *sde_kms,
163 enum sde_ctl idx);
164void sde_rm_release_ctl_path(struct sde_kms *sde_kms,
165 enum sde_ctl idx);
166struct sde_hw_mixer *sde_rm_acquire_mixer(struct sde_kms *sde_kms,
167 enum sde_lm idx);
168struct sde_hw_mixer *sde_rm_get_mixer(struct sde_kms *sde_kms,
169 enum sde_lm idx);
170void sde_rm_release_mixer(struct sde_kms *sde_kms,
171 enum sde_lm idx);
172struct sde_hw_intr *sde_rm_acquire_intr(struct sde_kms *sde_kms);
173struct sde_hw_intr *sde_rm_get_intr(struct sde_kms *sde_kms);
174
175const struct sde_hw_res_map *sde_rm_get_res_map(struct sde_kms *sde_kms,
176 enum sde_intf idx);
177
178/**
Ben Chan78647cd2016-06-26 22:02:47 -0400179 * IRQ functions
180 */
181int sde_irq_domain_init(struct sde_kms *sde_kms);
182int sde_irq_domain_fini(struct sde_kms *sde_kms);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700183void sde_irq_preinstall(struct msm_kms *kms);
184int sde_irq_postinstall(struct msm_kms *kms);
185void sde_irq_uninstall(struct msm_kms *kms);
186irqreturn_t sde_irq(struct msm_kms *kms);
Ben Chan78647cd2016-06-26 22:02:47 -0400187
188/**
189 * sde_set_irqmask - IRQ helper function for writing IRQ mask
190 * to SDE HW interrupt register.
191 * @sde_kms: SDE handle
192 * @reg_off: SDE HW interrupt register offset
193 * @irqmask: IRQ mask
194 */
195void sde_set_irqmask(
196 struct sde_kms *sde_kms,
197 uint32_t reg_off,
198 uint32_t irqmask);
199
200/**
201 * sde_irq_idx_lookup - IRQ helper function for lookup irq_idx from HW
202 * interrupt mapping table.
203 * @sde_kms: SDE handle
204 * @intr_type: SDE HW interrupt type for lookup
205 * @instance_idx: SDE HW block instance defined in sde_hw_mdss.h
206 * @return: irq_idx or -EINVAL when fail to lookup
207 */
208int sde_irq_idx_lookup(
209 struct sde_kms *sde_kms,
210 enum sde_intr_type intr_type,
211 uint32_t instance_idx);
212
213/**
214 * sde_enable_irq - IRQ helper function for enabling one or more IRQs
215 * @sde_kms: SDE handle
216 * @irq_idxs: Array of irq index
217 * @irq_count: Number of irq_idx provided in the array
218 * @return: 0 for success enabling IRQ, otherwise failure
219 */
220int sde_enable_irq(
221 struct sde_kms *sde_kms,
222 int *irq_idxs,
223 uint32_t irq_count);
224
225/**
226 * sde_disable_irq - IRQ helper function for diabling one of more IRQs
227 * @sde_kms: SDE handle
228 * @irq_idxs: Array of irq index
229 * @irq_count: Number of irq_idx provided in the array
230 * @return: 0 for success disabling IRQ, otherwise failure
231 */
232int sde_disable_irq(
233 struct sde_kms *sde_kms,
234 int *irq_idxs,
235 uint32_t irq_count);
236
237/**
238 * sde_register_irq_callback - For registering callback function on IRQ
239 * interrupt
240 * @sde_kms: SDE handle
241 * @irq_idx: irq index
242 * @irq_cb: IRQ callback structure, containing callback function
243 * and argument. Passing NULL for irq_cb will unregister
244 * the callback for the given irq_idx
245 * @return: 0 for success registering callback, otherwise failure
246 */
247int sde_register_irq_callback(
248 struct sde_kms *sde_kms,
249 int irq_idx,
250 struct sde_irq_callback *irq_cb);
251
252/**
253 * sde_clear_all_irqs - Clearing all SDE IRQ interrupt status
254 * @sde_kms: SDE handle
255 */
256void sde_clear_all_irqs(struct sde_kms *sde_kms);
257
258/**
259 * sde_disable_all_irqs - Diabling all SDE IRQ interrupt
260 * @sde_kms: SDE handle
261 */
262void sde_disable_all_irqs(struct sde_kms *sde_kms);
263
264/**
265 * Vblank enable/disable functions
266 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700267int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
268void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
269
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400270/**
271 * Plane functions
272 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700273enum sde_sspp sde_plane_pipe(struct drm_plane *plane);
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400274struct drm_plane *sde_plane_init(struct drm_device *dev, uint32_t pipe,
275 bool private_plane);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700276
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400277/**
278 * CRTC functions
279 */
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -0400280int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400281void sde_crtc_wait_for_commit_done(struct drm_crtc *crtc);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700282void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700283struct drm_crtc *sde_crtc_init(struct drm_device *dev,
284 struct drm_encoder *encoder,
285 struct drm_plane *plane, int id);
286
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400287/**
288 * Encoder functions and data types
289 */
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400290struct sde_encoder_hw_resources {
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400291 enum sde_intf_mode intfs[INTF_MAX];
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400292 bool pingpongs[PINGPONG_MAX];
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400293 bool ctls[CTL_MAX];
294 bool pingpongsplit;
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400295};
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400296
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400297void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
298 struct sde_encoder_hw_resources *hw_res);
299void sde_encoder_register_vblank_callback(struct drm_encoder *drm_enc,
300 void (*cb)(void *), void *data);
301void sde_encoders_init(struct drm_device *dev);
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400302void sde_encoder_get_vsync_info(struct drm_encoder *encoder,
303 struct vsync_info *vsync);
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400304
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700305
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700306
307#endif /* __sde_kms_H__ */