blob: bb043dfb46b954f9e57f40993b4327f197f1e2bc [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
Clarence Ip4ce59322016-06-26 22:27:51 -040087 /* directory entry for debugfs */
88 void *debugfs_root;
89
Narendra Muppalla1b0b3352015-09-29 10:16:51 -070090 /* io/register spaces: */
91 void __iomem *mmio, *vbif;
92
93 struct regulator *vdd;
94 struct regulator *mmagic;
95 struct regulator *venus;
96
97 struct clk *axi_clk;
98 struct clk *ahb_clk;
99 struct clk *src_clk;
100 struct clk *core_clk;
101 struct clk *lut_clk;
102 struct clk *mmagic_clk;
103 struct clk *iommu_clk;
104 struct clk *vsync_clk;
105
106 struct {
107 unsigned long enabled_mask;
108 struct irq_domain *domain;
109 } irqcontroller;
Ben Chan78647cd2016-06-26 22:02:47 -0400110
111 struct sde_hw_intr *hw_intr;
112 struct sde_irq irq_obj;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400113 struct sde_hw_resource_manager hw_res;
Ben Chan78647cd2016-06-26 22:02:47 -0400114};
115
116struct vsync_info {
117 u32 frame_count;
118 u32 line_count;
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700119};
120
121#define to_sde_kms(x) container_of(x, struct sde_kms, base)
122
123struct sde_plane_state {
124 struct drm_plane_state base;
125
126 /* aligned with property */
Clarence Ipe78efb72016-06-24 18:35:21 -0400127 uint64_t property_values[PLANE_PROP_COUNT];
128
129 /* blob properties */
130 struct drm_property_blob *property_blobs[PLANE_PROP_BLOBCOUNT];
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700131
132 /* assigned by crtc blender */
133 enum sde_stage stage;
134
135 /* some additional transactional status to help us know in the
136 * apply path whether we need to update SMP allocation, and
137 * whether current update is still pending:
138 */
139 bool mode_changed : 1;
140 bool pending : 1;
141};
142
143#define to_sde_plane_state(x) \
144 container_of(x, struct sde_plane_state, base)
145
146int sde_disable(struct sde_kms *sde_kms);
147int sde_enable(struct sde_kms *sde_kms);
148
Ben Chan78647cd2016-06-26 22:02:47 -0400149/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400150 * Debugfs functions - extra helper functions for debugfs support
151 *
152 * Main debugfs documentation is located at,
153 *
154 * Documentation/filesystems/debugfs.txt
155 *
156 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
157 * @sde_debugfs_create_regset32: Create 32-bit register dump file
158 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
159 */
160
161/**
162 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
163 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
164 */
165struct sde_debugfs_regset32 {
166 uint32_t offset;
167 uint32_t blk_len;
168 void __iomem *base;
169};
170
171/**
172 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
173 * This function is meant to initialize sde_debugfs_regset32 structures for use
174 * with sde_debugfs_create_regset32.
175 * @regset: opaque register definition structure
176 * @offset: sub-block offset
177 * @length: sub-block length, in bytes
178 * @base: base IOMEM address
179 */
180void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
181 uint32_t offset, uint32_t length, void __iomem *base);
182
183/**
184 * sde_debugfs_create_regset32 - Create register read back file for debugfs
185 *
186 * This function is almost identical to the standard debugfs_create_regset32()
187 * function, with the main difference being that a list of register
188 * names/offsets do not need to be provided. The 'read' function simply outputs
189 * sequential register values over a specified range.
190 *
191 * Similar to the related debugfs_create_regset32 API, the structure pointed to
192 * by regset needs to persist for the lifetime of the created file. The calling
193 * code is responsible for initialization/management of this structure.
194 *
195 * The structure pointed to by regset is meant to be opaque. Please use
196 * sde_debugfs_setup_regset32 to initialize it.
197 *
198 * @name: File name within debugfs
199 * @mode: File mode within debugfs
200 * @parent: Parent directory entry within debugfs, can be NULL
201 * @regset: Pointer to persistent register block definition
202 *
203 * Return: dentry pointer for newly created file, use either debugfs_remove()
204 * or debugfs_remove_recursive() (on a parent directory) to remove the
205 * file
206 */
207void *sde_debugfs_create_regset32(const char *name, umode_t mode,
208 void *parent, struct sde_debugfs_regset32 *regset);
209
210/**
211 * sde_debugfs_get_root - Return root directory entry for SDE's debugfs
212 *
213 * The return value should be passed as the 'parent' argument to subsequent
214 * debugfs create calls.
215 *
216 * @sde_kms: Pointer to SDE's KMS structure
217 *
218 * Return: dentry pointer for SDE's debugfs location
219 */
220void *sde_debugfs_get_root(struct sde_kms *sde_kms);
221
222/**
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400223 * HW resource manager functions
224 * @sde_rm_acquire_ctl_path : Allocates control path
225 * @sde_rm_get_ctl_path : returns control path driver context for already
226 * acquired ctl path
227 * @sde_rm_release_ctl_path : Frees control path driver context
228 * @sde_rm_acquire_mixer : Allocates mixer hw driver context
229 * @sde_rm_get_mixer : returns mixer context for already
230 * acquired mixer
231 * @sde_rm_release_mixer : Frees mixer hw driver context
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -0400232 * @sde_rm_acquire_intr : Allocate hw intr context
233 * @sde_rm_get_intr : Returns already acquired intr context
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400234 * @sde_rm_get_hw_res_map : Returns map for the passed INTF
235 */
236struct sde_hw_ctl *sde_rm_acquire_ctl_path(struct sde_kms *sde_kms,
237 enum sde_ctl idx);
238struct sde_hw_ctl *sde_rm_get_ctl_path(struct sde_kms *sde_kms,
239 enum sde_ctl idx);
240void sde_rm_release_ctl_path(struct sde_kms *sde_kms,
241 enum sde_ctl idx);
242struct sde_hw_mixer *sde_rm_acquire_mixer(struct sde_kms *sde_kms,
243 enum sde_lm idx);
244struct sde_hw_mixer *sde_rm_get_mixer(struct sde_kms *sde_kms,
245 enum sde_lm idx);
246void sde_rm_release_mixer(struct sde_kms *sde_kms,
247 enum sde_lm idx);
248struct sde_hw_intr *sde_rm_acquire_intr(struct sde_kms *sde_kms);
249struct sde_hw_intr *sde_rm_get_intr(struct sde_kms *sde_kms);
250
251const struct sde_hw_res_map *sde_rm_get_res_map(struct sde_kms *sde_kms,
252 enum sde_intf idx);
253
254/**
Ben Chan78647cd2016-06-26 22:02:47 -0400255 * IRQ functions
256 */
257int sde_irq_domain_init(struct sde_kms *sde_kms);
258int sde_irq_domain_fini(struct sde_kms *sde_kms);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700259void sde_irq_preinstall(struct msm_kms *kms);
260int sde_irq_postinstall(struct msm_kms *kms);
261void sde_irq_uninstall(struct msm_kms *kms);
262irqreturn_t sde_irq(struct msm_kms *kms);
Ben Chan78647cd2016-06-26 22:02:47 -0400263
264/**
265 * sde_set_irqmask - IRQ helper function for writing IRQ mask
266 * to SDE HW interrupt register.
267 * @sde_kms: SDE handle
268 * @reg_off: SDE HW interrupt register offset
269 * @irqmask: IRQ mask
270 */
271void sde_set_irqmask(
272 struct sde_kms *sde_kms,
273 uint32_t reg_off,
274 uint32_t irqmask);
275
276/**
277 * sde_irq_idx_lookup - IRQ helper function for lookup irq_idx from HW
278 * interrupt mapping table.
279 * @sde_kms: SDE handle
280 * @intr_type: SDE HW interrupt type for lookup
281 * @instance_idx: SDE HW block instance defined in sde_hw_mdss.h
282 * @return: irq_idx or -EINVAL when fail to lookup
283 */
284int sde_irq_idx_lookup(
285 struct sde_kms *sde_kms,
286 enum sde_intr_type intr_type,
287 uint32_t instance_idx);
288
289/**
290 * sde_enable_irq - IRQ helper function for enabling one or more IRQs
291 * @sde_kms: SDE handle
292 * @irq_idxs: Array of irq index
293 * @irq_count: Number of irq_idx provided in the array
294 * @return: 0 for success enabling IRQ, otherwise failure
295 */
296int sde_enable_irq(
297 struct sde_kms *sde_kms,
298 int *irq_idxs,
299 uint32_t irq_count);
300
301/**
302 * sde_disable_irq - IRQ helper function for diabling one of more IRQs
303 * @sde_kms: SDE handle
304 * @irq_idxs: Array of irq index
305 * @irq_count: Number of irq_idx provided in the array
306 * @return: 0 for success disabling IRQ, otherwise failure
307 */
308int sde_disable_irq(
309 struct sde_kms *sde_kms,
310 int *irq_idxs,
311 uint32_t irq_count);
312
313/**
314 * sde_register_irq_callback - For registering callback function on IRQ
315 * interrupt
316 * @sde_kms: SDE handle
317 * @irq_idx: irq index
318 * @irq_cb: IRQ callback structure, containing callback function
319 * and argument. Passing NULL for irq_cb will unregister
320 * the callback for the given irq_idx
321 * @return: 0 for success registering callback, otherwise failure
322 */
323int sde_register_irq_callback(
324 struct sde_kms *sde_kms,
325 int irq_idx,
326 struct sde_irq_callback *irq_cb);
327
328/**
329 * sde_clear_all_irqs - Clearing all SDE IRQ interrupt status
330 * @sde_kms: SDE handle
331 */
332void sde_clear_all_irqs(struct sde_kms *sde_kms);
333
334/**
335 * sde_disable_all_irqs - Diabling all SDE IRQ interrupt
336 * @sde_kms: SDE handle
337 */
338void sde_disable_all_irqs(struct sde_kms *sde_kms);
339
340/**
341 * Vblank enable/disable functions
342 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700343int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
344void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
345
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400346/**
347 * Plane functions
348 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700349enum sde_sspp sde_plane_pipe(struct drm_plane *plane);
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400350struct drm_plane *sde_plane_init(struct drm_device *dev, uint32_t pipe,
351 bool private_plane);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700352
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400353/**
354 * CRTC functions
355 */
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -0400356int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400357void sde_crtc_wait_for_commit_done(struct drm_crtc *crtc);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700358void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700359struct drm_crtc *sde_crtc_init(struct drm_device *dev,
360 struct drm_encoder *encoder,
361 struct drm_plane *plane, int id);
362
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400363/**
364 * Encoder functions and data types
365 */
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400366struct sde_encoder_hw_resources {
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400367 enum sde_intf_mode intfs[INTF_MAX];
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400368 bool pingpongs[PINGPONG_MAX];
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400369 bool ctls[CTL_MAX];
370 bool pingpongsplit;
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400371};
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400372
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400373void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
374 struct sde_encoder_hw_resources *hw_res);
375void sde_encoder_register_vblank_callback(struct drm_encoder *drm_enc,
376 void (*cb)(void *), void *data);
377void sde_encoders_init(struct drm_device *dev);
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400378void sde_encoder_get_vsync_info(struct drm_encoder *encoder,
379 struct vsync_info *vsync);
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400380
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700381
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700382
383#endif /* __sde_kms_H__ */