xref: /linux/drivers/gpu/drm/sysfb/drm_sysfb_helper.h (revision ea86aba47c3a724ea18a26ad498c1835f087dc63)
1b5626f6fSThomas Zimmermann /* SPDX-License-Identifier: GPL-2.0-only */
2b5626f6fSThomas Zimmermann 
3b5626f6fSThomas Zimmermann #ifndef DRM_SYSFB_HELPER_H
4b5626f6fSThomas Zimmermann #define DRM_SYSFB_HELPER_H
5b5626f6fSThomas Zimmermann 
6b5626f6fSThomas Zimmermann #include <linux/container_of.h>
7b5626f6fSThomas Zimmermann #include <linux/iosys-map.h>
8b5626f6fSThomas Zimmermann 
968ab3253SThomas Zimmermann #include <drm/drm_crtc.h>
10b5626f6fSThomas Zimmermann #include <drm/drm_device.h>
11b5626f6fSThomas Zimmermann #include <drm/drm_modes.h>
12b5626f6fSThomas Zimmermann 
13b5626f6fSThomas Zimmermann struct drm_format_info;
14b5626f6fSThomas Zimmermann 
15333376e9SThomas Zimmermann struct drm_display_mode drm_sysfb_mode(unsigned int width,
16333376e9SThomas Zimmermann 				       unsigned int height,
17333376e9SThomas Zimmermann 				       unsigned int width_mm,
18333376e9SThomas Zimmermann 				       unsigned int height_mm);
19333376e9SThomas Zimmermann 
20b5626f6fSThomas Zimmermann /*
21b5626f6fSThomas Zimmermann  * Device
22b5626f6fSThomas Zimmermann  */
23b5626f6fSThomas Zimmermann 
24b5626f6fSThomas Zimmermann struct drm_sysfb_device {
25b5626f6fSThomas Zimmermann 	struct drm_device dev;
26b5626f6fSThomas Zimmermann 
27b5626f6fSThomas Zimmermann 	/* hardware settings */
28b5626f6fSThomas Zimmermann 	struct drm_display_mode fb_mode;
29b5626f6fSThomas Zimmermann 	const struct drm_format_info *fb_format;
30b5626f6fSThomas Zimmermann 	unsigned int fb_pitch;
31*ea86aba4SThomas Zimmermann 	unsigned int fb_gamma_lut_size;
32b5626f6fSThomas Zimmermann 
33b5626f6fSThomas Zimmermann 	/* hardware-framebuffer kernel address */
34b5626f6fSThomas Zimmermann 	struct iosys_map fb_addr;
35b5626f6fSThomas Zimmermann };
36b5626f6fSThomas Zimmermann 
37b5626f6fSThomas Zimmermann static inline struct drm_sysfb_device *to_drm_sysfb_device(struct drm_device *dev)
38b5626f6fSThomas Zimmermann {
39b5626f6fSThomas Zimmermann 	return container_of(dev, struct drm_sysfb_device, dev);
40b5626f6fSThomas Zimmermann }
41b5626f6fSThomas Zimmermann 
42559d105fSThomas Zimmermann /*
4368ab3253SThomas Zimmermann  * CRTC
4468ab3253SThomas Zimmermann  */
4568ab3253SThomas Zimmermann 
4668ab3253SThomas Zimmermann struct drm_sysfb_crtc_state {
4768ab3253SThomas Zimmermann 	struct drm_crtc_state base;
4868ab3253SThomas Zimmermann 
4968ab3253SThomas Zimmermann 	/* Primary-plane format; required for color mgmt. */
5068ab3253SThomas Zimmermann 	const struct drm_format_info *format;
5168ab3253SThomas Zimmermann };
5268ab3253SThomas Zimmermann 
5368ab3253SThomas Zimmermann static inline struct drm_sysfb_crtc_state *
5468ab3253SThomas Zimmermann to_drm_sysfb_crtc_state(struct drm_crtc_state *base)
5568ab3253SThomas Zimmermann {
5668ab3253SThomas Zimmermann 	return container_of(base, struct drm_sysfb_crtc_state, base);
5768ab3253SThomas Zimmermann }
5868ab3253SThomas Zimmermann 
59*ea86aba4SThomas Zimmermann enum drm_mode_status drm_sysfb_crtc_helper_mode_valid(struct drm_crtc *crtc,
60*ea86aba4SThomas Zimmermann 						      const struct drm_display_mode *mode);
61*ea86aba4SThomas Zimmermann int drm_sysfb_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *new_state);
62*ea86aba4SThomas Zimmermann 
63*ea86aba4SThomas Zimmermann #define DRM_SYSFB_CRTC_HELPER_FUNCS \
64*ea86aba4SThomas Zimmermann 	.mode_valid = drm_sysfb_crtc_helper_mode_valid, \
65*ea86aba4SThomas Zimmermann 	.atomic_check = drm_sysfb_crtc_helper_atomic_check
66*ea86aba4SThomas Zimmermann 
6768ab3253SThomas Zimmermann void drm_sysfb_crtc_reset(struct drm_crtc *crtc);
6868ab3253SThomas Zimmermann struct drm_crtc_state *drm_sysfb_crtc_atomic_duplicate_state(struct drm_crtc *crtc);
6968ab3253SThomas Zimmermann void drm_sysfb_crtc_atomic_destroy_state(struct drm_crtc *crtc, struct drm_crtc_state *crtc_state);
7068ab3253SThomas Zimmermann 
7168ab3253SThomas Zimmermann #define DRM_SYSFB_CRTC_FUNCS \
7268ab3253SThomas Zimmermann 	.reset = drm_sysfb_crtc_reset, \
7368ab3253SThomas Zimmermann 	.set_config = drm_atomic_helper_set_config, \
7468ab3253SThomas Zimmermann 	.page_flip = drm_atomic_helper_page_flip, \
7568ab3253SThomas Zimmermann 	.atomic_duplicate_state = drm_sysfb_crtc_atomic_duplicate_state, \
7668ab3253SThomas Zimmermann 	.atomic_destroy_state = drm_sysfb_crtc_atomic_destroy_state
7768ab3253SThomas Zimmermann 
7868ab3253SThomas Zimmermann /*
7901e48e52SThomas Zimmermann  * Connector
8001e48e52SThomas Zimmermann  */
8101e48e52SThomas Zimmermann 
8201e48e52SThomas Zimmermann int drm_sysfb_connector_helper_get_modes(struct drm_connector *connector);
8301e48e52SThomas Zimmermann 
8401e48e52SThomas Zimmermann #define DRM_SYSFB_CONNECTOR_HELPER_FUNCS \
8501e48e52SThomas Zimmermann 	.get_modes = drm_sysfb_connector_helper_get_modes
8601e48e52SThomas Zimmermann 
8701e48e52SThomas Zimmermann #define DRM_SYSFB_CONNECTOR_FUNCS \
8801e48e52SThomas Zimmermann 	.reset = drm_atomic_helper_connector_reset, \
8901e48e52SThomas Zimmermann 	.fill_modes = drm_helper_probe_single_connector_modes, \
9001e48e52SThomas Zimmermann 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, \
9101e48e52SThomas Zimmermann 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state
9201e48e52SThomas Zimmermann 
9301e48e52SThomas Zimmermann /*
94559d105fSThomas Zimmermann  * Mode config
95559d105fSThomas Zimmermann  */
96559d105fSThomas Zimmermann 
97559d105fSThomas Zimmermann #define DRM_SYSFB_MODE_CONFIG_FUNCS \
98559d105fSThomas Zimmermann 	.fb_create = drm_gem_fb_create_with_dirty, \
99559d105fSThomas Zimmermann 	.atomic_check = drm_atomic_helper_check, \
100559d105fSThomas Zimmermann 	.atomic_commit = drm_atomic_helper_commit
101559d105fSThomas Zimmermann 
102b5626f6fSThomas Zimmermann #endif
103