Merge tag 'rproc-v6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc...
[linux-block.git] / drivers / video / cmdline.c
CommitLineData
93604a5a
TZ
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Based on the fbdev code in drivers/video/fbdev/core/fb_cmdline:
4 *
5 * Copyright (C) 2014 Intel Corp
6 * Copyright (C) 1994 Martin Schaller
7 *
8 * 2001 - Documented with DocBook
9 * - Brad Douglas <brad@neruo.com>
10 *
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.
14 *
15 * Authors:
16 * Daniel Vetter <daniel.vetter@ffwll.ch>
17 */
18
19#include <linux/fb.h> /* for FB_MAX */
20#include <linux/init.h>
21
22#include <video/cmdline.h>
23
24/*
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.
28 */
29static const char *video_options[FB_MAX] __read_mostly;
30static const char *video_option __read_mostly;
31static int video_of_only __read_mostly;
32
33static const char *__video_get_option_string(const char *name)
34{
35 const char *options = NULL;
36 size_t name_len = 0;
37
38 if (name)
39 name_len = strlen(name);
40
41 if (name_len) {
42 unsigned int i;
43 const char *opt;
44
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;
53 }
54 }
55
56 /* No match, return global options */
57 if (!options)
58 options = video_option;
59
60 return options;
61}
62
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>)
67 *
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.
72 *
73 * Returns:
74 * The string of video options for the given name, or NULL if no video
75 * option has been specified.
76 */
77const char *video_get_options(const char *name)
78{
79 return __video_get_option_string(name);
80}
81EXPORT_SYMBOL(video_get_options);
82
83bool __video_get_options(const char *name, const char **options, bool is_of)
84{
85 bool enabled = true;
86 const char *opt = NULL;
87
88 if (video_of_only && !is_of)
89 enabled = false;
90
91 opt = __video_get_option_string(name);
92
93 if (options)
94 *options = opt;
95
96 return enabled;
97}
98EXPORT_SYMBOL(__video_get_options);
99
100/*
101 * Process command line options for video adapters. This function is
102 * a __setup and __init function. It only stores the options. Drivers
103 * have to call video_get_options() as necessary.
104 */
105static int __init video_setup(char *options)
106{
107 if (!options || !*options)
108 goto out;
109
110 if (!strncmp(options, "ofonly", 6)) {
111 video_of_only = true;
112 goto out;
113 }
114
115 if (strchr(options, ':')) {
116 /* named */
117 size_t i;
118
119 for (i = 0; i < ARRAY_SIZE(video_options); i++) {
120 if (!video_options[i]) {
121 video_options[i] = options;
122 break;
123 }
124 }
125 } else {
126 /* global */
127 video_option = options;
128 }
129
130out:
131 return 1;
132}
133__setup("video=", video_setup);