0001
0002
0003
0004
0005
0006
0007 #include <linux/types.h>
0008
0009 #include <drm/drm_atomic.h>
0010 #include <drm/drm_atomic_helper.h>
0011 #include <drm/drm_crtc_helper.h>
0012 #include <drm/drm_drv.h>
0013 #include <drm/drm_fb_cma_helper.h>
0014 #include <drm/drm_fb_helper.h>
0015 #include <drm/drm_gem_cma_helper.h>
0016 #include <drm/drm_gem_framebuffer_helper.h>
0017 #include <drm/drm_mode_config.h>
0018 #include <drm/drm_panel.h>
0019 #include <drm/drm_print.h>
0020 #include <drm/drm_probe_helper.h>
0021 #include <drm/drm_vblank.h>
0022
0023 #include "logicvc_drm.h"
0024 #include "logicvc_interface.h"
0025 #include "logicvc_layer.h"
0026 #include "logicvc_mode.h"
0027
0028 static const struct drm_mode_config_funcs logicvc_mode_config_funcs = {
0029 .fb_create = drm_gem_fb_create,
0030 .output_poll_changed = drm_fb_helper_output_poll_changed,
0031 .atomic_check = drm_atomic_helper_check,
0032 .atomic_commit = drm_atomic_helper_commit,
0033 };
0034
0035 int logicvc_mode_init(struct logicvc_drm *logicvc)
0036 {
0037 struct drm_device *drm_dev = &logicvc->drm_dev;
0038 struct drm_mode_config *mode_config = &drm_dev->mode_config;
0039 struct logicvc_layer *layer_primary;
0040 uint32_t preferred_depth;
0041 int ret;
0042
0043 ret = drm_vblank_init(drm_dev, mode_config->num_crtc);
0044 if (ret) {
0045 drm_err(drm_dev, "Failed to initialize vblank\n");
0046 return ret;
0047 }
0048
0049 layer_primary = logicvc_layer_get_primary(logicvc);
0050 if (!layer_primary) {
0051 drm_err(drm_dev, "Failed to get primary layer\n");
0052 return -EINVAL;
0053 }
0054
0055 preferred_depth = layer_primary->formats->depth;
0056
0057
0058 if (layer_primary->formats->alpha)
0059 preferred_depth += 8;
0060
0061 mode_config->min_width = 64;
0062 mode_config->max_width = 2048;
0063 mode_config->min_height = 1;
0064 mode_config->max_height = 2048;
0065 mode_config->preferred_depth = preferred_depth;
0066 mode_config->funcs = &logicvc_mode_config_funcs;
0067
0068 drm_mode_config_reset(drm_dev);
0069
0070 drm_kms_helper_poll_init(drm_dev);
0071
0072 return 0;
0073 }
0074
0075 void logicvc_mode_fini(struct logicvc_drm *logicvc)
0076 {
0077 struct drm_device *drm_dev = &logicvc->drm_dev;
0078
0079 drm_kms_helper_poll_fini(drm_dev);
0080 }