drm_panel_orientation_quirks.c 6.0 KB

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