NV50: basic fbcon + misc fixes
[platform/upstream/libdrm.git] / linux-core / drm_crtc_helper.h
1 /*
2  * Copyright © 2006 Keith Packard
3  * Copyright © 2007 Intel Corporation
4  *   Jesse Barnes <jesse.barnes@intel.com>
5  */
6
7 /*
8  * The DRM mode setting helper functions are common code for drivers to use if they wish.
9  * Drivers are not forced to use this code in their implementations but it would be useful
10  * if they code they do use at least provides a consistent interface and operation to userspace
11  */
12
13 #ifndef __DRM_CRTC_HELPER_H__
14 #define __DRM_CRTC_HELPER_H__
15
16 #include <linux/i2c.h>
17 #include <linux/spinlock.h>
18 #include <linux/types.h>
19 #include <linux/idr.h>
20
21 #include <linux/fb.h>
22
23 struct drm_crtc_helper_funcs {
24         /*
25          * Control power levels on the CRTC.  If the mode passed in is
26          * unsupported, the provider must use the next lowest power level.
27          */
28         void (*dpms)(struct drm_crtc *crtc, int mode);
29         void (*prepare)(struct drm_crtc *crtc);
30         void (*commit)(struct drm_crtc *crtc);
31
32         /* Provider can fixup or change mode timings before modeset occurs */
33         bool (*mode_fixup)(struct drm_crtc *crtc,
34                            struct drm_display_mode *mode,
35                            struct drm_display_mode *adjusted_mode);
36         /* Actually set the mode */
37         void (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
38                          struct drm_display_mode *adjusted_mode, int x, int y);
39
40         /* Move the crtc on the current fb to the given position *optional* */
41         void (*mode_set_base)(struct drm_crtc *crtc, int x, int y);
42 };
43
44 struct drm_encoder_helper_funcs {
45         void (*dpms)(struct drm_encoder *encoder, int mode);
46         void (*save)(struct drm_encoder *encoder);
47         void (*restore)(struct drm_encoder *encoder);
48
49         bool (*mode_fixup)(struct drm_encoder *encoder,
50                            struct drm_display_mode *mode,
51                            struct drm_display_mode *adjusted_mode);
52         void (*prepare)(struct drm_encoder *encoder);
53         void (*commit)(struct drm_encoder *encoder);
54         void (*mode_set)(struct drm_encoder *encoder,
55                          struct drm_display_mode *mode,
56                          struct drm_display_mode *adjusted_mode);
57 };
58
59 struct drm_connector_helper_funcs {
60         int (*get_modes)(struct drm_connector *connector);
61         int (*mode_valid)(struct drm_connector *connector,
62                           struct drm_display_mode *mode);
63         struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
64 };
65         
66 extern void drm_helper_probe_single_connector_modes(struct drm_connector *connector, uint32_t maxX, uint32_t maxY);
67 extern void drm_helper_disable_unused_functions(struct drm_device *dev);
68 extern int drm_helper_hotplug_stage_two(struct drm_device *dev);
69 extern bool drm_helper_initial_config(struct drm_device *dev, bool can_grow);
70 extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
71 extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
72                                      int x, int y);
73 extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
74
75 extern int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
76                                           struct drm_mode_fb_cmd *mode_cmd);
77
78 static inline void drm_crtc_helper_add(struct drm_crtc *crtc, const struct drm_crtc_helper_funcs *funcs)
79 {
80         crtc->helper_private = (void *)funcs;
81 }
82
83 static inline void drm_encoder_helper_add(struct drm_encoder *encoder, const struct drm_encoder_helper_funcs *funcs)
84 {
85         encoder->helper_private = (void *)funcs;
86 }
87
88 static inline void drm_connector_helper_add(struct drm_connector *connector, const struct drm_connector_helper_funcs *funcs)
89 {
90         connector->helper_private = (void *)funcs;
91 }
92
93 extern int drm_get_buffer_object(struct drm_device *dev, struct drm_buffer_object **bo, unsigned long handle);
94
95 #endif