1 // SPDX-License-Identifier: GPL-2.0-only
3 * framebuffer-coreboot.c
5 * Memory based framebuffer accessed through coreboot table.
8 * Copyright 2017 Google Inc.
12 #include <linux/device.h>
13 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/platform_data/simplefb.h>
17 #include <linux/platform_device.h>
19 #include "coreboot_table.h"
21 #define CB_TAG_FRAMEBUFFER 0x12
23 static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
25 static int framebuffer_probe(struct coreboot_device *dev)
29 struct lb_framebuffer *fb = &dev->framebuffer;
30 struct platform_device *pdev;
32 struct simplefb_platform_data pdata = {
33 .width = fb->x_resolution,
34 .height = fb->y_resolution,
35 .stride = fb->bytes_per_line,
39 if (!fb->physical_address)
42 for (i = 0; i < ARRAY_SIZE(formats); ++i) {
43 if (fb->bits_per_pixel == formats[i].bits_per_pixel &&
44 fb->red_mask_pos == formats[i].red.offset &&
45 fb->red_mask_size == formats[i].red.length &&
46 fb->green_mask_pos == formats[i].green.offset &&
47 fb->green_mask_size == formats[i].green.length &&
48 fb->blue_mask_pos == formats[i].blue.offset &&
49 fb->blue_mask_size == formats[i].blue.length)
50 pdata.format = formats[i].name;
55 memset(&res, 0, sizeof(res));
56 res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
57 res.name = "Coreboot Framebuffer";
58 res.start = fb->physical_address;
59 length = PAGE_ALIGN(fb->y_resolution * fb->bytes_per_line);
60 res.end = res.start + length - 1;
61 if (res.end <= res.start)
64 pdev = platform_device_register_resndata(&dev->dev,
65 "simple-framebuffer", 0,
69 pr_warn("coreboot: could not register framebuffer\n");
71 dev_set_drvdata(&dev->dev, pdev);
73 return PTR_ERR_OR_ZERO(pdev);
76 static void framebuffer_remove(struct coreboot_device *dev)
78 struct platform_device *pdev = dev_get_drvdata(&dev->dev);
80 platform_device_unregister(pdev);
83 static const struct coreboot_device_id framebuffer_ids[] = {
84 { .tag = CB_TAG_FRAMEBUFFER },
87 MODULE_DEVICE_TABLE(coreboot, framebuffer_ids);
89 static struct coreboot_driver framebuffer_driver = {
90 .probe = framebuffer_probe,
91 .remove = framebuffer_remove,
93 .name = "framebuffer",
95 .id_table = framebuffer_ids,
97 module_coreboot_driver(framebuffer_driver);
100 MODULE_DESCRIPTION("Memory based framebuffer accessed through coreboot table");
101 MODULE_LICENSE("GPL");