Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 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 | |
Derek Foreman | 48666d5 | 2015-07-02 11:19:54 -0500 | [diff] [blame^] | 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 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 32 | static const struct drm_mode_config_funcs vc4_mode_funcs = { |
Derek Foreman | 48666d5 | 2015-07-02 11:19:54 -0500 | [diff] [blame^] | 33 | .output_poll_changed = vc4_output_poll_changed, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 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 | { |
Derek Foreman | 48666d5 | 2015-07-02 11:19:54 -0500 | [diff] [blame^] | 41 | struct vc4_dev *vc4 = to_vc4_dev(dev); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 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 | |
| 55 | drm_mode_config_reset(dev); |
| 56 | |
Derek Foreman | 48666d5 | 2015-07-02 11:19:54 -0500 | [diff] [blame^] | 57 | vc4->fbdev = drm_fbdev_cma_init(dev, 32, |
| 58 | dev->mode_config.num_crtc, |
| 59 | dev->mode_config.num_connector); |
| 60 | if (IS_ERR(vc4->fbdev)) |
| 61 | vc4->fbdev = NULL; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 62 | |
| 63 | drm_kms_helper_poll_init(dev); |
| 64 | |
| 65 | return 0; |
| 66 | } |