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_drv.h> 12 #include <drm/drm_gem_dma_helper.h> 13 #include <drm/drm_gem_framebuffer_helper.h> 14 #include <drm/drm_mode_config.h> 15 #include <drm/drm_panel.h> 16 #include <drm/drm_print.h> 17 #include <drm/drm_probe_helper.h> 18 #include <drm/drm_vblank.h> 19 20 #include "logicvc_drm.h" 21 #include "logicvc_interface.h" 22 #include "logicvc_layer.h" 23 #include "logicvc_mode.h" 24 25 static const struct drm_mode_config_funcs logicvc_mode_config_funcs = { 26 .fb_create = drm_gem_fb_create, 27 .atomic_check = drm_atomic_helper_check, 28 .atomic_commit = drm_atomic_helper_commit, 29 }; 30 31 int logicvc_mode_init(struct logicvc_drm *logicvc) 32 { 33 struct drm_device *drm_dev = &logicvc->drm_dev; 34 struct drm_mode_config *mode_config = &drm_dev->mode_config; 35 struct logicvc_layer *layer_primary; 36 uint32_t preferred_depth; 37 int ret; 38 39 ret = drm_vblank_init(drm_dev, mode_config->num_crtc); 40 if (ret) { 41 drm_err(drm_dev, "Failed to initialize vblank\n"); 42 return ret; 43 } 44 45 layer_primary = logicvc_layer_get_primary(logicvc); 46 if (!layer_primary) { 47 drm_err(drm_dev, "Failed to get primary layer\n"); 48 return -EINVAL; 49 } 50 51 preferred_depth = layer_primary->formats->depth; 52 53 /* DRM counts alpha in depth, our driver doesn't. */ 54 if (layer_primary->formats->alpha) 55 preferred_depth += 8; 56 57 mode_config->min_width = 64; 58 mode_config->max_width = 2048; 59 mode_config->min_height = 1; 60 mode_config->max_height = 2048; 61 mode_config->preferred_depth = preferred_depth; 62 mode_config->funcs = &logicvc_mode_config_funcs; 63 64 drm_mode_config_reset(drm_dev); 65 66 drm_kms_helper_poll_init(drm_dev); 67 68 return 0; 69 } 70 71 void logicvc_mode_fini(struct logicvc_drm *logicvc) 72 { 73 struct drm_device *drm_dev = &logicvc->drm_dev; 74 75 drm_kms_helper_poll_fini(drm_dev); 76 } 77