sysfb.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Generic System Framebuffers on x86
  3. * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 2 of the License, or (at your option)
  8. * any later version.
  9. */
  10. /*
  11. * Simple-Framebuffer support for x86 systems
  12. * Create a platform-device for any available boot framebuffer. The
  13. * simple-framebuffer platform device is already available on DT systems, so
  14. * this module parses the global "screen_info" object and creates a suitable
  15. * platform device compatible with the "simple-framebuffer" DT object. If
  16. * the framebuffer is incompatible, we instead create a legacy
  17. * "vesa-framebuffer", "efi-framebuffer" or "platform-framebuffer" device and
  18. * pass the screen_info as platform_data. This allows legacy drivers
  19. * to pick these devices up without messing with simple-framebuffer drivers.
  20. * The global "screen_info" is still valid at all times.
  21. *
  22. * If CONFIG_X86_SYSFB is not selected, we never register "simple-framebuffer"
  23. * platform devices, but only use legacy framebuffer devices for
  24. * backwards compatibility.
  25. *
  26. * TODO: We set the dev_id field of all platform-devices to 0. This allows
  27. * other x86 OF/DT parsers to create such devices, too. However, they must
  28. * start at offset 1 for this to work.
  29. */
  30. #include <linux/err.h>
  31. #include <linux/init.h>
  32. #include <linux/kernel.h>
  33. #include <linux/mm.h>
  34. #include <linux/platform_data/simplefb.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/screen_info.h>
  37. #include <asm/sysfb.h>
  38. static __init int sysfb_init(void)
  39. {
  40. struct screen_info *si = &screen_info;
  41. struct simplefb_platform_data mode;
  42. struct platform_device *pd;
  43. const char *name;
  44. bool compatible;
  45. int ret;
  46. sysfb_apply_efi_quirks();
  47. /* try to create a simple-framebuffer device */
  48. compatible = parse_mode(si, &mode);
  49. if (compatible) {
  50. ret = create_simplefb(si, &mode);
  51. if (!ret)
  52. return 0;
  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. pd = platform_device_register_resndata(NULL, name, 0,
  62. NULL, 0, si, sizeof(*si));
  63. return PTR_ERR_OR_ZERO(pd);
  64. }
  65. /* must execute after PCI subsystem for EFI quirks */
  66. device_initcall(sysfb_init);