drm_panel_orientation_quirks.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * drm_panel_orientation_quirks.c -- Quirks for non-normal panel orientation
  4. *
  5. * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
  6. *
  7. * Note the quirks in this file are shared with fbdev/efifb and as such
  8. * must not depend on other drm code.
  9. */
  10. #include <linux/dmi.h>
  11. #include <drm/drm_connector.h>
  12. #ifdef CONFIG_DMI
  13. /*
  14. * Some x86 clamshell design devices use portrait tablet screens and a display
  15. * engine which cannot rotate in hardware, so we need to rotate the fbcon to
  16. * compensate. Unfortunately these (cheap) devices also typically have quite
  17. * generic DMI data, so we match on a combination of DMI data, screen resolution
  18. * and a list of known BIOS dates to avoid false positives.
  19. */
  20. struct drm_dmi_panel_orientation_data {
  21. int width;
  22. int height;
  23. const char * const *bios_dates;
  24. int orientation;
  25. };
  26. static const struct drm_dmi_panel_orientation_data asus_t100ha = {
  27. .width = 800,
  28. .height = 1280,
  29. .orientation = DRM_MODE_PANEL_ORIENTATION_LEFT_UP,
  30. };
  31. static const struct drm_dmi_panel_orientation_data gpd_pocket = {
  32. .width = 1200,
  33. .height = 1920,
  34. .bios_dates = (const char * const []){ "05/26/2017", "06/28/2017",
  35. "07/05/2017", "08/07/2017", NULL },
  36. .orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
  37. };
  38. static const struct drm_dmi_panel_orientation_data gpd_win = {
  39. .width = 720,
  40. .height = 1280,
  41. .bios_dates = (const char * const []){
  42. "10/25/2016", "11/18/2016", "12/23/2016", "12/26/2016",
  43. "02/21/2017", "03/20/2017", "05/25/2017", NULL },
  44. .orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
  45. };
  46. static const struct drm_dmi_panel_orientation_data itworks_tw891 = {
  47. .width = 800,
  48. .height = 1280,
  49. .bios_dates = (const char * const []){ "10/16/2015", NULL },
  50. .orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
  51. };
  52. static const struct drm_dmi_panel_orientation_data vios_lth17 = {
  53. .width = 800,
  54. .height = 1280,
  55. .orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
  56. };
  57. static const struct dmi_system_id orientation_data[] = {
  58. { /* Asus T100HA */
  59. .matches = {
  60. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  61. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100HAN"),
  62. },
  63. .driver_data = (void *)&asus_t100ha,
  64. }, { /*
  65. * GPD Pocket, note that the the DMI data is less generic then
  66. * it seems, devices with a board-vendor of "AMI Corporation"
  67. * are quite rare, as are devices which have both board- *and*
  68. * product-id set to "Default String"
  69. */
  70. .matches = {
  71. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  72. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
  73. DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
  74. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
  75. },
  76. .driver_data = (void *)&gpd_pocket,
  77. }, { /* GPD Win (same note on DMI match as GPD Pocket) */
  78. .matches = {
  79. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  80. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
  81. DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
  82. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
  83. },
  84. .driver_data = (void *)&gpd_win,
  85. }, { /* I.T.Works TW891 */
  86. .matches = {
  87. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
  88. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
  89. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
  90. DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
  91. },
  92. .driver_data = (void *)&itworks_tw891,
  93. }, { /* VIOS LTH17 */
  94. .matches = {
  95. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "VIOS"),
  96. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LTH17"),
  97. },
  98. .driver_data = (void *)&vios_lth17,
  99. },
  100. {}
  101. };
  102. /**
  103. * drm_get_panel_orientation_quirk - Check for panel orientation quirks
  104. * @width: width in pixels of the panel
  105. * @height: height in pixels of the panel
  106. *
  107. * This function checks for platform specific (e.g. DMI based) quirks
  108. * providing info on panel_orientation for systems where this cannot be
  109. * probed from the hard-/firm-ware. To avoid false-positive this function
  110. * takes the panel resolution as argument and checks that against the
  111. * resolution expected by the quirk-table entry.
  112. *
  113. * Note this function is also used outside of the drm-subsys, by for example
  114. * the efifb code. Because of this this function gets compiled into its own
  115. * kernel-module when built as a module.
  116. *
  117. * Returns:
  118. * A DRM_MODE_PANEL_ORIENTATION_* value if there is a quirk for this system,
  119. * or DRM_MODE_PANEL_ORIENTATION_UNKNOWN if there is no quirk.
  120. */
  121. int drm_get_panel_orientation_quirk(int width, int height)
  122. {
  123. const struct dmi_system_id *match;
  124. const struct drm_dmi_panel_orientation_data *data;
  125. const char *bios_date;
  126. int i;
  127. for (match = dmi_first_match(orientation_data);
  128. match;
  129. match = dmi_first_match(match + 1)) {
  130. data = match->driver_data;
  131. if (data->width != width ||
  132. data->height != height)
  133. continue;
  134. if (!data->bios_dates)
  135. return data->orientation;
  136. bios_date = dmi_get_system_info(DMI_BIOS_DATE);
  137. if (!bios_date)
  138. continue;
  139. for (i = 0; data->bios_dates[i]; i++) {
  140. if (!strcmp(data->bios_dates[i], bios_date))
  141. return data->orientation;
  142. }
  143. }
  144. return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
  145. }
  146. EXPORT_SYMBOL(drm_get_panel_orientation_quirk);
  147. #else
  148. /* There are no quirks for non x86 devices yet */
  149. int drm_get_panel_orientation_quirk(int width, int height)
  150. {
  151. return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
  152. }
  153. EXPORT_SYMBOL(drm_get_panel_orientation_quirk);
  154. #endif