mid_bios.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**************************************************************************
  2. * Copyright (c) 2011, Intel Corporation.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. **************************************************************************/
  19. /* TODO
  20. * - Split functions by vbt type
  21. * - Make them all take drm_device
  22. * - Check ioremap failures
  23. */
  24. #include <drm/drmP.h>
  25. #include <drm/drm.h>
  26. #include "gma_drm.h"
  27. #include "psb_drv.h"
  28. #include "mid_bios.h"
  29. static void mid_get_fuse_settings(struct drm_device *dev)
  30. {
  31. struct drm_psb_private *dev_priv = dev->dev_private;
  32. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  33. uint32_t fuse_value = 0;
  34. uint32_t fuse_value_tmp = 0;
  35. #define FB_REG06 0xD0810600
  36. #define FB_MIPI_DISABLE (1 << 11)
  37. #define FB_REG09 0xD0810900
  38. #define FB_REG09 0xD0810900
  39. #define FB_SKU_MASK 0x7000
  40. #define FB_SKU_SHIFT 12
  41. #define FB_SKU_100 0
  42. #define FB_SKU_100L 1
  43. #define FB_SKU_83 2
  44. pci_write_config_dword(pci_root, 0xD0, FB_REG06);
  45. pci_read_config_dword(pci_root, 0xD4, &fuse_value);
  46. /* FB_MIPI_DISABLE doesn't mean LVDS on with Medfield */
  47. if (IS_MRST(dev))
  48. dev_priv->iLVDS_enable = fuse_value & FB_MIPI_DISABLE;
  49. DRM_INFO("internal display is %s\n",
  50. dev_priv->iLVDS_enable ? "LVDS display" : "MIPI display");
  51. /* Prevent runtime suspend at start*/
  52. if (dev_priv->iLVDS_enable) {
  53. dev_priv->is_lvds_on = true;
  54. dev_priv->is_mipi_on = false;
  55. } else {
  56. dev_priv->is_mipi_on = true;
  57. dev_priv->is_lvds_on = false;
  58. }
  59. dev_priv->video_device_fuse = fuse_value;
  60. pci_write_config_dword(pci_root, 0xD0, FB_REG09);
  61. pci_read_config_dword(pci_root, 0xD4, &fuse_value);
  62. dev_dbg(dev->dev, "SKU values is 0x%x.\n", fuse_value);
  63. fuse_value_tmp = (fuse_value & FB_SKU_MASK) >> FB_SKU_SHIFT;
  64. dev_priv->fuse_reg_value = fuse_value;
  65. switch (fuse_value_tmp) {
  66. case FB_SKU_100:
  67. dev_priv->core_freq = 200;
  68. break;
  69. case FB_SKU_100L:
  70. dev_priv->core_freq = 100;
  71. break;
  72. case FB_SKU_83:
  73. dev_priv->core_freq = 166;
  74. break;
  75. default:
  76. dev_warn(dev->dev, "Invalid SKU values, SKU value = 0x%08x\n",
  77. fuse_value_tmp);
  78. dev_priv->core_freq = 0;
  79. }
  80. dev_dbg(dev->dev, "LNC core clk is %dMHz.\n", dev_priv->core_freq);
  81. pci_dev_put(pci_root);
  82. }
  83. /*
  84. * Get the revison ID, B0:D2:F0;0x08
  85. */
  86. static void mid_get_pci_revID(struct drm_psb_private *dev_priv)
  87. {
  88. uint32_t platform_rev_id = 0;
  89. struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
  90. pci_read_config_dword(pci_gfx_root, 0x08, &platform_rev_id);
  91. dev_priv->platform_rev_id = (uint8_t) platform_rev_id;
  92. pci_dev_put(pci_gfx_root);
  93. dev_dbg(dev_priv->dev->dev, "platform_rev_id is %x\n",
  94. dev_priv->platform_rev_id);
  95. }
  96. static void mid_get_vbt_data(struct drm_psb_private *dev_priv)
  97. {
  98. struct drm_device *dev = dev_priv->dev;
  99. struct oaktrail_vbt *vbt = &dev_priv->vbt_data;
  100. u32 addr;
  101. u16 new_size;
  102. u8 *vbt_virtual;
  103. u8 bpi;
  104. u8 number_desc = 0;
  105. struct oaktrail_timing_info *dp_ti = &dev_priv->gct_data.DTD;
  106. struct gct_r10_timing_info ti;
  107. void *pGCT;
  108. struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
  109. /* Get the address of the platform config vbt, B0:D2:F0;0xFC */
  110. pci_read_config_dword(pci_gfx_root, 0xFC, &addr);
  111. pci_dev_put(pci_gfx_root);
  112. dev_dbg(dev->dev, "drm platform config address is %x\n", addr);
  113. /* check for platform config address == 0. */
  114. /* this means fw doesn't support vbt */
  115. if (addr == 0) {
  116. vbt->size = 0;
  117. return;
  118. }
  119. /* get the virtual address of the vbt */
  120. vbt_virtual = ioremap(addr, sizeof(*vbt));
  121. memcpy(vbt, vbt_virtual, sizeof(*vbt));
  122. iounmap(vbt_virtual); /* Free virtual address space */
  123. /* No matching signature don't process the data */
  124. if (memcmp(vbt->signature, "$GCT", 4)) {
  125. vbt->size = 0;
  126. return;
  127. }
  128. dev_dbg(dev->dev, "GCT revision is %x\n", vbt->revision);
  129. switch (vbt->revision) {
  130. case 0:
  131. vbt->oaktrail_gct = ioremap(addr + sizeof(*vbt) - 4,
  132. vbt->size - sizeof(*vbt) + 4);
  133. pGCT = vbt->oaktrail_gct;
  134. bpi = ((struct oaktrail_gct_v1 *)pGCT)->PD.BootPanelIndex;
  135. dev_priv->gct_data.bpi = bpi;
  136. dev_priv->gct_data.pt =
  137. ((struct oaktrail_gct_v1 *)pGCT)->PD.PanelType;
  138. memcpy(&dev_priv->gct_data.DTD,
  139. &((struct oaktrail_gct_v1 *)pGCT)->panel[bpi].DTD,
  140. sizeof(struct oaktrail_timing_info));
  141. dev_priv->gct_data.Panel_Port_Control =
  142. ((struct oaktrail_gct_v1 *)pGCT)->panel[bpi].Panel_Port_Control;
  143. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  144. ((struct oaktrail_gct_v1 *)pGCT)->panel[bpi].Panel_MIPI_Display_Descriptor;
  145. break;
  146. case 1:
  147. vbt->oaktrail_gct = ioremap(addr + sizeof(*vbt) - 4,
  148. vbt->size - sizeof(*vbt) + 4);
  149. pGCT = vbt->oaktrail_gct;
  150. bpi = ((struct oaktrail_gct_v2 *)pGCT)->PD.BootPanelIndex;
  151. dev_priv->gct_data.bpi = bpi;
  152. dev_priv->gct_data.pt =
  153. ((struct oaktrail_gct_v2 *)pGCT)->PD.PanelType;
  154. memcpy(&dev_priv->gct_data.DTD,
  155. &((struct oaktrail_gct_v2 *)pGCT)->panel[bpi].DTD,
  156. sizeof(struct oaktrail_timing_info));
  157. dev_priv->gct_data.Panel_Port_Control =
  158. ((struct oaktrail_gct_v2 *)pGCT)->panel[bpi].Panel_Port_Control;
  159. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  160. ((struct oaktrail_gct_v2 *)pGCT)->panel[bpi].Panel_MIPI_Display_Descriptor;
  161. break;
  162. case 0x10:
  163. /*header definition changed from rev 01 (v2) to rev 10h. */
  164. /*so, some values have changed location*/
  165. new_size = vbt->checksum; /*checksum contains lo size byte*/
  166. /*LSB of oaktrail_gct contains hi size byte*/
  167. new_size |= ((0xff & (unsigned int)vbt->oaktrail_gct)) << 8;
  168. vbt->checksum = vbt->size; /*size contains the checksum*/
  169. if (new_size > 0xff)
  170. vbt->size = 0xff; /*restrict size to 255*/
  171. else
  172. vbt->size = new_size;
  173. /* number of descriptors defined in the GCT */
  174. number_desc = ((0xff00 & (unsigned int)vbt->oaktrail_gct)) >> 8;
  175. bpi = ((0xff0000 & (unsigned int)vbt->oaktrail_gct)) >> 16;
  176. vbt->oaktrail_gct = ioremap(addr + GCT_R10_HEADER_SIZE,
  177. GCT_R10_DISPLAY_DESC_SIZE * number_desc);
  178. pGCT = vbt->oaktrail_gct;
  179. pGCT = (u8 *)pGCT + (bpi*GCT_R10_DISPLAY_DESC_SIZE);
  180. dev_priv->gct_data.bpi = bpi; /*save boot panel id*/
  181. /*copy the GCT display timings into a temp structure*/
  182. memcpy(&ti, pGCT, sizeof(struct gct_r10_timing_info));
  183. /*now copy the temp struct into the dev_priv->gct_data*/
  184. dp_ti->pixel_clock = ti.pixel_clock;
  185. dp_ti->hactive_hi = ti.hactive_hi;
  186. dp_ti->hactive_lo = ti.hactive_lo;
  187. dp_ti->hblank_hi = ti.hblank_hi;
  188. dp_ti->hblank_lo = ti.hblank_lo;
  189. dp_ti->hsync_offset_hi = ti.hsync_offset_hi;
  190. dp_ti->hsync_offset_lo = ti.hsync_offset_lo;
  191. dp_ti->hsync_pulse_width_hi = ti.hsync_pulse_width_hi;
  192. dp_ti->hsync_pulse_width_lo = ti.hsync_pulse_width_lo;
  193. dp_ti->vactive_hi = ti.vactive_hi;
  194. dp_ti->vactive_lo = ti.vactive_lo;
  195. dp_ti->vblank_hi = ti.vblank_hi;
  196. dp_ti->vblank_lo = ti.vblank_lo;
  197. dp_ti->vsync_offset_hi = ti.vsync_offset_hi;
  198. dp_ti->vsync_offset_lo = ti.vsync_offset_lo;
  199. dp_ti->vsync_pulse_width_hi = ti.vsync_pulse_width_hi;
  200. dp_ti->vsync_pulse_width_lo = ti.vsync_pulse_width_lo;
  201. /* Move the MIPI_Display_Descriptor data from GCT to dev priv */
  202. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  203. *((u8 *)pGCT + 0x0d);
  204. dev_priv->gct_data.Panel_MIPI_Display_Descriptor |=
  205. (*((u8 *)pGCT + 0x0e)) << 8;
  206. break;
  207. default:
  208. dev_err(dev->dev, "Unknown revision of GCT!\n");
  209. vbt->size = 0;
  210. }
  211. }
  212. int mid_chip_setup(struct drm_device *dev)
  213. {
  214. struct drm_psb_private *dev_priv = dev->dev_private;
  215. mid_get_fuse_settings(dev);
  216. mid_get_vbt_data(dev_priv);
  217. mid_get_pci_revID(dev_priv);
  218. return 0;
  219. }