xref: /linux/drivers/gpu/drm/clients/drm_client_setup.c (revision 33b4e4fcd2980ee5fd754731ca9b0325f0344f04)
1 // SPDX-License-Identifier: MIT
2 
3 #include <linux/export.h>
4 
5 #include <drm/clients/drm_client_setup.h>
6 #include <drm/drm_device.h>
7 #include <drm/drm_fourcc.h>
8 #include <drm/drm_print.h>
9 
10 #include "drm_client_internal.h"
11 
12 static char drm_client_default[16] = CONFIG_DRM_CLIENT_DEFAULT;
13 module_param_string(active, drm_client_default, sizeof(drm_client_default), 0444);
14 MODULE_PARM_DESC(active,
15 		 "Choose which drm client to start, default is"
16 		 CONFIG_DRM_CLIENT_DEFAULT "]");
17 
18 /**
19  * drm_client_setup() - Setup in-kernel DRM clients
20  * @dev: DRM device
21  * @format: Preferred pixel format for the device. Use NULL, unless
22  *          there is clearly a driver-preferred format.
23  *
24  * This function sets up the in-kernel DRM clients. Restore, hotplug
25  * events and teardown are all taken care of.
26  *
27  * Drivers should call drm_client_setup() after registering the new
28  * DRM device with drm_dev_register(). This function is safe to call
29  * even when there are no connectors present. Setup will be retried
30  * on the next hotplug event.
31  *
32  * The clients are destroyed by drm_dev_unregister().
33  */
34 void drm_client_setup(struct drm_device *dev, const struct drm_format_info *format)
35 {
36 
37 #ifdef CONFIG_DRM_FBDEV_EMULATION
38 	if (!strcmp(drm_client_default, "fbdev")) {
39 		int ret;
40 
41 		ret = drm_fbdev_client_setup(dev, format);
42 		if (ret)
43 			drm_warn(dev, "Failed to set up DRM client; error %d\n", ret);
44 		return;
45 	}
46 #endif
47 
48 #ifdef CONFIG_DRM_CLIENT_LOG
49 	if (!strcmp(drm_client_default, "log")) {
50 		drm_log_register(dev);
51 		return;
52 	}
53 #endif
54 	if (strcmp(drm_client_default, ""))
55 		drm_warn(dev, "Unknown DRM client %s\n", drm_client_default);
56 }
57 EXPORT_SYMBOL(drm_client_setup);
58 
59 /**
60  * drm_client_setup_with_fourcc() - Setup in-kernel DRM clients for color mode
61  * @dev: DRM device
62  * @fourcc: Preferred pixel format as 4CC code for the device
63  *
64  * This function sets up the in-kernel DRM clients. It is equivalent
65  * to drm_client_setup(), but expects a 4CC code as second argument.
66  */
67 void drm_client_setup_with_fourcc(struct drm_device *dev, u32 fourcc)
68 {
69 	drm_client_setup(dev, drm_format_info(fourcc));
70 }
71 EXPORT_SYMBOL(drm_client_setup_with_fourcc);
72 
73 /**
74  * drm_client_setup_with_color_mode() - Setup in-kernel DRM clients for color mode
75  * @dev: DRM device
76  * @color_mode: Preferred color mode for the device
77  *
78  * This function sets up the in-kernel DRM clients. It is equivalent
79  * to drm_client_setup(), but expects a color mode as second argument.
80  *
81  * Do not use this function in new drivers. Prefer drm_client_setup() with a
82  * format of NULL.
83  */
84 void drm_client_setup_with_color_mode(struct drm_device *dev, unsigned int color_mode)
85 {
86 	u32 fourcc = drm_driver_color_mode_format(dev, color_mode);
87 
88 	drm_client_setup_with_fourcc(dev, fourcc);
89 }
90 EXPORT_SYMBOL(drm_client_setup_with_color_mode);
91 
92 MODULE_DESCRIPTION("In-kernel DRM clients");
93 MODULE_LICENSE("GPL and additional rights");
94