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