Skip to content

Commit d07fdf9

Browse files
author
Thomas Zimmermann
committed
drm: Add client-agnostic setup helper
DRM may support multiple in-kernel clients that run as soon as a DRM driver has been registered. To select the client(s) in a single place, introduce drm_client_setup(). Drivers that call the new helper automatically instantiate the kernel's configured default clients. Only fbdev emulation is currently supported. Later versions can add support for DRM-based logging, a boot logo or even a console. Some drivers handle the color mode for clients internally. Provide the helper drm_client_setup_with_color_mode() for them. Using the new interface requires the driver to select DRM_CLIENT_SELECTION in its Kconfig. For now this only enables the client-setup helpers if the fbdev client has been configured by the user. A future patchset will further modularize client support and rework DRM_CLIENT_SELECTION to select the correct dependencies for all its clients. v5: - add CONFIG_DRM_CLIENT_SELECTION und DRM_CLIENT_SETUP v4: - fix docs for drm_client_setup_with_fourcc() (Geert) v3: - fix build error v2: - add drm_client_setup_with_fourcc() (Laurent) - push default-format handling into actual clients Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5d08c44 commit d07fdf9

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

drivers/gpu/drm/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ config DRM_DEBUG_MODESET_LOCK
210210

211211
If in doubt, say "N".
212212

213+
config DRM_CLIENT_SELECTION
214+
bool
215+
depends on DRM
216+
select DRM_CLIENT_SETUP if DRM_FBDEV_EMULATION
217+
help
218+
Drivers that support in-kernel DRM clients have to select this
219+
option.
220+
221+
config DRM_CLIENT_SETUP
222+
bool
223+
depends on DRM_CLIENT_SELECTION
224+
213225
config DRM_FBDEV_EMULATION
214226
bool "Enable legacy fbdev support for your modesetting driver"
215227
depends on DRM

drivers/gpu/drm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ drm_kms_helper-y := \
143143
drm_probe_helper.o \
144144
drm_self_refresh_helper.o \
145145
drm_simple_kms_helper.o
146+
drm_kms_helper-$(CONFIG_DRM_CLIENT_SETUP) += \
147+
drm_client_setup.o
146148
drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
147149
drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += \
148150
drm_fbdev_client.o \

drivers/gpu/drm/drm_client_setup.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
#include <drm/drm_client_setup.h>
4+
#include <drm/drm_device.h>
5+
#include <drm/drm_fbdev_client.h>
6+
#include <drm/drm_fourcc.h>
7+
#include <drm/drm_print.h>
8+
9+
/**
10+
* drm_client_setup() - Setup in-kernel DRM clients
11+
* @dev: DRM device
12+
* @format: Preferred pixel format for the device. Use NULL, unless
13+
* there is clearly a driver-preferred format.
14+
*
15+
* This function sets up the in-kernel DRM clients. Restore, hotplug
16+
* events and teardown are all taken care of.
17+
*
18+
* Drivers should call drm_client_setup() after registering the new
19+
* DRM device with drm_dev_register(). This function is safe to call
20+
* even when there are no connectors present. Setup will be retried
21+
* on the next hotplug event.
22+
*
23+
* The clients are destroyed by drm_dev_unregister().
24+
*/
25+
void drm_client_setup(struct drm_device *dev, const struct drm_format_info *format)
26+
{
27+
int ret;
28+
29+
ret = drm_fbdev_client_setup(dev, format);
30+
if (ret)
31+
drm_warn(dev, "Failed to set up DRM client; error %d\n", ret);
32+
}
33+
EXPORT_SYMBOL(drm_client_setup);
34+
35+
/**
36+
* drm_client_setup_with_fourcc() - Setup in-kernel DRM clients for color mode
37+
* @dev: DRM device
38+
* @fourcc: Preferred pixel format as 4CC code for the device
39+
*
40+
* This function sets up the in-kernel DRM clients. It is equivalent
41+
* to drm_client_setup(), but expects a 4CC code as second argument.
42+
*/
43+
void drm_client_setup_with_fourcc(struct drm_device *dev, u32 fourcc)
44+
{
45+
drm_client_setup(dev, drm_format_info(fourcc));
46+
}
47+
EXPORT_SYMBOL(drm_client_setup_with_fourcc);
48+
49+
/**
50+
* drm_client_setup_with_color_mode() - Setup in-kernel DRM clients for color mode
51+
* @dev: DRM device
52+
* @color_mode: Preferred color mode for the device
53+
*
54+
* This function sets up the in-kernel DRM clients. It is equivalent
55+
* to drm_client_setup(), but expects a color mode as second argument.
56+
*
57+
* Do not use this function in new drivers. Prefer drm_client_setup() with a
58+
* format of NULL.
59+
*/
60+
void drm_client_setup_with_color_mode(struct drm_device *dev, unsigned int color_mode)
61+
{
62+
u32 fourcc = drm_driver_color_mode_format(dev, color_mode);
63+
64+
drm_client_setup_with_fourcc(dev, fourcc);
65+
}
66+
EXPORT_SYMBOL(drm_client_setup_with_color_mode);

include/drm/drm_client_setup.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* SPDX-License-Identifier: MIT */
2+
3+
#ifndef DRM_CLIENT_SETUP_H
4+
#define DRM_CLIENT_SETUP_H
5+
6+
#include <linux/types.h>
7+
8+
struct drm_device;
9+
struct drm_format_info;
10+
11+
#if defined(CONFIG_DRM_CLIENT_SETUP)
12+
void drm_client_setup(struct drm_device *dev, const struct drm_format_info *format);
13+
void drm_client_setup_with_fourcc(struct drm_device *dev, u32 fourcc);
14+
void drm_client_setup_with_color_mode(struct drm_device *dev, unsigned int color_mode);
15+
#else
16+
static inline void drm_client_setup(struct drm_device *dev,
17+
const struct drm_format_info *format)
18+
{ }
19+
static inline void drm_client_setup_with_fourcc(struct drm_device *dev, u32 fourcc)
20+
{ }
21+
static inline void drm_client_setup_with_color_mode(struct drm_device *dev,
22+
unsigned int color_mode)
23+
{ }
24+
#endif
25+
26+
#endif

0 commit comments

Comments
 (0)