xref: /openbmc/linux/include/drm/drm_fb_helper.h (revision 47074ab7)
1785b93efSDave Airlie /*
2785b93efSDave Airlie  * Copyright (c) 2006-2009 Red Hat Inc.
3785b93efSDave Airlie  * Copyright (c) 2006-2008 Intel Corporation
4785b93efSDave Airlie  * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
5785b93efSDave Airlie  *
6785b93efSDave Airlie  * DRM framebuffer helper functions
7785b93efSDave Airlie  *
8785b93efSDave Airlie  * Permission to use, copy, modify, distribute, and sell this software and its
9785b93efSDave Airlie  * documentation for any purpose is hereby granted without fee, provided that
10785b93efSDave Airlie  * the above copyright notice appear in all copies and that both that copyright
11785b93efSDave Airlie  * notice and this permission notice appear in supporting documentation, and
12785b93efSDave Airlie  * that the name of the copyright holders not be used in advertising or
13785b93efSDave Airlie  * publicity pertaining to distribution of the software without specific,
14785b93efSDave Airlie  * written prior permission.  The copyright holders make no representations
15785b93efSDave Airlie  * about the suitability of this software for any purpose.  It is provided "as
16785b93efSDave Airlie  * is" without express or implied warranty.
17785b93efSDave Airlie  *
18785b93efSDave Airlie  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19785b93efSDave Airlie  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20785b93efSDave Airlie  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21785b93efSDave Airlie  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22785b93efSDave Airlie  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23785b93efSDave Airlie  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24785b93efSDave Airlie  * OF THIS SOFTWARE.
25785b93efSDave Airlie  *
26785b93efSDave Airlie  * Authors:
27785b93efSDave Airlie  *      Dave Airlie <airlied@linux.ie>
28785b93efSDave Airlie  *      Jesse Barnes <jesse.barnes@intel.com>
29785b93efSDave Airlie  */
30785b93efSDave Airlie #ifndef DRM_FB_HELPER_H
31785b93efSDave Airlie #define DRM_FB_HELPER_H
32785b93efSDave Airlie 
334abe3520SDave Airlie struct drm_fb_helper;
344abe3520SDave Airlie 
351a7aba7fSJesse Barnes #include <linux/kgdb.h>
361a7aba7fSJesse Barnes 
37b0ee9e7fSDave Airlie struct drm_fb_offset {
38b0ee9e7fSDave Airlie 	int x, y;
39b0ee9e7fSDave Airlie };
40b0ee9e7fSDave Airlie 
41785b93efSDave Airlie struct drm_fb_helper_crtc {
42785b93efSDave Airlie 	struct drm_mode_set mode_set;
438be48d92SDave Airlie 	struct drm_display_mode *desired_mode;
44b0ee9e7fSDave Airlie 	int x, y;
45785b93efSDave Airlie };
46785b93efSDave Airlie 
47b7b5ee59SRob Clark /**
48b7b5ee59SRob Clark  * struct drm_fb_helper_surface_size - describes fbdev size and scanout surface size
49b7b5ee59SRob Clark  * @fb_width: fbdev width
50b7b5ee59SRob Clark  * @fb_height: fbdev height
51b7b5ee59SRob Clark  * @surface_width: scanout buffer width
52b7b5ee59SRob Clark  * @surface_height: scanout buffer height
53b7b5ee59SRob Clark  * @surface_bpp: scanout buffer bpp
54b7b5ee59SRob Clark  * @surface_depth: scanout buffer depth
55b7b5ee59SRob Clark  *
56b7b5ee59SRob Clark  * Note that the scanout surface width/height may be larger than the fbdev
57b7b5ee59SRob Clark  * width/height.  In case of multiple displays, the scanout surface is sized
58b7b5ee59SRob Clark  * according to the largest width/height (so it is large enough for all CRTCs
59b7b5ee59SRob Clark  * to scanout).  But the fbdev width/height is sized to the minimum width/
60b7b5ee59SRob Clark  * height of all the displays.  This ensures that fbcon fits on the smallest
61b7b5ee59SRob Clark  * of the attached displays.
62b7b5ee59SRob Clark  *
63b7b5ee59SRob Clark  * So what is passed to drm_fb_helper_fill_var() should be fb_width/fb_height,
64b7b5ee59SRob Clark  * rather than the surface size.
65b7b5ee59SRob Clark  */
6638651674SDave Airlie struct drm_fb_helper_surface_size {
6738651674SDave Airlie 	u32 fb_width;
6838651674SDave Airlie 	u32 fb_height;
6938651674SDave Airlie 	u32 surface_width;
7038651674SDave Airlie 	u32 surface_height;
7138651674SDave Airlie 	u32 surface_bpp;
7238651674SDave Airlie 	u32 surface_depth;
7338651674SDave Airlie };
7438651674SDave Airlie 
75207fd329SDaniel Vetter /**
76207fd329SDaniel Vetter  * struct drm_fb_helper_funcs - driver callbacks for the fbdev emulation library
777b97936fSVille Syrjälä  * @gamma_set: Set the given gamma lut register on the given crtc.
787b97936fSVille Syrjälä  * @gamma_get: Read the given gamma lut register on the given crtc, used to
79207fd329SDaniel Vetter  *             save the current lut when force-restoring the fbdev for e.g.
80207fd329SDaniel Vetter  *             kdbg.
817b97936fSVille Syrjälä  * @fb_probe: Driver callback to allocate and initialize the fbdev info
82e227867fSMasanari Iida  *            structure. Furthermore it also needs to allocate the drm
83207fd329SDaniel Vetter  *            framebuffer used to back the fbdev.
847b97936fSVille Syrjälä  * @initial_config: Setup an initial fbdev display configuration
85207fd329SDaniel Vetter  *
86207fd329SDaniel Vetter  * Driver callbacks used by the fbdev emulation helper library.
87207fd329SDaniel Vetter  */
884abe3520SDave Airlie struct drm_fb_helper_funcs {
894abe3520SDave Airlie 	void (*gamma_set)(struct drm_crtc *crtc, u16 red, u16 green,
904abe3520SDave Airlie 			  u16 blue, int regno);
914abe3520SDave Airlie 	void (*gamma_get)(struct drm_crtc *crtc, u16 *red, u16 *green,
924abe3520SDave Airlie 			  u16 *blue, int regno);
934abe3520SDave Airlie 
944abe3520SDave Airlie 	int (*fb_probe)(struct drm_fb_helper *helper,
954abe3520SDave Airlie 			struct drm_fb_helper_surface_size *sizes);
9611e17a08SJesse Barnes 	bool (*initial_config)(struct drm_fb_helper *fb_helper,
9711e17a08SJesse Barnes 			       struct drm_fb_helper_crtc **crtcs,
9811e17a08SJesse Barnes 			       struct drm_display_mode **modes,
99b0ee9e7fSDave Airlie 			       struct drm_fb_offset *offsets,
10011e17a08SJesse Barnes 			       bool *enabled, int width, int height);
1014abe3520SDave Airlie };
1024abe3520SDave Airlie 
103d50ba256SDave Airlie struct drm_fb_helper_connector {
1040b4c0f3fSDave Airlie 	struct drm_connector *connector;
105d50ba256SDave Airlie };
106d50ba256SDave Airlie 
107785b93efSDave Airlie struct drm_fb_helper {
108785b93efSDave Airlie 	struct drm_framebuffer *fb;
109785b93efSDave Airlie 	struct drm_device *dev;
110785b93efSDave Airlie 	int crtc_count;
111785b93efSDave Airlie 	struct drm_fb_helper_crtc *crtc_info;
1120b4c0f3fSDave Airlie 	int connector_count;
11365c2a89cSDave Airlie 	int connector_info_alloc_count;
1140b4c0f3fSDave Airlie 	struct drm_fb_helper_connector **connector_info;
1153a493879SThierry Reding 	const struct drm_fb_helper_funcs *funcs;
11638651674SDave Airlie 	struct fb_info *fbdev;
11738651674SDave Airlie 	u32 pseudo_palette[17];
118785b93efSDave Airlie 	struct list_head kernel_fb_list;
1198be48d92SDave Airlie 
1204abe3520SDave Airlie 	/* we got a hotplug but fbdev wasn't running the console
1214abe3520SDave Airlie 	   delay until next set_par */
1224abe3520SDave Airlie 	bool delayed_hotplug;
123785b93efSDave Airlie };
124785b93efSDave Airlie 
12510a23102SThierry Reding void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
12610a23102SThierry Reding 			   const struct drm_fb_helper_funcs *funcs);
1274abe3520SDave Airlie int drm_fb_helper_init(struct drm_device *dev,
1288be48d92SDave Airlie 		       struct drm_fb_helper *helper, int crtc_count,
129eb1f8e4fSDave Airlie 		       int max_conn);
1304abe3520SDave Airlie void drm_fb_helper_fini(struct drm_fb_helper *helper);
131785b93efSDave Airlie int drm_fb_helper_blank(int blank, struct fb_info *info);
132785b93efSDave Airlie int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
133785b93efSDave Airlie 			      struct fb_info *info);
134785b93efSDave Airlie int drm_fb_helper_set_par(struct fb_info *info);
135785b93efSDave Airlie int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
136785b93efSDave Airlie 			    struct fb_info *info);
137785b93efSDave Airlie 
1385ea1f752SRob Clark bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper);
139b8017d6cSArchit Taneja 
140b8017d6cSArchit Taneja struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper);
141b8017d6cSArchit Taneja void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper);
142b8017d6cSArchit Taneja void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper);
14338651674SDave Airlie void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
144785b93efSDave Airlie 			    uint32_t fb_width, uint32_t fb_height);
1453632ef89SDave Airlie void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1463632ef89SDave Airlie 			    uint32_t depth);
1473632ef89SDave Airlie 
14847074ab7SArchit Taneja void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper);
14947074ab7SArchit Taneja 
150068143d3SDave Airlie int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
151d50ba256SDave Airlie 
1527394371dSChris Wilson int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
15301934c2aSThierry Reding int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
1540b4c0f3fSDave Airlie int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper);
1551a7aba7fSJesse Barnes int drm_fb_helper_debug_enter(struct fb_info *info);
1561a7aba7fSJesse Barnes int drm_fb_helper_debug_leave(struct fb_info *info);
1572f1046f3SJesse Barnes struct drm_display_mode *
1582f1046f3SJesse Barnes drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
1592f1046f3SJesse Barnes 			int width, int height);
1602f1046f3SJesse Barnes struct drm_display_mode *
1612f1046f3SJesse Barnes drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1622f1046f3SJesse Barnes 		      int width, int height);
1638be48d92SDave Airlie 
16465c2a89cSDave Airlie int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector);
16565c2a89cSDave Airlie int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
16665c2a89cSDave Airlie 				       struct drm_connector *connector);
167785b93efSDave Airlie #endif
168