1d9523678SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2851b4c14SSamuel Holland /*
3851b4c14SSamuel Holland * framebuffer-coreboot.c
4851b4c14SSamuel Holland *
5851b4c14SSamuel Holland * Memory based framebuffer accessed through coreboot table.
6851b4c14SSamuel Holland *
7851b4c14SSamuel Holland * Copyright 2012-2013 David Herrmann <dh.herrmann@gmail.com>
8851b4c14SSamuel Holland * Copyright 2017 Google Inc.
9851b4c14SSamuel Holland * Copyright 2017 Samuel Holland <samuel@sholland.org>
10851b4c14SSamuel Holland */
11851b4c14SSamuel Holland
12851b4c14SSamuel Holland #include <linux/device.h>
13851b4c14SSamuel Holland #include <linux/kernel.h>
14851b4c14SSamuel Holland #include <linux/mm.h>
15851b4c14SSamuel Holland #include <linux/module.h>
16851b4c14SSamuel Holland #include <linux/platform_data/simplefb.h>
17851b4c14SSamuel Holland #include <linux/platform_device.h>
18851b4c14SSamuel Holland
19851b4c14SSamuel Holland #include "coreboot_table.h"
20851b4c14SSamuel Holland
21851b4c14SSamuel Holland #define CB_TAG_FRAMEBUFFER 0x12
22851b4c14SSamuel Holland
23851b4c14SSamuel Holland static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
24851b4c14SSamuel Holland
framebuffer_probe(struct coreboot_device * dev)25851b4c14SSamuel Holland static int framebuffer_probe(struct coreboot_device *dev)
26851b4c14SSamuel Holland {
27851b4c14SSamuel Holland int i;
28851b4c14SSamuel Holland u32 length;
29851b4c14SSamuel Holland struct lb_framebuffer *fb = &dev->framebuffer;
30851b4c14SSamuel Holland struct platform_device *pdev;
31851b4c14SSamuel Holland struct resource res;
32851b4c14SSamuel Holland struct simplefb_platform_data pdata = {
33851b4c14SSamuel Holland .width = fb->x_resolution,
34851b4c14SSamuel Holland .height = fb->y_resolution,
35851b4c14SSamuel Holland .stride = fb->bytes_per_line,
36851b4c14SSamuel Holland .format = NULL,
37851b4c14SSamuel Holland };
38851b4c14SSamuel Holland
39851b4c14SSamuel Holland for (i = 0; i < ARRAY_SIZE(formats); ++i) {
40851b4c14SSamuel Holland if (fb->bits_per_pixel == formats[i].bits_per_pixel &&
41851b4c14SSamuel Holland fb->red_mask_pos == formats[i].red.offset &&
42851b4c14SSamuel Holland fb->red_mask_size == formats[i].red.length &&
43851b4c14SSamuel Holland fb->green_mask_pos == formats[i].green.offset &&
44851b4c14SSamuel Holland fb->green_mask_size == formats[i].green.length &&
45851b4c14SSamuel Holland fb->blue_mask_pos == formats[i].blue.offset &&
46*e6acaf25SAlper Nebi Yasak fb->blue_mask_size == formats[i].blue.length)
47851b4c14SSamuel Holland pdata.format = formats[i].name;
48851b4c14SSamuel Holland }
49851b4c14SSamuel Holland if (!pdata.format)
50851b4c14SSamuel Holland return -ENODEV;
51851b4c14SSamuel Holland
52851b4c14SSamuel Holland memset(&res, 0, sizeof(res));
53851b4c14SSamuel Holland res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
54851b4c14SSamuel Holland res.name = "Coreboot Framebuffer";
55851b4c14SSamuel Holland res.start = fb->physical_address;
56851b4c14SSamuel Holland length = PAGE_ALIGN(fb->y_resolution * fb->bytes_per_line);
57851b4c14SSamuel Holland res.end = res.start + length - 1;
58851b4c14SSamuel Holland if (res.end <= res.start)
59851b4c14SSamuel Holland return -EINVAL;
60851b4c14SSamuel Holland
61851b4c14SSamuel Holland pdev = platform_device_register_resndata(&dev->dev,
62851b4c14SSamuel Holland "simple-framebuffer", 0,
63851b4c14SSamuel Holland &res, 1, &pdata,
64851b4c14SSamuel Holland sizeof(pdata));
65851b4c14SSamuel Holland if (IS_ERR(pdev))
66851b4c14SSamuel Holland pr_warn("coreboot: could not register framebuffer\n");
67851b4c14SSamuel Holland else
68851b4c14SSamuel Holland dev_set_drvdata(&dev->dev, pdev);
69851b4c14SSamuel Holland
70851b4c14SSamuel Holland return PTR_ERR_OR_ZERO(pdev);
71851b4c14SSamuel Holland }
72851b4c14SSamuel Holland
framebuffer_remove(struct coreboot_device * dev)735f680532SUwe Kleine-König static void framebuffer_remove(struct coreboot_device *dev)
74851b4c14SSamuel Holland {
75851b4c14SSamuel Holland struct platform_device *pdev = dev_get_drvdata(&dev->dev);
76851b4c14SSamuel Holland
77851b4c14SSamuel Holland platform_device_unregister(pdev);
78851b4c14SSamuel Holland }
79851b4c14SSamuel Holland
80851b4c14SSamuel Holland static struct coreboot_driver framebuffer_driver = {
81851b4c14SSamuel Holland .probe = framebuffer_probe,
82851b4c14SSamuel Holland .remove = framebuffer_remove,
83851b4c14SSamuel Holland .drv = {
84851b4c14SSamuel Holland .name = "framebuffer",
85851b4c14SSamuel Holland },
86851b4c14SSamuel Holland .tag = CB_TAG_FRAMEBUFFER,
87851b4c14SSamuel Holland };
8835463503SStephen Boyd module_coreboot_driver(framebuffer_driver);
89851b4c14SSamuel Holland
90851b4c14SSamuel Holland MODULE_AUTHOR("Samuel Holland <samuel@sholland.org>");
91851b4c14SSamuel Holland MODULE_LICENSE("GPL");
92