2 * Copyright (C) 2016 Noralf Trønnes
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
10 #ifndef __LINUX_TINYDRM_H
11 #define __LINUX_TINYDRM_H
13 #include <drm/drm_gem_cma_helper.h>
14 #include <drm/drm_fb_cma_helper.h>
15 #include <drm/drm_simple_kms_helper.h>
18 * struct tinydrm_device - tinydrm device
20 * @pipe: Display pipe structure
21 * @dirty_lock: Serializes framebuffer flushing
22 * @fbdev_cma: CMA fbdev structure
23 * @suspend_state: Atomic state when suspended
24 * @fb_funcs: Framebuffer functions used when creating framebuffers
26 struct tinydrm_device
{
27 struct drm_device
*drm
;
28 struct drm_simple_display_pipe pipe
;
29 struct mutex dirty_lock
;
30 struct drm_fbdev_cma
*fbdev_cma
;
31 struct drm_atomic_state
*suspend_state
;
32 const struct drm_framebuffer_funcs
*fb_funcs
;
35 static inline struct tinydrm_device
*
36 pipe_to_tinydrm(struct drm_simple_display_pipe
*pipe
)
38 return container_of(pipe
, struct tinydrm_device
, pipe
);
42 * TINYDRM_GEM_DRIVER_OPS - default tinydrm gem operations
44 * This macro provides a shortcut for setting the tinydrm GEM operations in
45 * the &drm_driver structure.
47 #define TINYDRM_GEM_DRIVER_OPS \
48 .gem_free_object = tinydrm_gem_cma_free_object, \
49 .gem_vm_ops = &drm_gem_cma_vm_ops, \
50 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \
51 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \
52 .gem_prime_import = drm_gem_prime_import, \
53 .gem_prime_export = drm_gem_prime_export, \
54 .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, \
55 .gem_prime_import_sg_table = tinydrm_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 .dumb_create = drm_gem_cma_dumb_create, \
60 .dumb_map_offset = drm_gem_cma_dumb_map_offset, \
61 .dumb_destroy = drm_gem_dumb_destroy
64 * TINYDRM_MODE - tinydrm display mode
65 * @hd: Horizontal resolution, width
66 * @vd: Vertical resolution, height
67 * @hd_mm: Display width in millimeters
68 * @vd_mm: Display height in millimeters
70 * This macro creates a &drm_display_mode for use with tinydrm.
72 #define TINYDRM_MODE(hd, vd, hd_mm, vd_mm) \
74 .hsync_start = (hd), \
78 .vsync_start = (vd), \
81 .width_mm = (hd_mm), \
82 .height_mm = (vd_mm), \
83 .type = DRM_MODE_TYPE_DRIVER, \
84 .clock = 1 /* pass validation */
86 void tinydrm_lastclose(struct drm_device
*drm
);
87 void tinydrm_gem_cma_free_object(struct drm_gem_object
*gem_obj
);
88 struct drm_gem_object
*
89 tinydrm_gem_cma_prime_import_sg_table(struct drm_device
*drm
,
90 struct dma_buf_attachment
*attach
,
91 struct sg_table
*sgt
);
92 int devm_tinydrm_init(struct device
*parent
, struct tinydrm_device
*tdev
,
93 const struct drm_framebuffer_funcs
*fb_funcs
,
94 struct drm_driver
*driver
);
95 int devm_tinydrm_register(struct tinydrm_device
*tdev
);
96 void tinydrm_shutdown(struct tinydrm_device
*tdev
);
97 int tinydrm_suspend(struct tinydrm_device
*tdev
);
98 int tinydrm_resume(struct tinydrm_device
*tdev
);
100 void tinydrm_display_pipe_update(struct drm_simple_display_pipe
*pipe
,
101 struct drm_plane_state
*old_state
);
102 int tinydrm_display_pipe_prepare_fb(struct drm_simple_display_pipe
*pipe
,
103 struct drm_plane_state
*plane_state
);
105 tinydrm_display_pipe_init(struct tinydrm_device
*tdev
,
106 const struct drm_simple_display_pipe_funcs
*funcs
,
108 const uint32_t *formats
,
109 unsigned int format_count
,
110 const struct drm_display_mode
*mode
,
111 unsigned int rotation
);
113 #endif /* __LINUX_TINYDRM_H */