1c8b75bcaSEric Anholt /* 2c8b75bcaSEric Anholt * Copyright (C) 2015 Broadcom 3c8b75bcaSEric Anholt * 4c8b75bcaSEric Anholt * This program is free software; you can redistribute it and/or modify 5c8b75bcaSEric Anholt * it under the terms of the GNU General Public License version 2 as 6c8b75bcaSEric Anholt * published by the Free Software Foundation. 7c8b75bcaSEric Anholt */ 8c8b75bcaSEric Anholt 9c8b75bcaSEric Anholt /** 10c8b75bcaSEric Anholt * DOC: VC4 KMS 11c8b75bcaSEric Anholt * 12c8b75bcaSEric Anholt * This is the general code for implementing KMS mode setting that 13c8b75bcaSEric Anholt * doesn't clearly associate with any of the other objects (plane, 14c8b75bcaSEric Anholt * crtc, HDMI encoder). 15c8b75bcaSEric Anholt */ 16c8b75bcaSEric Anholt 17c8b75bcaSEric Anholt #include "drm_crtc.h" 18c8b75bcaSEric Anholt #include "drm_atomic_helper.h" 19c8b75bcaSEric Anholt #include "drm_crtc_helper.h" 20c8b75bcaSEric Anholt #include "drm_plane_helper.h" 21c8b75bcaSEric Anholt #include "drm_fb_cma_helper.h" 22c8b75bcaSEric Anholt #include "vc4_drv.h" 23c8b75bcaSEric Anholt 2448666d56SDerek Foreman static void vc4_output_poll_changed(struct drm_device *dev) 2548666d56SDerek Foreman { 2648666d56SDerek Foreman struct vc4_dev *vc4 = to_vc4_dev(dev); 2748666d56SDerek Foreman 2848666d56SDerek Foreman if (vc4->fbdev) 2948666d56SDerek Foreman drm_fbdev_cma_hotplug_event(vc4->fbdev); 3048666d56SDerek Foreman } 3148666d56SDerek Foreman 32c8b75bcaSEric Anholt static const struct drm_mode_config_funcs vc4_mode_funcs = { 3348666d56SDerek Foreman .output_poll_changed = vc4_output_poll_changed, 34c8b75bcaSEric Anholt .atomic_check = drm_atomic_helper_check, 35c8b75bcaSEric Anholt .atomic_commit = drm_atomic_helper_commit, 36c8b75bcaSEric Anholt .fb_create = drm_fb_cma_create, 37c8b75bcaSEric Anholt }; 38c8b75bcaSEric Anholt 39c8b75bcaSEric Anholt int vc4_kms_load(struct drm_device *dev) 40c8b75bcaSEric Anholt { 4148666d56SDerek Foreman struct vc4_dev *vc4 = to_vc4_dev(dev); 42c8b75bcaSEric Anholt int ret; 43c8b75bcaSEric Anholt 44c8b75bcaSEric Anholt ret = drm_vblank_init(dev, dev->mode_config.num_crtc); 45c8b75bcaSEric Anholt if (ret < 0) { 46c8b75bcaSEric Anholt dev_err(dev->dev, "failed to initialize vblank\n"); 47c8b75bcaSEric Anholt return ret; 48c8b75bcaSEric Anholt } 49c8b75bcaSEric Anholt 50c8b75bcaSEric Anholt dev->mode_config.max_width = 2048; 51c8b75bcaSEric Anholt dev->mode_config.max_height = 2048; 52c8b75bcaSEric Anholt dev->mode_config.funcs = &vc4_mode_funcs; 53c8b75bcaSEric Anholt dev->mode_config.preferred_depth = 24; 5498a44504SDerek Foreman dev->vblank_disable_allowed = true; 55c8b75bcaSEric Anholt 56c8b75bcaSEric Anholt drm_mode_config_reset(dev); 57c8b75bcaSEric Anholt 5848666d56SDerek Foreman vc4->fbdev = drm_fbdev_cma_init(dev, 32, 59c8b75bcaSEric Anholt dev->mode_config.num_crtc, 60c8b75bcaSEric Anholt dev->mode_config.num_connector); 6148666d56SDerek Foreman if (IS_ERR(vc4->fbdev)) 6248666d56SDerek Foreman vc4->fbdev = NULL; 63c8b75bcaSEric Anholt 64c8b75bcaSEric Anholt drm_kms_helper_poll_init(dev); 65c8b75bcaSEric Anholt 66c8b75bcaSEric Anholt return 0; 67c8b75bcaSEric Anholt } 68