blob: 2bfbb05f7d896912712679b9999060a2b04e4685 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Herrmanne3263ab2013-08-02 14:05:22 +02002/*
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +02003 * Generic System Framebuffers
David Herrmanne3263ab2013-08-02 14:05:22 +02004 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
David Herrmanne3263ab2013-08-02 14:05:22 +02005 */
6
7/*
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +02008 * Simple-Framebuffer support
David Herrmanne3263ab2013-08-02 14:05:22 +02009 * Create a platform-device for any available boot framebuffer. The
10 * simple-framebuffer platform device is already available on DT systems, so
11 * this module parses the global "screen_info" object and creates a suitable
12 * platform device compatible with the "simple-framebuffer" DT object. If
13 * the framebuffer is incompatible, we instead create a legacy
14 * "vesa-framebuffer", "efi-framebuffer" or "platform-framebuffer" device and
15 * pass the screen_info as platform_data. This allows legacy drivers
16 * to pick these devices up without messing with simple-framebuffer drivers.
17 * The global "screen_info" is still valid at all times.
18 *
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +020019 * If CONFIG_SYSFB_SIMPLEFB is not selected, never register "simple-framebuffer"
David Herrmanne3263ab2013-08-02 14:05:22 +020020 * platform devices, but only use legacy framebuffer devices for
21 * backwards compatibility.
22 *
23 * TODO: We set the dev_id field of all platform-devices to 0. This allows
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +020024 * other OF/DT parsers to create such devices, too. However, they must
David Herrmanne3263ab2013-08-02 14:05:22 +020025 * start at offset 1 for this to work.
26 */
27
28#include <linux/err.h>
29#include <linux/init.h>
30#include <linux/kernel.h>
31#include <linux/mm.h>
32#include <linux/platform_data/simplefb.h>
33#include <linux/platform_device.h>
34#include <linux/screen_info.h>
Javier Martinez Canillasd391c582021-06-25 15:09:46 +020035#include <linux/sysfb.h>
David Herrmanne3263ab2013-08-02 14:05:22 +020036
37static __init int sysfb_init(void)
38{
39 struct screen_info *si = &screen_info;
40 struct simplefb_platform_data mode;
41 struct platform_device *pd;
42 const char *name;
43 bool compatible;
44 int ret;
45
46 /* try to create a simple-framebuffer device */
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +020047 compatible = sysfb_parse_mode(si, &mode);
David Herrmanne3263ab2013-08-02 14:05:22 +020048 if (compatible) {
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +020049 ret = sysfb_create_simplefb(si, &mode);
David Herrmanne3263ab2013-08-02 14:05:22 +020050 if (!ret)
51 return 0;
52 }
53
54 /* if the FB is incompatible, create a legacy framebuffer device */
55 if (si->orig_video_isVGA == VIDEO_TYPE_EFI)
56 name = "efi-framebuffer";
57 else if (si->orig_video_isVGA == VIDEO_TYPE_VLFB)
58 name = "vesa-framebuffer";
59 else
60 name = "platform-framebuffer";
61
Javier Martinez Canillas8633ef82021-06-25 15:13:59 +020062 pd = platform_device_alloc(name, 0);
63 if (!pd)
64 return -ENOMEM;
65
66 sysfb_apply_efi_quirks(pd);
67
68 ret = platform_device_add_data(pd, si, sizeof(*si));
69 if (ret)
70 goto err;
71
72 ret = platform_device_add(pd);
73 if (ret)
74 goto err;
75
76 return 0;
77err:
78 platform_device_put(pd);
79 return ret;
David Herrmanne3263ab2013-08-02 14:05:22 +020080}
81
David Herrmann2995e502013-08-02 14:05:23 +020082/* must execute after PCI subsystem for EFI quirks */
David Herrmanne3263ab2013-08-02 14:05:22 +020083device_initcall(sysfb_init);