#include <linux/component.h>
#include <linux/of_platform.h>
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_cma_helper.h>
#include <drm/drm_gem_cma_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
DEFINE_DRM_GEM_CMA_FOPS(drv_driver_fops);
static struct drm_driver drv_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | DRIVER_ATOMIC,
// .lastclose = drv_lastclose,
.name = "mydrm",
.desc = "My drm demo",
.date = "20170330",
.major = 1,
.minor = 0,
.patchlevel = 0,
.fops = &drv_driver_fops,
.dumb_create = drm_gem_cma_dumb_create,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_free_object_unlocked = drm_gem_cma_free_object,
.gem_vm_ops = &drm_gem_cma_vm_ops,
.gem_prime_export = drm_gem_prime_export,
.gem_prime_import = drm_gem_prime_import,
.gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
.gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
.gem_prime_vmap = drm_gem_cma_prime_vmap,
.gem_prime_vunmap = drm_gem_cma_prime_vunmap,
.gem_prime_mmap = drm_gem_cma_prime_mmap,
// .enable_vblank = ltdc_crtc_enable_vblank,
// .disable_vblank = ltdc_crtc_disable_vblank,
};
static const struct drm_mode_config_funcs drv_mode_config_funcs = {
.fb_create = drm_gem_fb_create,
// .output_poll_changed = drv_output_poll_changed,
.atomic_check = drm_atomic_helper_check,
.atomic_commit = drm_atomic_helper_commit,
};
void mydev_setup(struct drm_device *ddev)
{
/* 模式设置 */
drm_mode_config_init(ddev);
/*
* set max width and height as default value.
* this value would be used to check framebuffer size limitation
* at drm_mode_addfb().
*/
ddev->mode_config.min_width = 0;
ddev->mode_config.min_height = 0;
ddev->mode_config.max_width = 240;
ddev->mode_config.max_height = 240;
ddev->mode_config.funcs = &drv_mode_config_funcs;
drm_mode_config_reset(ddev);
drm_kms_helper_poll_init(ddev);
}
static int mydrm_driver_probe(struct platform_device *pdev)
{
struct drm_device *ddev;
int ret;
ddev = drm_dev_alloc(&drv_driver, &pdev->dev);
if (IS_ERR(ddev))
return PTR_ERR(ddev);
mydev_setup(ddev);
ret = drm_dev_register(ddev, 0);
printk("mydrm init done!\n");
return 0;
}
static int mydrm_driver_remove(struct platform_device *pdev)
{
return 0;
}
static struct platform_driver mydrm_driver = {
.probe = mydrm_driver_probe,
.remove = mydrm_driver_remove,
.driver = {
.name = "mydrm",
},
};
static struct platform_device *mypdev;
static int mydrm_init(void)
{
int ret ;
/* 创建一个平台设备 */
mypdev = platform_device_register_simple("mydrm", -1, NULL, 0);
if (IS_ERR(mypdev))
return PTR_ERR(mypdev);
/* 注册平台驱动 */
ret = platform_driver_register(&mydrm_driver);
if(ret)
platform_device_unregister(mypdev);
return ret;
}
static void mydrm_exit(void)
{
platform_device_unregister(mypdev);
platform_driver_unregister(&mydrm_driver);
}
module_init(mydrm_init);
module_exit(mydrm_exit);
MODULE_LICENSE("GPL v2");
```
网友评论