These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / gpu / drm / vc4 / vc4_kms.c
1 /*
2  * Copyright (C) 2015 Broadcom
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 /**
10  * DOC: VC4 KMS
11  *
12  * This is the general code for implementing KMS mode setting that
13  * doesn't clearly associate with any of the other objects (plane,
14  * crtc, HDMI encoder).
15  */
16
17 #include "drm_crtc.h"
18 #include "drm_atomic_helper.h"
19 #include "drm_crtc_helper.h"
20 #include "drm_plane_helper.h"
21 #include "drm_fb_cma_helper.h"
22 #include "vc4_drv.h"
23
24 static void vc4_output_poll_changed(struct drm_device *dev)
25 {
26         struct vc4_dev *vc4 = to_vc4_dev(dev);
27
28         if (vc4->fbdev)
29                 drm_fbdev_cma_hotplug_event(vc4->fbdev);
30 }
31
32 static const struct drm_mode_config_funcs vc4_mode_funcs = {
33         .output_poll_changed = vc4_output_poll_changed,
34         .atomic_check = drm_atomic_helper_check,
35         .atomic_commit = drm_atomic_helper_commit,
36         .fb_create = drm_fb_cma_create,
37 };
38
39 int vc4_kms_load(struct drm_device *dev)
40 {
41         struct vc4_dev *vc4 = to_vc4_dev(dev);
42         int ret;
43
44         ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
45         if (ret < 0) {
46                 dev_err(dev->dev, "failed to initialize vblank\n");
47                 return ret;
48         }
49
50         dev->mode_config.max_width = 2048;
51         dev->mode_config.max_height = 2048;
52         dev->mode_config.funcs = &vc4_mode_funcs;
53         dev->mode_config.preferred_depth = 24;
54         dev->vblank_disable_allowed = true;
55
56         drm_mode_config_reset(dev);
57
58         vc4->fbdev = drm_fbdev_cma_init(dev, 32,
59                                         dev->mode_config.num_crtc,
60                                         dev->mode_config.num_connector);
61         if (IS_ERR(vc4->fbdev))
62                 vc4->fbdev = NULL;
63
64         drm_kms_helper_poll_init(dev);
65
66         return 0;
67 }