Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / video / cmdline.c
blob49ee3fb4951a55b3cbe11c387191a70cc0c162c8
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Based on the fbdev code in drivers/video/fbdev/core/fb_cmdline:
5 * Copyright (C) 2014 Intel Corp
6 * Copyright (C) 1994 Martin Schaller
8 * 2001 - Documented with DocBook
9 * - Brad Douglas <brad@neruo.com>
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive
13 * for more details.
15 * Authors:
16 * Daniel Vetter <daniel.vetter@ffwll.ch>
19 #include <linux/fb.h> /* for FB_MAX */
20 #include <linux/init.h>
22 #include <video/cmdline.h>
25 * FB_MAX is the maximum number of framebuffer devices and also
26 * the maximum number of video= parameters. Although not directly
27 * related to each other, it makes sense to keep it that way.
29 static const char *video_options[FB_MAX] __read_mostly;
30 static const char *video_option __read_mostly;
31 static int video_of_only __read_mostly;
33 static const char *__video_get_option_string(const char *name)
35 const char *options = NULL;
36 size_t name_len = 0;
38 if (name)
39 name_len = strlen(name);
41 if (name_len) {
42 unsigned int i;
43 const char *opt;
45 for (i = 0; i < ARRAY_SIZE(video_options); ++i) {
46 if (!video_options[i])
47 continue;
48 if (video_options[i][0] == '\0')
49 continue;
50 opt = video_options[i];
51 if (!strncmp(opt, name, name_len) && opt[name_len] == ':')
52 options = opt + name_len + 1;
56 /* No match, return global options */
57 if (!options)
58 options = video_option;
60 return options;
63 /**
64 * video_get_options - get kernel boot parameters
65 * @name: name of the output as it would appear in the boot parameter
66 * line (video=<name>:<options>)
68 * Looks up the video= options for the given name. Names are connector
69 * names with DRM, or driver names with fbdev. If no video option for
70 * the name has been specified, the function returns the global video=
71 * setting. A @name of NULL always returns the global video setting.
73 * Returns:
74 * The string of video options for the given name, or NULL if no video
75 * option has been specified.
77 const char *video_get_options(const char *name)
79 return __video_get_option_string(name);
81 EXPORT_SYMBOL(video_get_options);
83 #if IS_ENABLED(CONFIG_FB_CORE)
84 bool __video_get_options(const char *name, const char **options, bool is_of)
86 bool enabled = true;
87 const char *opt = NULL;
89 if (video_of_only && !is_of)
90 enabled = false;
92 opt = __video_get_option_string(name);
94 if (options)
95 *options = opt;
97 return enabled;
99 EXPORT_SYMBOL(__video_get_options);
100 #endif
103 * Process command line options for video adapters. This function is
104 * a __setup and __init function. It only stores the options. Drivers
105 * have to call video_get_options() as necessary.
107 static int __init video_setup(char *options)
109 if (!options || !*options)
110 goto out;
112 if (!strncmp(options, "ofonly", 6)) {
113 video_of_only = true;
114 goto out;
117 if (strchr(options, ':')) {
118 /* named */
119 size_t i;
121 for (i = 0; i < ARRAY_SIZE(video_options); i++) {
122 if (!video_options[i]) {
123 video_options[i] = options;
124 break;
127 } else {
128 /* global */
129 video_option = options;
132 out:
133 return 1;
135 __setup("video=", video_setup);