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
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"
25 #include "dpu_core_perf.h"
27 #define DRMID(x) ((x) ? (x)->base.id : -1)
30 * DPU_DEBUG - macro for kms/plane/crtc/encoder/connector logs
31 * @fmt: Pointer to format string
33 #define DPU_DEBUG(fmt, ...) \
35 if (drm_debug_enabled(DRM_UT_KMS)) \
36 DRM_DEBUG(fmt, ##__VA_ARGS__); \
38 pr_debug(fmt, ##__VA_ARGS__); \
42 * DPU_DEBUG_DRIVER - macro for hardware driver logging
43 * @fmt: Pointer to format string
45 #define DPU_DEBUG_DRIVER(fmt, ...) \
47 if (drm_debug_enabled(DRM_UT_DRIVER)) \
48 DRM_ERROR(fmt, ##__VA_ARGS__); \
50 pr_debug(fmt, ##__VA_ARGS__); \
53 #define DPU_ERROR(fmt, ...) pr_err("[dpu error]" fmt, ##__VA_ARGS__)
56 * ktime_compare_safe - compare two ktime structures
57 * This macro is similar to the standard ktime_compare() function, but
58 * attempts to also handle ktime overflows.
59 * @A: First ktime value
60 * @B: Second ktime value
61 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
63 #define ktime_compare_safe(A, B) \
64 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
66 #define DPU_NAME_SIZE 12
70 struct drm_device *dev;
71 const struct dpu_mdss_cfg *catalog;
73 /* io/register spaces: */
74 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma;
76 struct regulator *vdd;
77 struct regulator *mmagic;
78 struct regulator *venus;
80 struct dpu_hw_intr *hw_intr;
82 struct dpu_core_perf perf;
85 * Global private object state, Do not access directly, use
86 * dpu_kms_global_get_state()
88 struct drm_modeset_lock global_state_lock;
89 struct drm_private_obj global_state;
94 struct dpu_hw_vbif *hw_vbif[VBIF_MAX];
95 struct dpu_hw_mdp *hw_mdp;
99 struct platform_device *pdev;
102 struct clk_bulk_data *clocks;
105 /* reference count bandwidth requests, so we know when we can
106 * release bandwidth. Each atomic update increments, and frame-
107 * done event decrements. Additionally, for video mode, the
108 * reference is incremented when crtc is enabled, and decremented
111 atomic_t bandwidth_ref;
112 struct icc_path *path[2];
121 #define to_dpu_kms(x) container_of(x, struct dpu_kms, base)
123 #define to_dpu_global_state(x) container_of(x, struct dpu_global_state, base)
125 /* Global private object state for tracking resources that are shared across
126 * multiple kms objects (planes/crtcs/etc).
128 struct dpu_global_state {
129 struct drm_private_state base;
131 uint32_t pingpong_to_enc_id[PINGPONG_MAX - PINGPONG_0];
132 uint32_t mixer_to_enc_id[LM_MAX - LM_0];
133 uint32_t ctl_to_enc_id[CTL_MAX - CTL_0];
134 uint32_t dspp_to_enc_id[DSPP_MAX - DSPP_0];
135 uint32_t dsc_to_enc_id[DSC_MAX - DSC_0];
138 struct dpu_global_state
139 *dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms);
140 struct dpu_global_state
141 *__must_check dpu_kms_get_global_state(struct drm_atomic_state *s);
144 * Debugfs functions - extra helper functions for debugfs support
146 * Main debugfs documentation is located at,
148 * Documentation/filesystems/debugfs.rst
150 * @dpu_debugfs_create_regset32: Create 32-bit register dump file
154 * dpu_debugfs_create_regset32 - Create register read back file for debugfs
156 * This function is almost identical to the standard debugfs_create_regset32()
157 * function, with the main difference being that a list of register
158 * names/offsets do not need to be provided. The 'read' function simply outputs
159 * sequential register values over a specified range.
161 * @name: File name within debugfs
162 * @mode: File mode within debugfs
163 * @parent: Parent directory entry within debugfs, can be NULL
164 * @offset: sub-block offset
165 * @length: sub-block length, in bytes
166 * @dpu_kms: pointer to dpu kms structure
168 void dpu_debugfs_create_regset32(const char *name, umode_t mode,
170 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms);
173 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs
175 * The return value should be passed as the 'parent' argument to subsequent
176 * debugfs create calls.
178 * @dpu_kms: Pointer to DPU's KMS structure
180 * Return: dentry pointer for DPU's debugfs location
182 void *dpu_debugfs_get_root(struct dpu_kms *dpu_kms);
185 * DPU info management functions
186 * These functions/definitions allow for building up a 'dpu_info' structure
187 * containing one or more "key=value\n" entries.
189 #define DPU_KMS_INFO_MAX_SIZE 4096
192 * Vblank enable/disable functions
194 int dpu_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
195 void dpu_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
198 * dpu_kms_get_clk_rate() - get the clock rate
199 * @dpu_kms: pointer to dpu_kms structure
200 * @clock_name: clock name to get the rate
202 * Return: current clock rate
204 u64 dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name);
206 #endif /* __dpu_kms_H__ */