intel_bios.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * Copyright (c) 2006 Intel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Authors:
  18. * Eric Anholt <eric@anholt.net>
  19. *
  20. */
  21. #include <drm/drmP.h>
  22. #include <drm/drm.h>
  23. #include "gma_drm.h"
  24. #include "psb_drv.h"
  25. #include "psb_intel_drv.h"
  26. #include "psb_intel_reg.h"
  27. #include "intel_bios.h"
  28. static void *find_section(struct bdb_header *bdb, int section_id)
  29. {
  30. u8 *base = (u8 *)bdb;
  31. int index = 0;
  32. u16 total, current_size;
  33. u8 current_id;
  34. /* skip to first section */
  35. index += bdb->header_size;
  36. total = bdb->bdb_size;
  37. /* walk the sections looking for section_id */
  38. while (index < total) {
  39. current_id = *(base + index);
  40. index++;
  41. current_size = *((u16 *)(base + index));
  42. index += 2;
  43. if (current_id == section_id)
  44. return base + index;
  45. index += current_size;
  46. }
  47. return NULL;
  48. }
  49. static void fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  50. struct lvds_dvo_timing *dvo_timing)
  51. {
  52. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  53. dvo_timing->hactive_lo;
  54. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  55. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  56. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  57. dvo_timing->hsync_pulse_width;
  58. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  59. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  60. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  61. dvo_timing->vactive_lo;
  62. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  63. dvo_timing->vsync_off;
  64. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  65. dvo_timing->vsync_pulse_width;
  66. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  67. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  68. panel_fixed_mode->clock = dvo_timing->clock * 10;
  69. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  70. /* Some VBTs have bogus h/vtotal values */
  71. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  72. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  73. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  74. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  75. drm_mode_set_name(panel_fixed_mode);
  76. }
  77. static void parse_backlight_data(struct drm_psb_private *dev_priv,
  78. struct bdb_header *bdb)
  79. {
  80. struct bdb_lvds_backlight *vbt_lvds_bl = NULL;
  81. struct bdb_lvds_backlight *lvds_bl;
  82. u8 p_type = 0;
  83. void *bl_start = NULL;
  84. struct bdb_lvds_options *lvds_opts
  85. = find_section(bdb, BDB_LVDS_OPTIONS);
  86. dev_priv->lvds_bl = NULL;
  87. if (lvds_opts)
  88. p_type = lvds_opts->panel_type;
  89. else
  90. return;
  91. bl_start = find_section(bdb, BDB_LVDS_BACKLIGHT);
  92. vbt_lvds_bl = (struct bdb_lvds_backlight *)(bl_start + 1) + p_type;
  93. lvds_bl = kzalloc(sizeof(*vbt_lvds_bl), GFP_KERNEL);
  94. if (!lvds_bl) {
  95. dev_err(dev_priv->dev->dev, "out of memory for backlight data\n");
  96. return;
  97. }
  98. memcpy(lvds_bl, vbt_lvds_bl, sizeof(*vbt_lvds_bl));
  99. dev_priv->lvds_bl = lvds_bl;
  100. }
  101. /* Try to find integrated panel data */
  102. static void parse_lfp_panel_data(struct drm_psb_private *dev_priv,
  103. struct bdb_header *bdb)
  104. {
  105. struct bdb_lvds_options *lvds_options;
  106. struct bdb_lvds_lfp_data *lvds_lfp_data;
  107. struct bdb_lvds_lfp_data_entry *entry;
  108. struct lvds_dvo_timing *dvo_timing;
  109. struct drm_display_mode *panel_fixed_mode;
  110. /* Defaults if we can't find VBT info */
  111. dev_priv->lvds_dither = 0;
  112. dev_priv->lvds_vbt = 0;
  113. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  114. if (!lvds_options)
  115. return;
  116. dev_priv->lvds_dither = lvds_options->pixel_dither;
  117. if (lvds_options->panel_type == 0xff)
  118. return;
  119. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  120. if (!lvds_lfp_data)
  121. return;
  122. entry = &lvds_lfp_data->data[lvds_options->panel_type];
  123. dvo_timing = &entry->dvo_timing;
  124. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode),
  125. GFP_KERNEL);
  126. if (panel_fixed_mode == NULL) {
  127. dev_err(dev_priv->dev->dev, "out of memory for fixed panel mode\n");
  128. return;
  129. }
  130. dev_priv->lvds_vbt = 1;
  131. fill_detail_timing_data(panel_fixed_mode, dvo_timing);
  132. if (panel_fixed_mode->htotal > 0 && panel_fixed_mode->vtotal > 0) {
  133. dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
  134. drm_mode_debug_printmodeline(panel_fixed_mode);
  135. } else {
  136. dev_dbg(dev_priv->dev->dev, "ignoring invalid LVDS VBT\n");
  137. dev_priv->lvds_vbt = 0;
  138. kfree(panel_fixed_mode);
  139. }
  140. return;
  141. }
  142. /* Try to find sdvo panel data */
  143. static void parse_sdvo_panel_data(struct drm_psb_private *dev_priv,
  144. struct bdb_header *bdb)
  145. {
  146. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  147. struct lvds_dvo_timing *dvo_timing;
  148. struct drm_display_mode *panel_fixed_mode;
  149. dev_priv->sdvo_lvds_vbt_mode = NULL;
  150. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  151. if (!sdvo_lvds_options)
  152. return;
  153. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  154. if (!dvo_timing)
  155. return;
  156. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  157. if (!panel_fixed_mode)
  158. return;
  159. fill_detail_timing_data(panel_fixed_mode,
  160. dvo_timing + sdvo_lvds_options->panel_type);
  161. dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
  162. return;
  163. }
  164. static void parse_general_features(struct drm_psb_private *dev_priv,
  165. struct bdb_header *bdb)
  166. {
  167. struct bdb_general_features *general;
  168. /* Set sensible defaults in case we can't find the general block */
  169. dev_priv->int_tv_support = 1;
  170. dev_priv->int_crt_support = 1;
  171. general = find_section(bdb, BDB_GENERAL_FEATURES);
  172. if (general) {
  173. dev_priv->int_tv_support = general->int_tv_support;
  174. dev_priv->int_crt_support = general->int_crt_support;
  175. dev_priv->lvds_use_ssc = general->enable_ssc;
  176. if (dev_priv->lvds_use_ssc) {
  177. dev_priv->lvds_ssc_freq
  178. = general->ssc_freq ? 100 : 96;
  179. }
  180. }
  181. }
  182. /**
  183. * psb_intel_init_bios - initialize VBIOS settings & find VBT
  184. * @dev: DRM device
  185. *
  186. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  187. * to appropriate values.
  188. *
  189. * VBT existence is a sanity check that is relied on by other i830_bios.c code.
  190. * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
  191. * feed an updated VBT back through that, compared to what we'll fetch using
  192. * this method of groping around in the BIOS data.
  193. *
  194. * Returns 0 on success, nonzero on failure.
  195. */
  196. bool psb_intel_init_bios(struct drm_device *dev)
  197. {
  198. struct drm_psb_private *dev_priv = dev->dev_private;
  199. struct pci_dev *pdev = dev->pdev;
  200. struct vbt_header *vbt = NULL;
  201. struct bdb_header *bdb;
  202. u8 __iomem *bios;
  203. size_t size;
  204. int i;
  205. bios = pci_map_rom(pdev, &size);
  206. if (!bios)
  207. return -1;
  208. /* Scour memory looking for the VBT signature */
  209. for (i = 0; i + 4 < size; i++) {
  210. if (!memcmp(bios + i, "$VBT", 4)) {
  211. vbt = (struct vbt_header *)(bios + i);
  212. break;
  213. }
  214. }
  215. if (!vbt) {
  216. dev_err(dev->dev, "VBT signature missing\n");
  217. pci_unmap_rom(pdev, bios);
  218. return -1;
  219. }
  220. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  221. /* Grab useful general definitions */
  222. parse_general_features(dev_priv, bdb);
  223. parse_lfp_panel_data(dev_priv, bdb);
  224. parse_sdvo_panel_data(dev_priv, bdb);
  225. parse_backlight_data(dev_priv, bdb);
  226. pci_unmap_rom(pdev, bios);
  227. return 0;
  228. }
  229. /**
  230. * Destroy and free VBT data
  231. */
  232. void psb_intel_destroy_bios(struct drm_device *dev)
  233. {
  234. struct drm_psb_private *dev_priv = dev->dev_private;
  235. struct drm_display_mode *sdvo_lvds_vbt_mode =
  236. dev_priv->sdvo_lvds_vbt_mode;
  237. struct drm_display_mode *lfp_lvds_vbt_mode =
  238. dev_priv->lfp_lvds_vbt_mode;
  239. struct bdb_lvds_backlight *lvds_bl =
  240. dev_priv->lvds_bl;
  241. /*free sdvo panel mode*/
  242. if (sdvo_lvds_vbt_mode) {
  243. dev_priv->sdvo_lvds_vbt_mode = NULL;
  244. kfree(sdvo_lvds_vbt_mode);
  245. }
  246. if (lfp_lvds_vbt_mode) {
  247. dev_priv->lfp_lvds_vbt_mode = NULL;
  248. kfree(lfp_lvds_vbt_mode);
  249. }
  250. if (lvds_bl) {
  251. dev_priv->lvds_bl = NULL;
  252. kfree(lvds_bl);
  253. }
  254. }