1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
6 */
7
8 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
9
10 #include <linux/debugfs.h>
11 #include <linux/dma-buf.h>
12 #include <linux/of_irq.h>
13 #include <linux/pm_opp.h>
14
15 #include <drm/drm_crtc.h>
16 #include <drm/drm_file.h>
17 #include <drm/drm_vblank.h>
18
19 #include "msm_drv.h"
20 #include "msm_mmu.h"
21 #include "msm_gem.h"
22 #include "disp/msm_disp_snapshot.h"
23
24 #include "dpu_kms.h"
25 #include "dpu_core_irq.h"
26 #include "dpu_formats.h"
27 #include "dpu_hw_vbif.h"
28 #include "dpu_vbif.h"
29 #include "dpu_encoder.h"
30 #include "dpu_plane.h"
31 #include "dpu_crtc.h"
32
33 #define CREATE_TRACE_POINTS
34 #include "dpu_trace.h"
35
36 /*
37 * To enable overall DRM driver logging
38 * # echo 0x2 > /sys/module/drm/parameters/debug
39 *
40 * To enable DRM driver h/w logging
41 * # echo <mask> > /sys/kernel/debug/dri/0/debug/hw_log_mask
42 *
43 * See dpu_hw_mdss.h for h/w logging mask definitions (search for DPU_DBG_MASK_)
44 */
45 #define DPU_DEBUGFS_DIR "msm_dpu"
46 #define DPU_DEBUGFS_HWMASKNAME "hw_log_mask"
47
48 #define MIN_IB_BW 400000000ULL /* Min ib vote 400MB */
49
50 static int dpu_kms_hw_init(struct msm_kms *kms);
51 static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms);
52
53 #ifdef CONFIG_DEBUG_FS
_dpu_danger_signal_status(struct seq_file * s,bool danger_status)54 static int _dpu_danger_signal_status(struct seq_file *s,
55 bool danger_status)
56 {
57 struct dpu_kms *kms = (struct dpu_kms *)s->private;
58 struct dpu_danger_safe_status status;
59 int i;
60
61 if (!kms->hw_mdp) {
62 DPU_ERROR("invalid arg(s)\n");
63 return 0;
64 }
65
66 memset(&status, 0, sizeof(struct dpu_danger_safe_status));
67
68 pm_runtime_get_sync(&kms->pdev->dev);
69 if (danger_status) {
70 seq_puts(s, "\nDanger signal status:\n");
71 if (kms->hw_mdp->ops.get_danger_status)
72 kms->hw_mdp->ops.get_danger_status(kms->hw_mdp,
73 &status);
74 } else {
75 seq_puts(s, "\nSafe signal status:\n");
76 if (kms->hw_mdp->ops.get_safe_status)
77 kms->hw_mdp->ops.get_safe_status(kms->hw_mdp,
78 &status);
79 }
80 pm_runtime_put_sync(&kms->pdev->dev);
81
82 seq_printf(s, "MDP : 0x%x\n", status.mdp);
83
84 for (i = SSPP_VIG0; i < SSPP_MAX; i++)
85 seq_printf(s, "SSPP%d : 0x%x \t", i - SSPP_VIG0,
86 status.sspp[i]);
87 seq_puts(s, "\n");
88
89 return 0;
90 }
91
dpu_debugfs_danger_stats_show(struct seq_file * s,void * v)92 static int dpu_debugfs_danger_stats_show(struct seq_file *s, void *v)
93 {
94 return _dpu_danger_signal_status(s, true);
95 }
96 DEFINE_SHOW_ATTRIBUTE(dpu_debugfs_danger_stats);
97
dpu_debugfs_safe_stats_show(struct seq_file * s,void * v)98 static int dpu_debugfs_safe_stats_show(struct seq_file *s, void *v)
99 {
100 return _dpu_danger_signal_status(s, false);
101 }
102 DEFINE_SHOW_ATTRIBUTE(dpu_debugfs_safe_stats);
103
dpu_debugfs_danger_init(struct dpu_kms * dpu_kms,struct dentry * parent)104 static void dpu_debugfs_danger_init(struct dpu_kms *dpu_kms,
105 struct dentry *parent)
106 {
107 struct dentry *entry = debugfs_create_dir("danger", parent);
108
109 debugfs_create_file("danger_status", 0600, entry,
110 dpu_kms, &dpu_debugfs_danger_stats_fops);
111 debugfs_create_file("safe_status", 0600, entry,
112 dpu_kms, &dpu_debugfs_safe_stats_fops);
113 }
114
_dpu_debugfs_show_regset32(struct seq_file * s,void * data)115 static int _dpu_debugfs_show_regset32(struct seq_file *s, void *data)
116 {
117 struct dpu_debugfs_regset32 *regset = s->private;
118 struct dpu_kms *dpu_kms = regset->dpu_kms;
119 void __iomem *base;
120 uint32_t i, addr;
121
122 if (!dpu_kms->mmio)
123 return 0;
124
125 base = dpu_kms->mmio + regset->offset;
126
127 /* insert padding spaces, if needed */
128 if (regset->offset & 0xF) {
129 seq_printf(s, "[%x]", regset->offset & ~0xF);
130 for (i = 0; i < (regset->offset & 0xF); i += 4)
131 seq_puts(s, " ");
132 }
133
134 pm_runtime_get_sync(&dpu_kms->pdev->dev);
135
136 /* main register output */
137 for (i = 0; i < regset->blk_len; i += 4) {
138 addr = regset->offset + i;
139 if ((addr & 0xF) == 0x0)
140 seq_printf(s, i ? "\n[%x]" : "[%x]", addr);
141 seq_printf(s, " %08x", readl_relaxed(base + i));
142 }
143 seq_puts(s, "\n");
144 pm_runtime_put_sync(&dpu_kms->pdev->dev);
145
146 return 0;
147 }
148
dpu_debugfs_open_regset32(struct inode * inode,struct file * file)149 static int dpu_debugfs_open_regset32(struct inode *inode,
150 struct file *file)
151 {
152 return single_open(file, _dpu_debugfs_show_regset32, inode->i_private);
153 }
154
155 static const struct file_operations dpu_fops_regset32 = {
156 .open = dpu_debugfs_open_regset32,
157 .read = seq_read,
158 .llseek = seq_lseek,
159 .release = single_release,
160 };
161
dpu_debugfs_setup_regset32(struct dpu_debugfs_regset32 * regset,uint32_t offset,uint32_t length,struct dpu_kms * dpu_kms)162 void dpu_debugfs_setup_regset32(struct dpu_debugfs_regset32 *regset,
163 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms)
164 {
165 if (regset) {
166 regset->offset = offset;
167 regset->blk_len = length;
168 regset->dpu_kms = dpu_kms;
169 }
170 }
171
dpu_debugfs_create_regset32(const char * name,umode_t mode,void * parent,struct dpu_debugfs_regset32 * regset)172 void dpu_debugfs_create_regset32(const char *name, umode_t mode,
173 void *parent, struct dpu_debugfs_regset32 *regset)
174 {
175 if (!name || !regset || !regset->dpu_kms || !regset->blk_len)
176 return;
177
178 /* make sure offset is a multiple of 4 */
179 regset->offset = round_down(regset->offset, 4);
180
181 debugfs_create_file(name, mode, parent, regset, &dpu_fops_regset32);
182 }
183
dpu_kms_debugfs_init(struct msm_kms * kms,struct drm_minor * minor)184 static int dpu_kms_debugfs_init(struct msm_kms *kms, struct drm_minor *minor)
185 {
186 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
187 void *p = dpu_hw_util_get_log_mask_ptr();
188 struct dentry *entry;
189 struct drm_device *dev;
190 struct msm_drm_private *priv;
191
192 if (!p)
193 return -EINVAL;
194
195 dev = dpu_kms->dev;
196 priv = dev->dev_private;
197
198 entry = debugfs_create_dir("debug", minor->debugfs_root);
199
200 debugfs_create_x32(DPU_DEBUGFS_HWMASKNAME, 0600, entry, p);
201
202 dpu_debugfs_danger_init(dpu_kms, entry);
203 dpu_debugfs_vbif_init(dpu_kms, entry);
204 dpu_debugfs_core_irq_init(dpu_kms, entry);
205
206 if (priv->dp)
207 msm_dp_debugfs_init(priv->dp, minor);
208
209 return dpu_core_perf_debugfs_init(dpu_kms, entry);
210 }
211 #endif
212
213 /* Global/shared object state funcs */
214
215 /*
216 * This is a helper that returns the private state currently in operation.
217 * Note that this would return the "old_state" if called in the atomic check
218 * path, and the "new_state" after the atomic swap has been done.
219 */
220 struct dpu_global_state *
dpu_kms_get_existing_global_state(struct dpu_kms * dpu_kms)221 dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms)
222 {
223 return to_dpu_global_state(dpu_kms->global_state.state);
224 }
225
226 /*
227 * This acquires the modeset lock set aside for global state, creates
228 * a new duplicated private object state.
229 */
dpu_kms_get_global_state(struct drm_atomic_state * s)230 struct dpu_global_state *dpu_kms_get_global_state(struct drm_atomic_state *s)
231 {
232 struct msm_drm_private *priv = s->dev->dev_private;
233 struct dpu_kms *dpu_kms = to_dpu_kms(priv->kms);
234 struct drm_private_state *priv_state;
235 int ret;
236
237 ret = drm_modeset_lock(&dpu_kms->global_state_lock, s->acquire_ctx);
238 if (ret)
239 return ERR_PTR(ret);
240
241 priv_state = drm_atomic_get_private_obj_state(s,
242 &dpu_kms->global_state);
243 if (IS_ERR(priv_state))
244 return ERR_CAST(priv_state);
245
246 return to_dpu_global_state(priv_state);
247 }
248
249 static struct drm_private_state *
dpu_kms_global_duplicate_state(struct drm_private_obj * obj)250 dpu_kms_global_duplicate_state(struct drm_private_obj *obj)
251 {
252 struct dpu_global_state *state;
253
254 state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL);
255 if (!state)
256 return NULL;
257
258 __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
259
260 return &state->base;
261 }
262
dpu_kms_global_destroy_state(struct drm_private_obj * obj,struct drm_private_state * state)263 static void dpu_kms_global_destroy_state(struct drm_private_obj *obj,
264 struct drm_private_state *state)
265 {
266 struct dpu_global_state *dpu_state = to_dpu_global_state(state);
267
268 kfree(dpu_state);
269 }
270
271 static const struct drm_private_state_funcs dpu_kms_global_state_funcs = {
272 .atomic_duplicate_state = dpu_kms_global_duplicate_state,
273 .atomic_destroy_state = dpu_kms_global_destroy_state,
274 };
275
dpu_kms_global_obj_init(struct dpu_kms * dpu_kms)276 static int dpu_kms_global_obj_init(struct dpu_kms *dpu_kms)
277 {
278 struct dpu_global_state *state;
279
280 drm_modeset_lock_init(&dpu_kms->global_state_lock);
281
282 state = kzalloc(sizeof(*state), GFP_KERNEL);
283 if (!state)
284 return -ENOMEM;
285
286 drm_atomic_private_obj_init(dpu_kms->dev, &dpu_kms->global_state,
287 &state->base,
288 &dpu_kms_global_state_funcs);
289 return 0;
290 }
291
dpu_kms_parse_data_bus_icc_path(struct dpu_kms * dpu_kms)292 static int dpu_kms_parse_data_bus_icc_path(struct dpu_kms *dpu_kms)
293 {
294 struct icc_path *path0;
295 struct icc_path *path1;
296 struct drm_device *dev = dpu_kms->dev;
297
298 path0 = of_icc_get(dev->dev, "mdp0-mem");
299 path1 = of_icc_get(dev->dev, "mdp1-mem");
300
301 if (IS_ERR_OR_NULL(path0))
302 return PTR_ERR_OR_ZERO(path0);
303
304 dpu_kms->path[0] = path0;
305 dpu_kms->num_paths = 1;
306
307 if (!IS_ERR_OR_NULL(path1)) {
308 dpu_kms->path[1] = path1;
309 dpu_kms->num_paths++;
310 }
311 return 0;
312 }
313
dpu_kms_enable_vblank(struct msm_kms * kms,struct drm_crtc * crtc)314 static int dpu_kms_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
315 {
316 return dpu_crtc_vblank(crtc, true);
317 }
318
dpu_kms_disable_vblank(struct msm_kms * kms,struct drm_crtc * crtc)319 static void dpu_kms_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
320 {
321 dpu_crtc_vblank(crtc, false);
322 }
323
dpu_kms_enable_commit(struct msm_kms * kms)324 static void dpu_kms_enable_commit(struct msm_kms *kms)
325 {
326 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
327 pm_runtime_get_sync(&dpu_kms->pdev->dev);
328 }
329
dpu_kms_disable_commit(struct msm_kms * kms)330 static void dpu_kms_disable_commit(struct msm_kms *kms)
331 {
332 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
333 pm_runtime_put_sync(&dpu_kms->pdev->dev);
334 }
335
dpu_kms_vsync_time(struct msm_kms * kms,struct drm_crtc * crtc)336 static ktime_t dpu_kms_vsync_time(struct msm_kms *kms, struct drm_crtc *crtc)
337 {
338 struct drm_encoder *encoder;
339
340 drm_for_each_encoder_mask(encoder, crtc->dev, crtc->state->encoder_mask) {
341 ktime_t vsync_time;
342
343 if (dpu_encoder_vsync_time(encoder, &vsync_time) == 0)
344 return vsync_time;
345 }
346
347 return ktime_get();
348 }
349
dpu_kms_prepare_commit(struct msm_kms * kms,struct drm_atomic_state * state)350 static void dpu_kms_prepare_commit(struct msm_kms *kms,
351 struct drm_atomic_state *state)
352 {
353 struct drm_crtc *crtc;
354 struct drm_crtc_state *crtc_state;
355 struct drm_encoder *encoder;
356 int i;
357
358 if (!kms)
359 return;
360
361 /* Call prepare_commit for all affected encoders */
362 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
363 drm_for_each_encoder_mask(encoder, crtc->dev,
364 crtc_state->encoder_mask) {
365 dpu_encoder_prepare_commit(encoder);
366 }
367 }
368 }
369
dpu_kms_flush_commit(struct msm_kms * kms,unsigned crtc_mask)370 static void dpu_kms_flush_commit(struct msm_kms *kms, unsigned crtc_mask)
371 {
372 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
373 struct drm_crtc *crtc;
374
375 for_each_crtc_mask(dpu_kms->dev, crtc, crtc_mask) {
376 if (!crtc->state->active)
377 continue;
378
379 trace_dpu_kms_commit(DRMID(crtc));
380 dpu_crtc_commit_kickoff(crtc);
381 }
382 }
383
384 /*
385 * Override the encoder enable since we need to setup the inline rotator and do
386 * some crtc magic before enabling any bridge that might be present.
387 */
dpu_kms_encoder_enable(struct drm_encoder * encoder)388 void dpu_kms_encoder_enable(struct drm_encoder *encoder)
389 {
390 const struct drm_encoder_helper_funcs *funcs = encoder->helper_private;
391 struct drm_device *dev = encoder->dev;
392 struct drm_crtc *crtc;
393
394 /* Forward this enable call to the commit hook */
395 if (funcs && funcs->commit)
396 funcs->commit(encoder);
397
398 drm_for_each_crtc(crtc, dev) {
399 if (!(crtc->state->encoder_mask & drm_encoder_mask(encoder)))
400 continue;
401
402 trace_dpu_kms_enc_enable(DRMID(crtc));
403 }
404 }
405
dpu_kms_complete_commit(struct msm_kms * kms,unsigned crtc_mask)406 static void dpu_kms_complete_commit(struct msm_kms *kms, unsigned crtc_mask)
407 {
408 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
409 struct drm_crtc *crtc;
410
411 DPU_ATRACE_BEGIN("kms_complete_commit");
412
413 for_each_crtc_mask(dpu_kms->dev, crtc, crtc_mask)
414 dpu_crtc_complete_commit(crtc);
415
416 DPU_ATRACE_END("kms_complete_commit");
417 }
418
dpu_kms_wait_for_commit_done(struct msm_kms * kms,struct drm_crtc * crtc)419 static void dpu_kms_wait_for_commit_done(struct msm_kms *kms,
420 struct drm_crtc *crtc)
421 {
422 struct drm_encoder *encoder;
423 struct drm_device *dev;
424 int ret;
425
426 if (!kms || !crtc || !crtc->state) {
427 DPU_ERROR("invalid params\n");
428 return;
429 }
430
431 dev = crtc->dev;
432
433 if (!crtc->state->enable) {
434 DPU_DEBUG("[crtc:%d] not enable\n", crtc->base.id);
435 return;
436 }
437
438 if (!crtc->state->active) {
439 DPU_DEBUG("[crtc:%d] not active\n", crtc->base.id);
440 return;
441 }
442
443 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
444 if (encoder->crtc != crtc)
445 continue;
446 /*
447 * Wait for post-flush if necessary to delay before
448 * plane_cleanup. For example, wait for vsync in case of video
449 * mode panels. This may be a no-op for command mode panels.
450 */
451 trace_dpu_kms_wait_for_commit_done(DRMID(crtc));
452 ret = dpu_encoder_wait_for_event(encoder, MSM_ENC_COMMIT_DONE);
453 if (ret && ret != -EWOULDBLOCK) {
454 DPU_ERROR("wait for commit done returned %d\n", ret);
455 break;
456 }
457 }
458 }
459
dpu_kms_wait_flush(struct msm_kms * kms,unsigned crtc_mask)460 static void dpu_kms_wait_flush(struct msm_kms *kms, unsigned crtc_mask)
461 {
462 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
463 struct drm_crtc *crtc;
464
465 for_each_crtc_mask(dpu_kms->dev, crtc, crtc_mask)
466 dpu_kms_wait_for_commit_done(kms, crtc);
467 }
468
_dpu_kms_initialize_dsi(struct drm_device * dev,struct msm_drm_private * priv,struct dpu_kms * dpu_kms)469 static int _dpu_kms_initialize_dsi(struct drm_device *dev,
470 struct msm_drm_private *priv,
471 struct dpu_kms *dpu_kms)
472 {
473 struct drm_encoder *encoder = NULL;
474 struct msm_display_info info;
475 int i, rc = 0;
476
477 if (!(priv->dsi[0] || priv->dsi[1]))
478 return rc;
479
480 /*
481 * We support following confiurations:
482 * - Single DSI host (dsi0 or dsi1)
483 * - Two independent DSI hosts
484 * - Bonded DSI0 and DSI1 hosts
485 *
486 * TODO: Support swapping DSI0 and DSI1 in the bonded setup.
487 */
488 for (i = 0; i < ARRAY_SIZE(priv->dsi); i++) {
489 int other = (i + 1) % 2;
490
491 if (!priv->dsi[i])
492 continue;
493
494 if (msm_dsi_is_bonded_dsi(priv->dsi[i]) &&
495 !msm_dsi_is_master_dsi(priv->dsi[i]))
496 continue;
497
498 encoder = dpu_encoder_init(dev, DRM_MODE_ENCODER_DSI);
499 if (IS_ERR(encoder)) {
500 DPU_ERROR("encoder init failed for dsi display\n");
501 return PTR_ERR(encoder);
502 }
503
504 priv->encoders[priv->num_encoders++] = encoder;
505
506 memset(&info, 0, sizeof(info));
507 info.intf_type = encoder->encoder_type;
508
509 rc = msm_dsi_modeset_init(priv->dsi[i], dev, encoder);
510 if (rc) {
511 DPU_ERROR("modeset_init failed for dsi[%d], rc = %d\n",
512 i, rc);
513 break;
514 }
515
516 info.h_tile_instance[info.num_of_h_tiles++] = i;
517 info.capabilities = msm_dsi_is_cmd_mode(priv->dsi[i]) ?
518 MSM_DISPLAY_CAP_CMD_MODE :
519 MSM_DISPLAY_CAP_VID_MODE;
520
521 if (msm_dsi_is_bonded_dsi(priv->dsi[i]) && priv->dsi[other]) {
522 rc = msm_dsi_modeset_init(priv->dsi[other], dev, encoder);
523 if (rc) {
524 DPU_ERROR("modeset_init failed for dsi[%d], rc = %d\n",
525 other, rc);
526 break;
527 }
528
529 info.h_tile_instance[info.num_of_h_tiles++] = other;
530 }
531
532 rc = dpu_encoder_setup(dev, encoder, &info);
533 if (rc)
534 DPU_ERROR("failed to setup DPU encoder %d: rc:%d\n",
535 encoder->base.id, rc);
536 }
537
538 return rc;
539 }
540
_dpu_kms_initialize_displayport(struct drm_device * dev,struct msm_drm_private * priv,struct dpu_kms * dpu_kms)541 static int _dpu_kms_initialize_displayport(struct drm_device *dev,
542 struct msm_drm_private *priv,
543 struct dpu_kms *dpu_kms)
544 {
545 struct drm_encoder *encoder = NULL;
546 struct msm_display_info info;
547 int rc = 0;
548
549 if (!priv->dp)
550 return rc;
551
552 encoder = dpu_encoder_init(dev, DRM_MODE_ENCODER_TMDS);
553 if (IS_ERR(encoder)) {
554 DPU_ERROR("encoder init failed for dsi display\n");
555 return PTR_ERR(encoder);
556 }
557
558 memset(&info, 0, sizeof(info));
559 rc = msm_dp_modeset_init(priv->dp, dev, encoder);
560 if (rc) {
561 DPU_ERROR("modeset_init failed for DP, rc = %d\n", rc);
562 drm_encoder_cleanup(encoder);
563 return rc;
564 }
565
566 priv->encoders[priv->num_encoders++] = encoder;
567
568 info.num_of_h_tiles = 1;
569 info.capabilities = MSM_DISPLAY_CAP_VID_MODE;
570 info.intf_type = encoder->encoder_type;
571 rc = dpu_encoder_setup(dev, encoder, &info);
572 if (rc)
573 DPU_ERROR("failed to setup DPU encoder %d: rc:%d\n",
574 encoder->base.id, rc);
575 return rc;
576 }
577
578 /**
579 * _dpu_kms_setup_displays - create encoders, bridges and connectors
580 * for underlying displays
581 * @dev: Pointer to drm device structure
582 * @priv: Pointer to private drm device data
583 * @dpu_kms: Pointer to dpu kms structure
584 * Returns: Zero on success
585 */
_dpu_kms_setup_displays(struct drm_device * dev,struct msm_drm_private * priv,struct dpu_kms * dpu_kms)586 static int _dpu_kms_setup_displays(struct drm_device *dev,
587 struct msm_drm_private *priv,
588 struct dpu_kms *dpu_kms)
589 {
590 int rc = 0;
591
592 rc = _dpu_kms_initialize_dsi(dev, priv, dpu_kms);
593 if (rc) {
594 DPU_ERROR("initialize_dsi failed, rc = %d\n", rc);
595 return rc;
596 }
597
598 rc = _dpu_kms_initialize_displayport(dev, priv, dpu_kms);
599 if (rc) {
600 DPU_ERROR("initialize_DP failed, rc = %d\n", rc);
601 return rc;
602 }
603
604 return rc;
605 }
606
_dpu_kms_drm_obj_destroy(struct dpu_kms * dpu_kms)607 static void _dpu_kms_drm_obj_destroy(struct dpu_kms *dpu_kms)
608 {
609 struct msm_drm_private *priv;
610 int i;
611
612 priv = dpu_kms->dev->dev_private;
613
614 for (i = 0; i < priv->num_crtcs; i++)
615 priv->crtcs[i]->funcs->destroy(priv->crtcs[i]);
616 priv->num_crtcs = 0;
617
618 for (i = 0; i < priv->num_planes; i++)
619 priv->planes[i]->funcs->destroy(priv->planes[i]);
620 priv->num_planes = 0;
621
622 for (i = 0; i < priv->num_connectors; i++)
623 priv->connectors[i]->funcs->destroy(priv->connectors[i]);
624 priv->num_connectors = 0;
625
626 for (i = 0; i < priv->num_encoders; i++)
627 priv->encoders[i]->funcs->destroy(priv->encoders[i]);
628 priv->num_encoders = 0;
629 }
630
_dpu_kms_drm_obj_init(struct dpu_kms * dpu_kms)631 static int _dpu_kms_drm_obj_init(struct dpu_kms *dpu_kms)
632 {
633 struct drm_device *dev;
634 struct drm_plane *primary_planes[MAX_PLANES], *plane;
635 struct drm_plane *cursor_planes[MAX_PLANES] = { NULL };
636 struct drm_crtc *crtc;
637
638 struct msm_drm_private *priv;
639 struct dpu_mdss_cfg *catalog;
640
641 int primary_planes_idx = 0, cursor_planes_idx = 0, i, ret;
642 int max_crtc_count;
643 dev = dpu_kms->dev;
644 priv = dev->dev_private;
645 catalog = dpu_kms->catalog;
646
647 /*
648 * Create encoder and query display drivers to create
649 * bridges and connectors
650 */
651 ret = _dpu_kms_setup_displays(dev, priv, dpu_kms);
652 if (ret)
653 goto fail;
654
655 max_crtc_count = min(catalog->mixer_count, priv->num_encoders);
656
657 /* Create the planes, keeping track of one primary/cursor per crtc */
658 for (i = 0; i < catalog->sspp_count; i++) {
659 enum drm_plane_type type;
660
661 if ((catalog->sspp[i].features & BIT(DPU_SSPP_CURSOR))
662 && cursor_planes_idx < max_crtc_count)
663 type = DRM_PLANE_TYPE_CURSOR;
664 else if (primary_planes_idx < max_crtc_count)
665 type = DRM_PLANE_TYPE_PRIMARY;
666 else
667 type = DRM_PLANE_TYPE_OVERLAY;
668
669 DPU_DEBUG("Create plane type %d with features %lx (cur %lx)\n",
670 type, catalog->sspp[i].features,
671 catalog->sspp[i].features & BIT(DPU_SSPP_CURSOR));
672
673 plane = dpu_plane_init(dev, catalog->sspp[i].id, type,
674 (1UL << max_crtc_count) - 1, 0);
675 if (IS_ERR(plane)) {
676 DPU_ERROR("dpu_plane_init failed\n");
677 ret = PTR_ERR(plane);
678 goto fail;
679 }
680 priv->planes[priv->num_planes++] = plane;
681
682 if (type == DRM_PLANE_TYPE_CURSOR)
683 cursor_planes[cursor_planes_idx++] = plane;
684 else if (type == DRM_PLANE_TYPE_PRIMARY)
685 primary_planes[primary_planes_idx++] = plane;
686 }
687
688 max_crtc_count = min(max_crtc_count, primary_planes_idx);
689
690 /* Create one CRTC per encoder */
691 for (i = 0; i < max_crtc_count; i++) {
692 crtc = dpu_crtc_init(dev, primary_planes[i], cursor_planes[i]);
693 if (IS_ERR(crtc)) {
694 ret = PTR_ERR(crtc);
695 goto fail;
696 }
697 priv->crtcs[priv->num_crtcs++] = crtc;
698 }
699
700 /* All CRTCs are compatible with all encoders */
701 for (i = 0; i < priv->num_encoders; i++)
702 priv->encoders[i]->possible_crtcs = (1 << priv->num_crtcs) - 1;
703
704 return 0;
705 fail:
706 _dpu_kms_drm_obj_destroy(dpu_kms);
707 return ret;
708 }
709
dpu_kms_round_pixclk(struct msm_kms * kms,unsigned long rate,struct drm_encoder * encoder)710 static long dpu_kms_round_pixclk(struct msm_kms *kms, unsigned long rate,
711 struct drm_encoder *encoder)
712 {
713 return rate;
714 }
715
_dpu_kms_hw_destroy(struct dpu_kms * dpu_kms)716 static void _dpu_kms_hw_destroy(struct dpu_kms *dpu_kms)
717 {
718 int i;
719
720 if (dpu_kms->hw_intr)
721 dpu_hw_intr_destroy(dpu_kms->hw_intr);
722 dpu_kms->hw_intr = NULL;
723
724 /* safe to call these more than once during shutdown */
725 _dpu_kms_mmu_destroy(dpu_kms);
726
727 if (dpu_kms->catalog) {
728 for (i = 0; i < ARRAY_SIZE(dpu_kms->hw_vbif); i++) {
729 if (dpu_kms->hw_vbif[i]) {
730 dpu_hw_vbif_destroy(dpu_kms->hw_vbif[i]);
731 dpu_kms->hw_vbif[i] = NULL;
732 }
733 }
734 }
735
736 if (dpu_kms->rm_init)
737 dpu_rm_destroy(&dpu_kms->rm);
738 dpu_kms->rm_init = false;
739
740 if (dpu_kms->catalog)
741 dpu_hw_catalog_deinit(dpu_kms->catalog);
742 dpu_kms->catalog = NULL;
743
744 if (dpu_kms->vbif[VBIF_NRT])
745 devm_iounmap(&dpu_kms->pdev->dev, dpu_kms->vbif[VBIF_NRT]);
746 dpu_kms->vbif[VBIF_NRT] = NULL;
747
748 if (dpu_kms->vbif[VBIF_RT])
749 devm_iounmap(&dpu_kms->pdev->dev, dpu_kms->vbif[VBIF_RT]);
750 dpu_kms->vbif[VBIF_RT] = NULL;
751
752 if (dpu_kms->hw_mdp)
753 dpu_hw_mdp_destroy(dpu_kms->hw_mdp);
754 dpu_kms->hw_mdp = NULL;
755
756 if (dpu_kms->mmio)
757 devm_iounmap(&dpu_kms->pdev->dev, dpu_kms->mmio);
758 dpu_kms->mmio = NULL;
759 }
760
dpu_kms_destroy(struct msm_kms * kms)761 static void dpu_kms_destroy(struct msm_kms *kms)
762 {
763 struct dpu_kms *dpu_kms;
764
765 if (!kms) {
766 DPU_ERROR("invalid kms\n");
767 return;
768 }
769
770 dpu_kms = to_dpu_kms(kms);
771
772 _dpu_kms_hw_destroy(dpu_kms);
773
774 msm_kms_destroy(&dpu_kms->base);
775 }
776
dpu_irq(struct msm_kms * kms)777 static irqreturn_t dpu_irq(struct msm_kms *kms)
778 {
779 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
780
781 return dpu_core_irq(dpu_kms);
782 }
783
dpu_irq_preinstall(struct msm_kms * kms)784 static void dpu_irq_preinstall(struct msm_kms *kms)
785 {
786 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
787
788 dpu_core_irq_preinstall(dpu_kms);
789 }
790
dpu_irq_postinstall(struct msm_kms * kms)791 static int dpu_irq_postinstall(struct msm_kms *kms)
792 {
793 struct msm_drm_private *priv;
794 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
795
796 if (!dpu_kms || !dpu_kms->dev)
797 return -EINVAL;
798
799 priv = dpu_kms->dev->dev_private;
800 if (!priv)
801 return -EINVAL;
802
803 msm_dp_irq_postinstall(priv->dp);
804
805 return 0;
806 }
807
dpu_irq_uninstall(struct msm_kms * kms)808 static void dpu_irq_uninstall(struct msm_kms *kms)
809 {
810 struct dpu_kms *dpu_kms = to_dpu_kms(kms);
811
812 dpu_core_irq_uninstall(dpu_kms);
813 }
814
dpu_kms_mdp_snapshot(struct msm_disp_state * disp_state,struct msm_kms * kms)815 static void dpu_kms_mdp_snapshot(struct msm_disp_state *disp_state, struct msm_kms *kms)
816 {
817 int i;
818 struct dpu_kms *dpu_kms;
819 struct dpu_mdss_cfg *cat;
820 struct dpu_hw_mdp *top;
821
822 dpu_kms = to_dpu_kms(kms);
823
824 cat = dpu_kms->catalog;
825 top = dpu_kms->hw_mdp;
826
827 pm_runtime_get_sync(&dpu_kms->pdev->dev);
828
829 /* dump CTL sub-blocks HW regs info */
830 for (i = 0; i < cat->ctl_count; i++)
831 msm_disp_snapshot_add_block(disp_state, cat->ctl[i].len,
832 dpu_kms->mmio + cat->ctl[i].base, "ctl_%d", i);
833
834 /* dump DSPP sub-blocks HW regs info */
835 for (i = 0; i < cat->dspp_count; i++)
836 msm_disp_snapshot_add_block(disp_state, cat->dspp[i].len,
837 dpu_kms->mmio + cat->dspp[i].base, "dspp_%d", i);
838
839 /* dump INTF sub-blocks HW regs info */
840 for (i = 0; i < cat->intf_count; i++)
841 msm_disp_snapshot_add_block(disp_state, cat->intf[i].len,
842 dpu_kms->mmio + cat->intf[i].base, "intf_%d", i);
843
844 /* dump PP sub-blocks HW regs info */
845 for (i = 0; i < cat->pingpong_count; i++)
846 msm_disp_snapshot_add_block(disp_state, cat->pingpong[i].len,
847 dpu_kms->mmio + cat->pingpong[i].base, "pingpong_%d", i);
848
849 /* dump SSPP sub-blocks HW regs info */
850 for (i = 0; i < cat->sspp_count; i++)
851 msm_disp_snapshot_add_block(disp_state, cat->sspp[i].len,
852 dpu_kms->mmio + cat->sspp[i].base, "sspp_%d", i);
853
854 msm_disp_snapshot_add_block(disp_state, top->hw.length,
855 dpu_kms->mmio + top->hw.blk_off, "top");
856
857 pm_runtime_put_sync(&dpu_kms->pdev->dev);
858 }
859
860 static const struct msm_kms_funcs kms_funcs = {
861 .hw_init = dpu_kms_hw_init,
862 .irq_preinstall = dpu_irq_preinstall,
863 .irq_postinstall = dpu_irq_postinstall,
864 .irq_uninstall = dpu_irq_uninstall,
865 .irq = dpu_irq,
866 .enable_commit = dpu_kms_enable_commit,
867 .disable_commit = dpu_kms_disable_commit,
868 .vsync_time = dpu_kms_vsync_time,
869 .prepare_commit = dpu_kms_prepare_commit,
870 .flush_commit = dpu_kms_flush_commit,
871 .wait_flush = dpu_kms_wait_flush,
872 .complete_commit = dpu_kms_complete_commit,
873 .enable_vblank = dpu_kms_enable_vblank,
874 .disable_vblank = dpu_kms_disable_vblank,
875 .check_modified_format = dpu_format_check_modified_format,
876 .get_format = dpu_get_msm_format,
877 .round_pixclk = dpu_kms_round_pixclk,
878 .destroy = dpu_kms_destroy,
879 .snapshot = dpu_kms_mdp_snapshot,
880 #ifdef CONFIG_DEBUG_FS
881 .debugfs_init = dpu_kms_debugfs_init,
882 #endif
883 };
884
_dpu_kms_mmu_destroy(struct dpu_kms * dpu_kms)885 static void _dpu_kms_mmu_destroy(struct dpu_kms *dpu_kms)
886 {
887 struct msm_mmu *mmu;
888
889 if (!dpu_kms->base.aspace)
890 return;
891
892 mmu = dpu_kms->base.aspace->mmu;
893
894 mmu->funcs->detach(mmu);
895 msm_gem_address_space_put(dpu_kms->base.aspace);
896
897 dpu_kms->base.aspace = NULL;
898 }
899
_dpu_kms_mmu_init(struct dpu_kms * dpu_kms)900 static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
901 {
902 struct iommu_domain *domain;
903 struct msm_gem_address_space *aspace;
904 struct msm_mmu *mmu;
905
906 domain = iommu_domain_alloc(&platform_bus_type);
907 if (!domain)
908 return 0;
909
910 mmu = msm_iommu_new(dpu_kms->dev->dev, domain);
911 if (IS_ERR(mmu)) {
912 iommu_domain_free(domain);
913 return PTR_ERR(mmu);
914 }
915 aspace = msm_gem_address_space_create(mmu, "dpu1",
916 0x1000, 0x100000000 - 0x1000);
917
918 if (IS_ERR(aspace)) {
919 mmu->funcs->destroy(mmu);
920 return PTR_ERR(aspace);
921 }
922
923 dpu_kms->base.aspace = aspace;
924 return 0;
925 }
926
_dpu_kms_get_clk(struct dpu_kms * dpu_kms,char * clock_name)927 static struct dss_clk *_dpu_kms_get_clk(struct dpu_kms *dpu_kms,
928 char *clock_name)
929 {
930 struct dss_module_power *mp = &dpu_kms->mp;
931 int i;
932
933 for (i = 0; i < mp->num_clk; i++) {
934 if (!strcmp(mp->clk_config[i].clk_name, clock_name))
935 return &mp->clk_config[i];
936 }
937
938 return NULL;
939 }
940
dpu_kms_get_clk_rate(struct dpu_kms * dpu_kms,char * clock_name)941 u64 dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name)
942 {
943 struct dss_clk *clk;
944
945 clk = _dpu_kms_get_clk(dpu_kms, clock_name);
946 if (!clk)
947 return -EINVAL;
948
949 return clk_get_rate(clk->clk);
950 }
951
dpu_kms_hw_init(struct msm_kms * kms)952 static int dpu_kms_hw_init(struct msm_kms *kms)
953 {
954 struct dpu_kms *dpu_kms;
955 struct drm_device *dev;
956 int i, rc = -EINVAL;
957
958 if (!kms) {
959 DPU_ERROR("invalid kms\n");
960 return rc;
961 }
962
963 dpu_kms = to_dpu_kms(kms);
964 dev = dpu_kms->dev;
965
966 rc = dpu_kms_global_obj_init(dpu_kms);
967 if (rc)
968 return rc;
969
970 atomic_set(&dpu_kms->bandwidth_ref, 0);
971
972 dpu_kms->mmio = msm_ioremap(dpu_kms->pdev, "mdp", "mdp");
973 if (IS_ERR(dpu_kms->mmio)) {
974 rc = PTR_ERR(dpu_kms->mmio);
975 DPU_ERROR("mdp register memory map failed: %d\n", rc);
976 dpu_kms->mmio = NULL;
977 goto error;
978 }
979 DRM_DEBUG("mapped dpu address space @%pK\n", dpu_kms->mmio);
980
981 dpu_kms->vbif[VBIF_RT] = msm_ioremap(dpu_kms->pdev, "vbif", "vbif");
982 if (IS_ERR(dpu_kms->vbif[VBIF_RT])) {
983 rc = PTR_ERR(dpu_kms->vbif[VBIF_RT]);
984 DPU_ERROR("vbif register memory map failed: %d\n", rc);
985 dpu_kms->vbif[VBIF_RT] = NULL;
986 goto error;
987 }
988 dpu_kms->vbif[VBIF_NRT] = msm_ioremap_quiet(dpu_kms->pdev, "vbif_nrt", "vbif_nrt");
989 if (IS_ERR(dpu_kms->vbif[VBIF_NRT])) {
990 dpu_kms->vbif[VBIF_NRT] = NULL;
991 DPU_DEBUG("VBIF NRT is not defined");
992 }
993
994 dpu_kms->reg_dma = msm_ioremap_quiet(dpu_kms->pdev, "regdma", "regdma");
995 if (IS_ERR(dpu_kms->reg_dma)) {
996 dpu_kms->reg_dma = NULL;
997 DPU_DEBUG("REG_DMA is not defined");
998 }
999
1000 dpu_kms_parse_data_bus_icc_path(dpu_kms);
1001
1002 rc = pm_runtime_resume_and_get(&dpu_kms->pdev->dev);
1003 if (rc < 0)
1004 goto error;
1005
1006 dpu_kms->core_rev = readl_relaxed(dpu_kms->mmio + 0x0);
1007
1008 pr_info("dpu hardware revision:0x%x\n", dpu_kms->core_rev);
1009
1010 dpu_kms->catalog = dpu_hw_catalog_init(dpu_kms->core_rev);
1011 if (IS_ERR_OR_NULL(dpu_kms->catalog)) {
1012 rc = PTR_ERR(dpu_kms->catalog);
1013 if (!dpu_kms->catalog)
1014 rc = -EINVAL;
1015 DPU_ERROR("catalog init failed: %d\n", rc);
1016 dpu_kms->catalog = NULL;
1017 goto power_error;
1018 }
1019
1020 /*
1021 * Now we need to read the HW catalog and initialize resources such as
1022 * clocks, regulators, GDSC/MMAGIC, ioremap the register ranges etc
1023 */
1024 rc = _dpu_kms_mmu_init(dpu_kms);
1025 if (rc) {
1026 DPU_ERROR("dpu_kms_mmu_init failed: %d\n", rc);
1027 goto power_error;
1028 }
1029
1030 rc = dpu_rm_init(&dpu_kms->rm, dpu_kms->catalog, dpu_kms->mmio);
1031 if (rc) {
1032 DPU_ERROR("rm init failed: %d\n", rc);
1033 goto power_error;
1034 }
1035
1036 dpu_kms->rm_init = true;
1037
1038 dpu_kms->hw_mdp = dpu_hw_mdptop_init(MDP_TOP, dpu_kms->mmio,
1039 dpu_kms->catalog);
1040 if (IS_ERR(dpu_kms->hw_mdp)) {
1041 rc = PTR_ERR(dpu_kms->hw_mdp);
1042 DPU_ERROR("failed to get hw_mdp: %d\n", rc);
1043 dpu_kms->hw_mdp = NULL;
1044 goto power_error;
1045 }
1046
1047 for (i = 0; i < dpu_kms->catalog->vbif_count; i++) {
1048 u32 vbif_idx = dpu_kms->catalog->vbif[i].id;
1049
1050 dpu_kms->hw_vbif[vbif_idx] = dpu_hw_vbif_init(vbif_idx,
1051 dpu_kms->vbif[vbif_idx], dpu_kms->catalog);
1052 if (IS_ERR_OR_NULL(dpu_kms->hw_vbif[vbif_idx])) {
1053 rc = PTR_ERR(dpu_kms->hw_vbif[vbif_idx]);
1054 if (!dpu_kms->hw_vbif[vbif_idx])
1055 rc = -EINVAL;
1056 DPU_ERROR("failed to init vbif %d: %d\n", vbif_idx, rc);
1057 dpu_kms->hw_vbif[vbif_idx] = NULL;
1058 goto power_error;
1059 }
1060 }
1061
1062 rc = dpu_core_perf_init(&dpu_kms->perf, dev, dpu_kms->catalog,
1063 _dpu_kms_get_clk(dpu_kms, "core"));
1064 if (rc) {
1065 DPU_ERROR("failed to init perf %d\n", rc);
1066 goto perf_err;
1067 }
1068
1069 dpu_kms->hw_intr = dpu_hw_intr_init(dpu_kms->mmio, dpu_kms->catalog);
1070 if (IS_ERR_OR_NULL(dpu_kms->hw_intr)) {
1071 rc = PTR_ERR(dpu_kms->hw_intr);
1072 DPU_ERROR("hw_intr init failed: %d\n", rc);
1073 dpu_kms->hw_intr = NULL;
1074 goto hw_intr_init_err;
1075 }
1076
1077 dev->mode_config.min_width = 0;
1078 dev->mode_config.min_height = 0;
1079
1080 /*
1081 * max crtc width is equal to the max mixer width * 2 and max height is
1082 * is 4K
1083 */
1084 dev->mode_config.max_width =
1085 dpu_kms->catalog->caps->max_mixer_width * 2;
1086 dev->mode_config.max_height = 4096;
1087
1088 dev->max_vblank_count = 0xffffffff;
1089 /* Disable vblank irqs aggressively for power-saving */
1090 dev->vblank_disable_immediate = true;
1091
1092 /*
1093 * _dpu_kms_drm_obj_init should create the DRM related objects
1094 * i.e. CRTCs, planes, encoders, connectors and so forth
1095 */
1096 rc = _dpu_kms_drm_obj_init(dpu_kms);
1097 if (rc) {
1098 DPU_ERROR("modeset init failed: %d\n", rc);
1099 goto drm_obj_init_err;
1100 }
1101
1102 dpu_vbif_init_memtypes(dpu_kms);
1103
1104 pm_runtime_put_sync(&dpu_kms->pdev->dev);
1105
1106 return 0;
1107
1108 drm_obj_init_err:
1109 dpu_core_perf_destroy(&dpu_kms->perf);
1110 hw_intr_init_err:
1111 perf_err:
1112 power_error:
1113 pm_runtime_put_sync(&dpu_kms->pdev->dev);
1114 error:
1115 _dpu_kms_hw_destroy(dpu_kms);
1116
1117 return rc;
1118 }
1119
dpu_kms_init(struct drm_device * dev)1120 struct msm_kms *dpu_kms_init(struct drm_device *dev)
1121 {
1122 struct msm_drm_private *priv;
1123 struct dpu_kms *dpu_kms;
1124 int irq;
1125
1126 if (!dev) {
1127 DPU_ERROR("drm device node invalid\n");
1128 return ERR_PTR(-EINVAL);
1129 }
1130
1131 priv = dev->dev_private;
1132 dpu_kms = to_dpu_kms(priv->kms);
1133
1134 irq = irq_of_parse_and_map(dpu_kms->pdev->dev.of_node, 0);
1135 if (irq < 0) {
1136 DPU_ERROR("failed to get irq: %d\n", irq);
1137 return ERR_PTR(irq);
1138 }
1139 dpu_kms->base.irq = irq;
1140
1141 return &dpu_kms->base;
1142 }
1143
dpu_bind(struct device * dev,struct device * master,void * data)1144 static int dpu_bind(struct device *dev, struct device *master, void *data)
1145 {
1146 struct drm_device *ddev = dev_get_drvdata(master);
1147 struct platform_device *pdev = to_platform_device(dev);
1148 struct msm_drm_private *priv = ddev->dev_private;
1149 struct dpu_kms *dpu_kms;
1150 struct dss_module_power *mp;
1151 int ret = 0;
1152
1153 dpu_kms = devm_kzalloc(&pdev->dev, sizeof(*dpu_kms), GFP_KERNEL);
1154 if (!dpu_kms)
1155 return -ENOMEM;
1156
1157 ret = devm_pm_opp_set_clkname(dev, "core");
1158 if (ret)
1159 return ret;
1160 /* OPP table is optional */
1161 ret = devm_pm_opp_of_add_table(dev);
1162 if (ret && ret != -ENODEV) {
1163 dev_err(dev, "invalid OPP table in device tree\n");
1164 return ret;
1165 }
1166
1167 mp = &dpu_kms->mp;
1168 ret = msm_dss_parse_clock(pdev, mp);
1169 if (ret) {
1170 DPU_ERROR("failed to parse clocks, ret=%d\n", ret);
1171 return ret;
1172 }
1173
1174 platform_set_drvdata(pdev, dpu_kms);
1175
1176 ret = msm_kms_init(&dpu_kms->base, &kms_funcs);
1177 if (ret) {
1178 DPU_ERROR("failed to init kms, ret=%d\n", ret);
1179 return ret;
1180 }
1181 dpu_kms->dev = ddev;
1182 dpu_kms->pdev = pdev;
1183
1184 pm_runtime_enable(&pdev->dev);
1185 dpu_kms->rpm_enabled = true;
1186
1187 priv->kms = &dpu_kms->base;
1188
1189 return 0;
1190 }
1191
dpu_unbind(struct device * dev,struct device * master,void * data)1192 static void dpu_unbind(struct device *dev, struct device *master, void *data)
1193 {
1194 struct platform_device *pdev = to_platform_device(dev);
1195 struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
1196 struct dss_module_power *mp = &dpu_kms->mp;
1197
1198 msm_dss_put_clk(mp->clk_config, mp->num_clk);
1199 devm_kfree(&pdev->dev, mp->clk_config);
1200 mp->num_clk = 0;
1201
1202 if (dpu_kms->rpm_enabled)
1203 pm_runtime_disable(&pdev->dev);
1204 }
1205
1206 static const struct component_ops dpu_ops = {
1207 .bind = dpu_bind,
1208 .unbind = dpu_unbind,
1209 };
1210
dpu_dev_probe(struct platform_device * pdev)1211 static int dpu_dev_probe(struct platform_device *pdev)
1212 {
1213 return component_add(&pdev->dev, &dpu_ops);
1214 }
1215
dpu_dev_remove(struct platform_device * pdev)1216 static int dpu_dev_remove(struct platform_device *pdev)
1217 {
1218 component_del(&pdev->dev, &dpu_ops);
1219 return 0;
1220 }
1221
dpu_runtime_suspend(struct device * dev)1222 static int __maybe_unused dpu_runtime_suspend(struct device *dev)
1223 {
1224 int i, rc = -1;
1225 struct platform_device *pdev = to_platform_device(dev);
1226 struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
1227 struct dss_module_power *mp = &dpu_kms->mp;
1228
1229 /* Drop the performance state vote */
1230 dev_pm_opp_set_rate(dev, 0);
1231 rc = msm_dss_enable_clk(mp->clk_config, mp->num_clk, false);
1232 if (rc)
1233 DPU_ERROR("clock disable failed rc:%d\n", rc);
1234
1235 for (i = 0; i < dpu_kms->num_paths; i++)
1236 icc_set_bw(dpu_kms->path[i], 0, 0);
1237
1238 return rc;
1239 }
1240
dpu_runtime_resume(struct device * dev)1241 static int __maybe_unused dpu_runtime_resume(struct device *dev)
1242 {
1243 int rc = -1;
1244 struct platform_device *pdev = to_platform_device(dev);
1245 struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
1246 struct drm_encoder *encoder;
1247 struct drm_device *ddev;
1248 struct dss_module_power *mp = &dpu_kms->mp;
1249 int i;
1250
1251 ddev = dpu_kms->dev;
1252
1253 WARN_ON(!(dpu_kms->num_paths));
1254 /* Min vote of BW is required before turning on AXI clk */
1255 for (i = 0; i < dpu_kms->num_paths; i++)
1256 icc_set_bw(dpu_kms->path[i], 0, Bps_to_icc(MIN_IB_BW));
1257
1258 rc = msm_dss_enable_clk(mp->clk_config, mp->num_clk, true);
1259 if (rc) {
1260 DPU_ERROR("clock enable failed rc:%d\n", rc);
1261 return rc;
1262 }
1263
1264 dpu_vbif_init_memtypes(dpu_kms);
1265
1266 drm_for_each_encoder(encoder, ddev)
1267 dpu_encoder_virt_runtime_resume(encoder);
1268
1269 return rc;
1270 }
1271
1272 static const struct dev_pm_ops dpu_pm_ops = {
1273 SET_RUNTIME_PM_OPS(dpu_runtime_suspend, dpu_runtime_resume, NULL)
1274 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1275 pm_runtime_force_resume)
1276 };
1277
1278 static const struct of_device_id dpu_dt_match[] = {
1279 { .compatible = "qcom,sdm845-dpu", },
1280 { .compatible = "qcom,sc7180-dpu", },
1281 { .compatible = "qcom,sc7280-dpu", },
1282 { .compatible = "qcom,sm8150-dpu", },
1283 { .compatible = "qcom,sm8250-dpu", },
1284 {}
1285 };
1286 MODULE_DEVICE_TABLE(of, dpu_dt_match);
1287
1288 static struct platform_driver dpu_driver = {
1289 .probe = dpu_dev_probe,
1290 .remove = dpu_dev_remove,
1291 .driver = {
1292 .name = "msm_dpu",
1293 .of_match_table = dpu_dt_match,
1294 .pm = &dpu_pm_ops,
1295 },
1296 };
1297
msm_dpu_register(void)1298 void __init msm_dpu_register(void)
1299 {
1300 platform_driver_register(&dpu_driver);
1301 }
1302
msm_dpu_unregister(void)1303 void __exit msm_dpu_unregister(void)
1304 {
1305 platform_driver_unregister(&dpu_driver);
1306 }
1307