1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2019-2022 Bootlin 4 * Author: Paul Kocialkowski <paul.kocialkowski@bootlin.com> 5 */ 6 7 #include <linux/types.h> 8 9 #include <drm/drm_atomic.h> 10 #include <drm/drm_atomic_helper.h> 11 #include <drm/drm_crtc_helper.h> 12 #include <drm/drm_drv.h> 13 #include <drm/drm_fb_cma_helper.h> 14 #include <drm/drm_fb_helper.h> 15 #include <drm/drm_gem_cma_helper.h> 16 #include <drm/drm_gem_framebuffer_helper.h> 17 #include <drm/drm_mode_config.h> 18 #include <drm/drm_panel.h> 19 #include <drm/drm_print.h> 20 #include <drm/drm_probe_helper.h> 21 #include <drm/drm_vblank.h> 22 23 #include "logicvc_drm.h" 24 #include "logicvc_interface.h" 25 #include "logicvc_layer.h" 26 #include "logicvc_mode.h" 27 28 static const struct drm_mode_config_funcs logicvc_mode_config_funcs = { 29 .fb_create = drm_gem_fb_create, 30 .output_poll_changed = drm_fb_helper_output_poll_changed, 31 .atomic_check = drm_atomic_helper_check, 32 .atomic_commit = drm_atomic_helper_commit, 33 }; 34 35 int logicvc_mode_init(struct logicvc_drm *logicvc) 36 { 37 struct drm_device *drm_dev = &logicvc->drm_dev; 38 struct drm_mode_config *mode_config = &drm_dev->mode_config; 39 struct logicvc_layer *layer_primary; 40 uint32_t preferred_depth; 41 int ret; 42 43 ret = drm_vblank_init(drm_dev, mode_config->num_crtc); 44 if (ret) { 45 drm_err(drm_dev, "Failed to initialize vblank\n"); 46 return ret; 47 } 48 49 layer_primary = logicvc_layer_get_primary(logicvc); 50 if (!layer_primary) { 51 drm_err(drm_dev, "Failed to get primary layer\n"); 52 return -EINVAL; 53 } 54 55 preferred_depth = layer_primary->formats->depth; 56 57 /* DRM counts alpha in depth, our driver doesn't. */ 58 if (layer_primary->formats->alpha) 59 preferred_depth += 8; 60 61 mode_config->min_width = 64; 62 mode_config->max_width = 2048; 63 mode_config->min_height = 1; 64 mode_config->max_height = 2048; 65 mode_config->preferred_depth = preferred_depth; 66 mode_config->funcs = &logicvc_mode_config_funcs; 67 68 drm_mode_config_reset(drm_dev); 69 70 drm_kms_helper_poll_init(drm_dev); 71 72 return 0; 73 } 74 75 void logicvc_mode_fini(struct logicvc_drm *logicvc) 76 { 77 struct drm_device *drm_dev = &logicvc->drm_dev; 78 79 drm_kms_helper_poll_fini(drm_dev); 80 } 81