blob: c4d3881d6b0c4f3bf5ca5a123cbecccc26826903 [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"
Clarence Ipc475b082016-06-26 09:27:23 -040020#include "sde_hw_ctl.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040021#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
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040049 * and PingPong 0/1, if the field is set to SDE_NONE means any HW
50 * instance for that type is allowed as long as it is unused.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040051 */
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
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040059/* struct sde_hw_resource_manager : Resource manager 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
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -040068 * is enabled/disabled by default for this platform
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040069 */
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) \
Clarence Ip4c1d9772016-06-26 09:35:38 -0400144 container_of(x, struct sde_plane_state, base)
145
146/**
147 * sde_plane_get_property - Query integer value of plane property
148 *
149 * @S: Pointer to plane state
150 * @X: Property index, from enum msm_mdp_plane_property
151 *
152 * Return: Integer value of requested property
153 */
154#define sde_plane_get_property(S, X) \
155 ((S) && ((X) < PLANE_PROP_COUNT) ? ((S)->property_values[(X)]) : 0)
156
157/**
158 * sde_plane_get_property32 - Query 32-bit representation of plane property
159 *
160 * @S: Pointer to plane state
161 * @X: Property index, from enum msm_mdp_plane_property
162 *
163 * Return: 32-bit value of requested property
164 */
165#define sde_plane_get_property32(S, X) \
166 ((S) && ((X) < PLANE_PROP_COUNT) ? \
167 (uint32_t)((S)->property_values[(X)]) : 0)
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700168
169int sde_disable(struct sde_kms *sde_kms);
170int sde_enable(struct sde_kms *sde_kms);
171
Ben Chan78647cd2016-06-26 22:02:47 -0400172/**
Clarence Ip4ce59322016-06-26 22:27:51 -0400173 * Debugfs functions - extra helper functions for debugfs support
174 *
175 * Main debugfs documentation is located at,
176 *
177 * Documentation/filesystems/debugfs.txt
178 *
179 * @sde_debugfs_setup_regset32: Initialize data for sde_debugfs_create_regset32
180 * @sde_debugfs_create_regset32: Create 32-bit register dump file
181 * @sde_debugfs_get_root: Get root dentry for SDE_KMS's debugfs node
182 */
183
184/**
185 * Companion structure for sde_debugfs_create_regset32. Do not initialize the
186 * members of this structure explicitly; use sde_debugfs_setup_regset32 instead.
187 */
188struct sde_debugfs_regset32 {
189 uint32_t offset;
190 uint32_t blk_len;
191 void __iomem *base;
192};
193
194/**
195 * sde_debugfs_setup_regset32 - Initialize register block definition for debugfs
196 * This function is meant to initialize sde_debugfs_regset32 structures for use
197 * with sde_debugfs_create_regset32.
198 * @regset: opaque register definition structure
199 * @offset: sub-block offset
200 * @length: sub-block length, in bytes
201 * @base: base IOMEM address
202 */
203void sde_debugfs_setup_regset32(struct sde_debugfs_regset32 *regset,
204 uint32_t offset, uint32_t length, void __iomem *base);
205
206/**
207 * sde_debugfs_create_regset32 - Create register read back file for debugfs
208 *
209 * This function is almost identical to the standard debugfs_create_regset32()
210 * function, with the main difference being that a list of register
211 * names/offsets do not need to be provided. The 'read' function simply outputs
212 * sequential register values over a specified range.
213 *
214 * Similar to the related debugfs_create_regset32 API, the structure pointed to
215 * by regset needs to persist for the lifetime of the created file. The calling
216 * code is responsible for initialization/management of this structure.
217 *
218 * The structure pointed to by regset is meant to be opaque. Please use
219 * sde_debugfs_setup_regset32 to initialize it.
220 *
221 * @name: File name within debugfs
222 * @mode: File mode within debugfs
223 * @parent: Parent directory entry within debugfs, can be NULL
224 * @regset: Pointer to persistent register block definition
225 *
226 * Return: dentry pointer for newly created file, use either debugfs_remove()
227 * or debugfs_remove_recursive() (on a parent directory) to remove the
228 * file
229 */
230void *sde_debugfs_create_regset32(const char *name, umode_t mode,
231 void *parent, struct sde_debugfs_regset32 *regset);
232
233/**
234 * sde_debugfs_get_root - Return root directory entry for SDE's debugfs
235 *
236 * The return value should be passed as the 'parent' argument to subsequent
237 * debugfs create calls.
238 *
239 * @sde_kms: Pointer to SDE's KMS structure
240 *
241 * Return: dentry pointer for SDE's debugfs location
242 */
243void *sde_debugfs_get_root(struct sde_kms *sde_kms);
244
245/**
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400246 * HW resource manager functions
247 * @sde_rm_acquire_ctl_path : Allocates control path
248 * @sde_rm_get_ctl_path : returns control path driver context for already
249 * acquired ctl path
250 * @sde_rm_release_ctl_path : Frees control path driver context
251 * @sde_rm_acquire_mixer : Allocates mixer hw driver context
252 * @sde_rm_get_mixer : returns mixer context for already
253 * acquired mixer
254 * @sde_rm_release_mixer : Frees mixer hw driver context
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -0400255 * @sde_rm_acquire_intr : Allocate hw intr context
256 * @sde_rm_get_intr : Returns already acquired intr context
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400257 * @sde_rm_get_hw_res_map : Returns map for the passed INTF
258 */
259struct sde_hw_ctl *sde_rm_acquire_ctl_path(struct sde_kms *sde_kms,
260 enum sde_ctl idx);
261struct sde_hw_ctl *sde_rm_get_ctl_path(struct sde_kms *sde_kms,
262 enum sde_ctl idx);
263void sde_rm_release_ctl_path(struct sde_kms *sde_kms,
264 enum sde_ctl idx);
265struct sde_hw_mixer *sde_rm_acquire_mixer(struct sde_kms *sde_kms,
266 enum sde_lm idx);
267struct sde_hw_mixer *sde_rm_get_mixer(struct sde_kms *sde_kms,
268 enum sde_lm idx);
269void sde_rm_release_mixer(struct sde_kms *sde_kms,
270 enum sde_lm idx);
271struct sde_hw_intr *sde_rm_acquire_intr(struct sde_kms *sde_kms);
272struct sde_hw_intr *sde_rm_get_intr(struct sde_kms *sde_kms);
273
274const struct sde_hw_res_map *sde_rm_get_res_map(struct sde_kms *sde_kms,
275 enum sde_intf idx);
276
277/**
Ben Chan78647cd2016-06-26 22:02:47 -0400278 * IRQ functions
279 */
280int sde_irq_domain_init(struct sde_kms *sde_kms);
281int sde_irq_domain_fini(struct sde_kms *sde_kms);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700282void sde_irq_preinstall(struct msm_kms *kms);
283int sde_irq_postinstall(struct msm_kms *kms);
284void sde_irq_uninstall(struct msm_kms *kms);
285irqreturn_t sde_irq(struct msm_kms *kms);
Ben Chan78647cd2016-06-26 22:02:47 -0400286
287/**
288 * sde_set_irqmask - IRQ helper function for writing IRQ mask
289 * to SDE HW interrupt register.
290 * @sde_kms: SDE handle
291 * @reg_off: SDE HW interrupt register offset
292 * @irqmask: IRQ mask
293 */
294void sde_set_irqmask(
295 struct sde_kms *sde_kms,
296 uint32_t reg_off,
297 uint32_t irqmask);
298
299/**
300 * sde_irq_idx_lookup - IRQ helper function for lookup irq_idx from HW
301 * interrupt mapping table.
302 * @sde_kms: SDE handle
303 * @intr_type: SDE HW interrupt type for lookup
304 * @instance_idx: SDE HW block instance defined in sde_hw_mdss.h
305 * @return: irq_idx or -EINVAL when fail to lookup
306 */
307int sde_irq_idx_lookup(
308 struct sde_kms *sde_kms,
309 enum sde_intr_type intr_type,
310 uint32_t instance_idx);
311
312/**
313 * sde_enable_irq - IRQ helper function for enabling one or more IRQs
314 * @sde_kms: SDE handle
315 * @irq_idxs: Array of irq index
316 * @irq_count: Number of irq_idx provided in the array
317 * @return: 0 for success enabling IRQ, otherwise failure
318 */
319int sde_enable_irq(
320 struct sde_kms *sde_kms,
321 int *irq_idxs,
322 uint32_t irq_count);
323
324/**
325 * sde_disable_irq - IRQ helper function for diabling one of more IRQs
326 * @sde_kms: SDE handle
327 * @irq_idxs: Array of irq index
328 * @irq_count: Number of irq_idx provided in the array
329 * @return: 0 for success disabling IRQ, otherwise failure
330 */
331int sde_disable_irq(
332 struct sde_kms *sde_kms,
333 int *irq_idxs,
334 uint32_t irq_count);
335
336/**
337 * sde_register_irq_callback - For registering callback function on IRQ
338 * interrupt
339 * @sde_kms: SDE handle
340 * @irq_idx: irq index
341 * @irq_cb: IRQ callback structure, containing callback function
342 * and argument. Passing NULL for irq_cb will unregister
343 * the callback for the given irq_idx
344 * @return: 0 for success registering callback, otherwise failure
345 */
346int sde_register_irq_callback(
347 struct sde_kms *sde_kms,
348 int irq_idx,
349 struct sde_irq_callback *irq_cb);
350
351/**
352 * sde_clear_all_irqs - Clearing all SDE IRQ interrupt status
353 * @sde_kms: SDE handle
354 */
355void sde_clear_all_irqs(struct sde_kms *sde_kms);
356
357/**
358 * sde_disable_all_irqs - Diabling all SDE IRQ interrupt
359 * @sde_kms: SDE handle
360 */
361void sde_disable_all_irqs(struct sde_kms *sde_kms);
362
363/**
364 * Vblank enable/disable functions
365 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700366int sde_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
367void sde_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
368
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400369/**
370 * Plane functions
371 */
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700372enum sde_sspp sde_plane_pipe(struct drm_plane *plane);
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400373struct drm_plane *sde_plane_init(struct drm_device *dev, uint32_t pipe,
Clarence Ip4c1d9772016-06-26 09:35:38 -0400374 bool primary_plane);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700375
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400376/**
377 * CRTC functions
378 */
Abhijit Kulkarni7acb3262016-07-05 15:27:25 -0400379int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400380void sde_crtc_wait_for_commit_done(struct drm_crtc *crtc);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700381void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700382struct drm_crtc *sde_crtc_init(struct drm_device *dev,
383 struct drm_encoder *encoder,
384 struct drm_plane *plane, int id);
385
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400386/**
387 * Encoder functions and data types
388 */
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400389struct sde_encoder_hw_resources {
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400390 enum sde_intf_mode intfs[INTF_MAX];
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400391 bool pingpongs[PINGPONG_MAX];
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400392 bool ctls[CTL_MAX];
393 bool pingpongsplit;
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400394};
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400395
Abhijit Kulkarni3e3e0d22016-06-24 17:56:13 -0400396void sde_encoder_get_hw_resources(struct drm_encoder *encoder,
397 struct sde_encoder_hw_resources *hw_res);
398void sde_encoder_register_vblank_callback(struct drm_encoder *drm_enc,
399 void (*cb)(void *), void *data);
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400400void sde_encoder_get_vblank_status(struct drm_encoder *encoder,
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400401 struct vsync_info *vsync);
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400402void sde_encoders_init(struct drm_device *dev);
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700403
Narendra Muppalla1b0b3352015-09-29 10:16:51 -0700404
405#endif /* __sde_kms_H__ */