1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
11 #include <linux/interconnect.h>
13 #include <drm/drm_drv.h>
19 #include "dpu_hw_catalog.h"
20 #include "dpu_hw_ctl.h"
21 #include "dpu_hw_lm.h"
22 #include "dpu_hw_interrupts.h"
23 #include "dpu_hw_top.h"
24 #include "dpu_io_util.h"
26 #include "dpu_core_perf.h"
28 #define DRMID(x) ((x) ? (x)->base.id : -1)
31 * DPU_DEBUG - macro for kms/plane/crtc/encoder/connector logs
32 * @fmt: Pointer to format string
34 #define DPU_DEBUG(fmt, ...) \
36 if (drm_debug_enabled(DRM_UT_KMS)) \
37 DRM_DEBUG(fmt, ##__VA_ARGS__); \
39 pr_debug(fmt, ##__VA_ARGS__); \
43 * DPU_DEBUG_DRIVER - macro for hardware driver logging
44 * @fmt: Pointer to format string
46 #define DPU_DEBUG_DRIVER(fmt, ...) \
48 if (drm_debug_enabled(DRM_UT_DRIVER)) \
49 DRM_ERROR(fmt, ##__VA_ARGS__); \
51 pr_debug(fmt, ##__VA_ARGS__); \
54 #define DPU_ERROR(fmt, ...) pr_err("[dpu error]" fmt, ##__VA_ARGS__)
57 * ktime_compare_safe - compare two ktime structures
58 * This macro is similar to the standard ktime_compare() function, but
59 * attempts to also handle ktime overflows.
60 * @A: First ktime value
61 * @B: Second ktime value
62 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
64 #define ktime_compare_safe(A, B) \
65 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
67 #define DPU_NAME_SIZE 12
70 * struct dpu_irq_callback - IRQ callback handlers
71 * @list: list to callback
73 * @arg: argument for the handler
75 struct dpu_irq_callback
{
76 struct list_head list
;
77 void (*func
)(void *arg
, int irq_idx
);
82 * struct dpu_irq: IRQ structure contains callback registration info
83 * @total_irq: total number of irq_idx obtained from HW interrupts mapping
84 * @irq_cb_tbl: array of IRQ callbacks setting
85 * @enable_counts array of IRQ enable counts
86 * @cb_lock: callback lock
87 * @debugfs_file: debugfs file for irq statistics
91 struct list_head
*irq_cb_tbl
;
92 atomic_t
*enable_counts
;
99 struct drm_device
*dev
;
101 struct dpu_mdss_cfg
*catalog
;
103 /* io/register spaces: */
104 void __iomem
*mmio
, *vbif
[VBIF_MAX
], *reg_dma
;
106 struct regulator
*vdd
;
107 struct regulator
*mmagic
;
108 struct regulator
*venus
;
110 struct dpu_hw_intr
*hw_intr
;
111 struct dpu_irq irq_obj
;
113 struct dpu_core_perf perf
;
116 * Global private object state, Do not access directly, use
117 * dpu_kms_global_get_state()
119 struct drm_modeset_lock global_state_lock
;
120 struct drm_private_obj global_state
;
125 struct dpu_hw_vbif
*hw_vbif
[VBIF_MAX
];
126 struct dpu_hw_mdp
*hw_mdp
;
128 bool has_danger_ctrl
;
130 struct platform_device
*pdev
;
133 struct opp_table
*opp_table
;
135 struct dss_module_power mp
;
137 /* reference count bandwidth requests, so we know when we can
138 * release bandwidth. Each atomic update increments, and frame-
139 * done event decrements. Additionally, for video mode, the
140 * reference is incremented when crtc is enabled, and decremented
143 atomic_t bandwidth_ref
;
144 struct icc_path
*path
[2];
153 #define to_dpu_kms(x) container_of(x, struct dpu_kms, base)
155 #define to_dpu_global_state(x) container_of(x, struct dpu_global_state, base)
157 /* Global private object state for tracking resources that are shared across
158 * multiple kms objects (planes/crtcs/etc).
160 struct dpu_global_state
{
161 struct drm_private_state base
;
163 uint32_t pingpong_to_enc_id
[PINGPONG_MAX
- PINGPONG_0
];
164 uint32_t mixer_to_enc_id
[LM_MAX
- LM_0
];
165 uint32_t ctl_to_enc_id
[CTL_MAX
- CTL_0
];
166 uint32_t intf_to_enc_id
[INTF_MAX
- INTF_0
];
167 uint32_t dspp_to_enc_id
[DSPP_MAX
- DSPP_0
];
170 struct dpu_global_state
171 *dpu_kms_get_existing_global_state(struct dpu_kms
*dpu_kms
);
172 struct dpu_global_state
173 *__must_check
dpu_kms_get_global_state(struct drm_atomic_state
*s
);
176 * Debugfs functions - extra helper functions for debugfs support
178 * Main debugfs documentation is located at,
180 * Documentation/filesystems/debugfs.rst
182 * @dpu_debugfs_setup_regset32: Initialize data for dpu_debugfs_create_regset32
183 * @dpu_debugfs_create_regset32: Create 32-bit register dump file
184 * @dpu_debugfs_get_root: Get root dentry for DPU_KMS's debugfs node
188 * Companion structure for dpu_debugfs_create_regset32. Do not initialize the
189 * members of this structure explicitly; use dpu_debugfs_setup_regset32 instead.
191 struct dpu_debugfs_regset32
{
194 struct dpu_kms
*dpu_kms
;
198 * dpu_debugfs_setup_regset32 - Initialize register block definition for debugfs
199 * This function is meant to initialize dpu_debugfs_regset32 structures for use
200 * with dpu_debugfs_create_regset32.
201 * @regset: opaque register definition structure
202 * @offset: sub-block offset
203 * @length: sub-block length, in bytes
204 * @dpu_kms: pointer to dpu kms structure
206 void dpu_debugfs_setup_regset32(struct dpu_debugfs_regset32
*regset
,
207 uint32_t offset
, uint32_t length
, struct dpu_kms
*dpu_kms
);
210 * dpu_debugfs_create_regset32 - Create register read back file for debugfs
212 * This function is almost identical to the standard debugfs_create_regset32()
213 * function, with the main difference being that a list of register
214 * names/offsets do not need to be provided. The 'read' function simply outputs
215 * sequential register values over a specified range.
217 * Similar to the related debugfs_create_regset32 API, the structure pointed to
218 * by regset needs to persist for the lifetime of the created file. The calling
219 * code is responsible for initialization/management of this structure.
221 * The structure pointed to by regset is meant to be opaque. Please use
222 * dpu_debugfs_setup_regset32 to initialize it.
224 * @name: File name within debugfs
225 * @mode: File mode within debugfs
226 * @parent: Parent directory entry within debugfs, can be NULL
227 * @regset: Pointer to persistent register block definition
229 void dpu_debugfs_create_regset32(const char *name
, umode_t mode
,
230 void *parent
, struct dpu_debugfs_regset32
*regset
);
233 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs
235 * The return value should be passed as the 'parent' argument to subsequent
236 * debugfs create calls.
238 * @dpu_kms: Pointer to DPU's KMS structure
240 * Return: dentry pointer for DPU's debugfs location
242 void *dpu_debugfs_get_root(struct dpu_kms
*dpu_kms
);
245 * DPU info management functions
246 * These functions/definitions allow for building up a 'dpu_info' structure
247 * containing one or more "key=value\n" entries.
249 #define DPU_KMS_INFO_MAX_SIZE 4096
252 * Vblank enable/disable functions
254 int dpu_enable_vblank(struct msm_kms
*kms
, struct drm_crtc
*crtc
);
255 void dpu_disable_vblank(struct msm_kms
*kms
, struct drm_crtc
*crtc
);
257 void dpu_kms_encoder_enable(struct drm_encoder
*encoder
);
260 * dpu_kms_get_clk_rate() - get the clock rate
261 * @dpu_kms: poiner to dpu_kms structure
262 * @clock_name: clock name to get the rate
264 * Return: current clock rate
266 u64
dpu_kms_get_clk_rate(struct dpu_kms
*dpu_kms
, char *clock_name
);
268 #endif /* __dpu_kms_H__ */