framebuffer-coreboot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * framebuffer-coreboot.c
  4. *
  5. * Memory based framebuffer accessed through coreboot table.
  6. *
  7. * Copyright 2012-2013 David Herrmann <dh.herrmann@gmail.com>
  8. * Copyright 2017 Google Inc.
  9. * Copyright 2017 Samuel Holland <samuel@sholland.org>
  10. */
  11. #include <linux/device.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mm.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_data/simplefb.h>
  16. #include <linux/platform_device.h>
  17. #include "coreboot_table.h"
  18. #define CB_TAG_FRAMEBUFFER 0x12
  19. static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
  20. static int framebuffer_probe(struct coreboot_device *dev)
  21. {
  22. int i;
  23. u32 length;
  24. struct lb_framebuffer *fb = &dev->framebuffer;
  25. struct platform_device *pdev;
  26. struct resource res;
  27. struct simplefb_platform_data pdata = {
  28. .width = fb->x_resolution,
  29. .height = fb->y_resolution,
  30. .stride = fb->bytes_per_line,
  31. .format = NULL,
  32. };
  33. if (!fb->physical_address)
  34. return -ENODEV;
  35. for (i = 0; i < ARRAY_SIZE(formats); ++i) {
  36. if (fb->bits_per_pixel == formats[i].bits_per_pixel &&
  37. fb->red_mask_pos == formats[i].red.offset &&
  38. fb->red_mask_size == formats[i].red.length &&
  39. fb->green_mask_pos == formats[i].green.offset &&
  40. fb->green_mask_size == formats[i].green.length &&
  41. fb->blue_mask_pos == formats[i].blue.offset &&
  42. fb->blue_mask_size == formats[i].blue.length)
  43. pdata.format = formats[i].name;
  44. }
  45. if (!pdata.format)
  46. return -ENODEV;
  47. memset(&res, 0, sizeof(res));
  48. res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  49. res.name = "Coreboot Framebuffer";
  50. res.start = fb->physical_address;
  51. length = PAGE_ALIGN(fb->y_resolution * fb->bytes_per_line);
  52. res.end = res.start + length - 1;
  53. if (res.end <= res.start)
  54. return -EINVAL;
  55. pdev = platform_device_register_resndata(&dev->dev,
  56. "simple-framebuffer", 0,
  57. &res, 1, &pdata,
  58. sizeof(pdata));
  59. if (IS_ERR(pdev))
  60. pr_warn("coreboot: could not register framebuffer\n");
  61. else
  62. dev_set_drvdata(&dev->dev, pdev);
  63. return PTR_ERR_OR_ZERO(pdev);
  64. }
  65. static void framebuffer_remove(struct coreboot_device *dev)
  66. {
  67. struct platform_device *pdev = dev_get_drvdata(&dev->dev);
  68. platform_device_unregister(pdev);
  69. }
  70. static const struct coreboot_device_id framebuffer_ids[] = {
  71. { .tag = CB_TAG_FRAMEBUFFER },
  72. { /* sentinel */ }
  73. };
  74. MODULE_DEVICE_TABLE(coreboot, framebuffer_ids);
  75. static struct coreboot_driver framebuffer_driver = {
  76. .probe = framebuffer_probe,
  77. .remove = framebuffer_remove,
  78. .drv = {
  79. .name = "framebuffer",
  80. },
  81. .id_table = framebuffer_ids,
  82. };
  83. module_coreboot_driver(framebuffer_driver);
  84. MODULE_AUTHOR("Samuel Holland <samuel@sholland.org>");
  85. MODULE_DESCRIPTION("Memory based framebuffer accessed through coreboot table");
  86. MODULE_LICENSE("GPL");