1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics SA 2017
5 * Authors: Philippe Cornu <philippe.cornu@st.com>
6 * Yannick Fertre <yannick.fertre@st.com>
7 * Fabien Dessenne <fabien.dessenne@st.com>
8 * Mickael Reulier <mickael.reulier@st.com>
11 #include <linux/component.h>
12 #include <linux/of_platform.h>
14 #include <drm/drm_atomic.h>
15 #include <drm/drm_atomic_helper.h>
16 #include <drm/drm_crtc_helper.h>
17 #include <drm/drm_fb_helper.h>
18 #include <drm/drm_fb_cma_helper.h>
19 #include <drm/drm_gem_cma_helper.h>
20 #include <drm/drm_gem_framebuffer_helper.h>
24 #define STM_MAX_FB_WIDTH 2048
25 #define STM_MAX_FB_HEIGHT 2048 /* same as width to handle orientation */
27 static const struct drm_mode_config_funcs drv_mode_config_funcs
= {
28 .fb_create
= drm_gem_fb_create
,
29 .output_poll_changed
= drm_fb_helper_output_poll_changed
,
30 .atomic_check
= drm_atomic_helper_check
,
31 .atomic_commit
= drm_atomic_helper_commit
,
34 DEFINE_DRM_GEM_CMA_FOPS(drv_driver_fops
);
36 static struct drm_driver drv_driver
= {
37 .driver_features
= DRIVER_MODESET
| DRIVER_GEM
| DRIVER_PRIME
|
39 .lastclose
= drm_fb_helper_lastclose
,
41 .desc
= "STMicroelectronics SoC DRM",
46 .fops
= &drv_driver_fops
,
47 .dumb_create
= drm_gem_cma_dumb_create
,
48 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
49 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
50 .gem_free_object_unlocked
= drm_gem_cma_free_object
,
51 .gem_vm_ops
= &drm_gem_cma_vm_ops
,
52 .gem_prime_export
= drm_gem_prime_export
,
53 .gem_prime_import
= drm_gem_prime_import
,
54 .gem_prime_get_sg_table
= drm_gem_cma_prime_get_sg_table
,
55 .gem_prime_import_sg_table
= drm_gem_cma_prime_import_sg_table
,
56 .gem_prime_vmap
= drm_gem_cma_prime_vmap
,
57 .gem_prime_vunmap
= drm_gem_cma_prime_vunmap
,
58 .gem_prime_mmap
= drm_gem_cma_prime_mmap
,
59 .enable_vblank
= ltdc_crtc_enable_vblank
,
60 .disable_vblank
= ltdc_crtc_disable_vblank
,
63 static int drv_load(struct drm_device
*ddev
)
65 struct platform_device
*pdev
= to_platform_device(ddev
->dev
);
66 struct ltdc_device
*ldev
;
69 DRM_DEBUG("%s\n", __func__
);
71 ldev
= devm_kzalloc(ddev
->dev
, sizeof(*ldev
), GFP_KERNEL
);
75 ddev
->dev_private
= (void *)ldev
;
77 drm_mode_config_init(ddev
);
80 * set max width and height as default value.
81 * this value would be used to check framebuffer size limitation
82 * at drm_mode_addfb().
84 ddev
->mode_config
.min_width
= 0;
85 ddev
->mode_config
.min_height
= 0;
86 ddev
->mode_config
.max_width
= STM_MAX_FB_WIDTH
;
87 ddev
->mode_config
.max_height
= STM_MAX_FB_HEIGHT
;
88 ddev
->mode_config
.funcs
= &drv_mode_config_funcs
;
90 ret
= ltdc_load(ddev
);
94 drm_mode_config_reset(ddev
);
95 drm_kms_helper_poll_init(ddev
);
97 if (ddev
->mode_config
.num_connector
) {
98 ret
= drm_fb_cma_fbdev_init(ddev
, 16, 0);
100 DRM_DEBUG("Warning: fails to create fbdev\n");
103 platform_set_drvdata(pdev
, ddev
);
107 drm_mode_config_cleanup(ddev
);
111 static void drv_unload(struct drm_device
*ddev
)
113 DRM_DEBUG("%s\n", __func__
);
115 drm_fb_cma_fbdev_fini(ddev
);
116 drm_kms_helper_poll_fini(ddev
);
118 drm_mode_config_cleanup(ddev
);
121 static int stm_drm_platform_probe(struct platform_device
*pdev
)
123 struct device
*dev
= &pdev
->dev
;
124 struct drm_device
*ddev
;
127 DRM_DEBUG("%s\n", __func__
);
129 dma_set_coherent_mask(dev
, DMA_BIT_MASK(32));
131 ddev
= drm_dev_alloc(&drv_driver
, dev
);
133 return PTR_ERR(ddev
);
135 ret
= drv_load(ddev
);
139 ret
= drm_dev_register(ddev
, 0);
151 static int stm_drm_platform_remove(struct platform_device
*pdev
)
153 struct drm_device
*ddev
= platform_get_drvdata(pdev
);
155 DRM_DEBUG("%s\n", __func__
);
157 drm_dev_unregister(ddev
);
164 static const struct of_device_id drv_dt_ids
[] = {
165 { .compatible
= "st,stm32-ltdc"},
168 MODULE_DEVICE_TABLE(of
, drv_dt_ids
);
170 static struct platform_driver stm_drm_platform_driver
= {
171 .probe
= stm_drm_platform_probe
,
172 .remove
= stm_drm_platform_remove
,
174 .name
= "stm32-display",
175 .of_match_table
= drv_dt_ids
,
179 module_platform_driver(stm_drm_platform_driver
);
181 MODULE_AUTHOR("Philippe Cornu <philippe.cornu@st.com>");
182 MODULE_AUTHOR("Yannick Fertre <yannick.fertre@st.com>");
183 MODULE_AUTHOR("Fabien Dessenne <fabien.dessenne@st.com>");
184 MODULE_AUTHOR("Mickael Reulier <mickael.reulier@st.com>");
185 MODULE_DESCRIPTION("STMicroelectronics ST DRM LTDC driver");
186 MODULE_LICENSE("GPL v2");