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, ...) \
34 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
37 * DPU_DEBUG_DRIVER - macro for hardware driver logging
38 * @fmt: Pointer to format string
40 #define DPU_DEBUG_DRIVER(fmt, ...) \
41 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
43 #define DPU_ERROR(fmt, ...) pr_err("[dpu error]" fmt, ##__VA_ARGS__)
44 #define DPU_ERROR_RATELIMITED(fmt, ...) pr_err_ratelimited("[dpu error]" fmt, ##__VA_ARGS__)
47 * ktime_compare_safe - compare two ktime structures
48 * This macro is similar to the standard ktime_compare() function, but
49 * attempts to also handle ktime overflows.
50 * @A: First ktime value
51 * @B: Second ktime value
52 * Returns: -1 if A < B, 0 if A == B, 1 if A > B
54 #define ktime_compare_safe(A, B) \
55 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
59 struct drm_device *dev;
60 const struct dpu_mdss_cfg *catalog;
61 const struct msm_mdss_data *mdss;
63 /* io/register spaces: */
64 void __iomem *mmio, *vbif[VBIF_MAX];
66 struct regulator *vdd;
67 struct regulator *mmagic;
68 struct regulator *venus;
70 struct dpu_hw_intr *hw_intr;
72 struct dpu_core_perf perf;
75 * Global private object state, Do not access directly, use
76 * dpu_kms_global_get_state()
78 struct drm_private_obj global_state;
82 struct dpu_hw_vbif *hw_vbif[VBIF_MAX];
83 struct dpu_hw_mdp *hw_mdp;
87 struct platform_device *pdev;
90 struct clk_bulk_data *clocks;
93 /* reference count bandwidth requests, so we know when we can
94 * release bandwidth. Each atomic update increments, and frame-
95 * done event decrements. Additionally, for video mode, the
96 * reference is incremented when crtc is enabled, and decremented
99 atomic_t bandwidth_ref;
100 struct icc_path *path[2];
109 #define DPU_ENC_WR_PTR_START_TIMEOUT_US 20000
111 #define DPU_ENC_MAX_POLL_TIMEOUT_US 2000
113 #define to_dpu_kms(x) container_of(x, struct dpu_kms, base)
115 #define to_dpu_global_state(x) container_of(x, struct dpu_global_state, base)
117 /* Global private object state for tracking resources that are shared across
118 * multiple kms objects (planes/crtcs/etc).
120 struct dpu_global_state {
121 struct drm_private_state base;
125 uint32_t pingpong_to_enc_id[PINGPONG_MAX - PINGPONG_0];
126 uint32_t mixer_to_enc_id[LM_MAX - LM_0];
127 uint32_t ctl_to_enc_id[CTL_MAX - CTL_0];
128 uint32_t dspp_to_enc_id[DSPP_MAX - DSPP_0];
129 uint32_t dsc_to_enc_id[DSC_MAX - DSC_0];
130 uint32_t cdm_to_enc_id;
133 struct dpu_global_state
134 *dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms);
135 struct dpu_global_state
136 *__must_check dpu_kms_get_global_state(struct drm_atomic_state *s);
139 * Debugfs functions - extra helper functions for debugfs support
141 * Main debugfs documentation is located at,
143 * Documentation/filesystems/debugfs.rst
145 * @dpu_debugfs_create_regset32: Create 32-bit register dump file
149 * dpu_debugfs_create_regset32 - Create register read back file for debugfs
151 * This function is almost identical to the standard debugfs_create_regset32()
152 * function, with the main difference being that a list of register
153 * names/offsets do not need to be provided. The 'read' function simply outputs
154 * sequential register values over a specified range.
156 * @name: File name within debugfs
157 * @mode: File mode within debugfs
158 * @parent: Parent directory entry within debugfs, can be NULL
159 * @offset: sub-block offset
160 * @length: sub-block length, in bytes
161 * @dpu_kms: pointer to dpu kms structure
163 void dpu_debugfs_create_regset32(const char *name, umode_t mode,
165 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms);
168 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs
170 * The return value should be passed as the 'parent' argument to subsequent
171 * debugfs create calls.
173 * @dpu_kms: Pointer to DPU's KMS structure
175 * Return: dentry pointer for DPU's debugfs location
177 void *dpu_debugfs_get_root(struct dpu_kms *dpu_kms);
180 * DPU info management functions
181 * These functions/definitions allow for building up a 'dpu_info' structure
182 * containing one or more "key=value\n" entries.
184 #define DPU_KMS_INFO_MAX_SIZE 4096
187 * Vblank enable/disable functions
189 int dpu_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
190 void dpu_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
193 * dpu_kms_get_clk_rate() - get the clock rate
194 * @dpu_kms: pointer to dpu_kms structure
195 * @clock_name: clock name to get the rate
197 * Return: current clock rate
199 unsigned long dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name);
201 #endif /* __dpu_kms_H__ */