Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Herrmann | e3263ab | 2013-08-02 14:05:22 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Generic System Framebuffers on x86 |
| 4 | * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> |
David Herrmann | e3263ab | 2013-08-02 14:05:22 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Simple-Framebuffer support for x86 systems |
| 9 | * 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 | * |
| 19 | * If CONFIG_X86_SYSFB is not selected, we never register "simple-framebuffer" |
| 20 | * 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 |
| 24 | * other x86 OF/DT parsers to create such devices, too. However, they must |
| 25 | * 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 Canillas | d391c58 | 2021-06-25 15:09:46 +0200 | [diff] [blame^] | 35 | #include <linux/sysfb.h> |
David Herrmann | e3263ab | 2013-08-02 14:05:22 +0200 | [diff] [blame] | 36 | |
| 37 | static __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 | |
David Herrmann | 2995e50 | 2013-08-02 14:05:23 +0200 | [diff] [blame] | 46 | sysfb_apply_efi_quirks(); |
| 47 | |
David Herrmann | e3263ab | 2013-08-02 14:05:22 +0200 | [diff] [blame] | 48 | /* try to create a simple-framebuffer device */ |
| 49 | compatible = parse_mode(si, &mode); |
| 50 | if (compatible) { |
| 51 | ret = create_simplefb(si, &mode); |
| 52 | if (!ret) |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | /* if the FB is incompatible, create a legacy framebuffer device */ |
| 57 | if (si->orig_video_isVGA == VIDEO_TYPE_EFI) |
| 58 | name = "efi-framebuffer"; |
| 59 | else if (si->orig_video_isVGA == VIDEO_TYPE_VLFB) |
| 60 | name = "vesa-framebuffer"; |
| 61 | else |
| 62 | name = "platform-framebuffer"; |
| 63 | |
| 64 | pd = platform_device_register_resndata(NULL, name, 0, |
| 65 | NULL, 0, si, sizeof(*si)); |
Fabian Frederick | e8d95ce | 2014-10-17 22:00:53 +0200 | [diff] [blame] | 66 | return PTR_ERR_OR_ZERO(pd); |
David Herrmann | e3263ab | 2013-08-02 14:05:22 +0200 | [diff] [blame] | 67 | } |
| 68 | |
David Herrmann | 2995e50 | 2013-08-02 14:05:23 +0200 | [diff] [blame] | 69 | /* must execute after PCI subsystem for EFI quirks */ |
David Herrmann | e3263ab | 2013-08-02 14:05:22 +0200 | [diff] [blame] | 70 | device_initcall(sysfb_init); |