mid_bios.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. if (pci_root == NULL) {
  45. WARN_ON(1);
  46. return;
  47. }
  48. pci_write_config_dword(pci_root, 0xD0, FB_REG06);
  49. pci_read_config_dword(pci_root, 0xD4, &fuse_value);
  50. /* FB_MIPI_DISABLE doesn't mean LVDS on with Medfield */
  51. if (IS_MRST(dev))
  52. dev_priv->iLVDS_enable = fuse_value & FB_MIPI_DISABLE;
  53. DRM_INFO("internal display is %s\n",
  54. dev_priv->iLVDS_enable ? "LVDS display" : "MIPI display");
  55. /* Prevent runtime suspend at start*/
  56. if (dev_priv->iLVDS_enable) {
  57. dev_priv->is_lvds_on = true;
  58. dev_priv->is_mipi_on = false;
  59. } else {
  60. dev_priv->is_mipi_on = true;
  61. dev_priv->is_lvds_on = false;
  62. }
  63. dev_priv->video_device_fuse = fuse_value;
  64. pci_write_config_dword(pci_root, 0xD0, FB_REG09);
  65. pci_read_config_dword(pci_root, 0xD4, &fuse_value);
  66. dev_dbg(dev->dev, "SKU values is 0x%x.\n", fuse_value);
  67. fuse_value_tmp = (fuse_value & FB_SKU_MASK) >> FB_SKU_SHIFT;
  68. dev_priv->fuse_reg_value = fuse_value;
  69. switch (fuse_value_tmp) {
  70. case FB_SKU_100:
  71. dev_priv->core_freq = 200;
  72. break;
  73. case FB_SKU_100L:
  74. dev_priv->core_freq = 100;
  75. break;
  76. case FB_SKU_83:
  77. dev_priv->core_freq = 166;
  78. break;
  79. default:
  80. dev_warn(dev->dev, "Invalid SKU values, SKU value = 0x%08x\n",
  81. fuse_value_tmp);
  82. dev_priv->core_freq = 0;
  83. }
  84. dev_dbg(dev->dev, "LNC core clk is %dMHz.\n", dev_priv->core_freq);
  85. pci_dev_put(pci_root);
  86. }
  87. /*
  88. * Get the revison ID, B0:D2:F0;0x08
  89. */
  90. static void mid_get_pci_revID(struct drm_psb_private *dev_priv)
  91. {
  92. uint32_t platform_rev_id = 0;
  93. struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
  94. if (pci_gfx_root == NULL) {
  95. WARN_ON(1);
  96. return;
  97. }
  98. pci_read_config_dword(pci_gfx_root, 0x08, &platform_rev_id);
  99. dev_priv->platform_rev_id = (uint8_t) platform_rev_id;
  100. pci_dev_put(pci_gfx_root);
  101. dev_dbg(dev_priv->dev->dev, "platform_rev_id is %x\n",
  102. dev_priv->platform_rev_id);
  103. }
  104. static void mid_get_vbt_data(struct drm_psb_private *dev_priv)
  105. {
  106. struct drm_device *dev = dev_priv->dev;
  107. struct oaktrail_vbt *vbt = &dev_priv->vbt_data;
  108. u32 addr;
  109. u16 new_size;
  110. u8 *vbt_virtual;
  111. u8 bpi;
  112. u8 number_desc = 0;
  113. struct oaktrail_timing_info *dp_ti = &dev_priv->gct_data.DTD;
  114. struct gct_r10_timing_info ti;
  115. void *pGCT;
  116. struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
  117. /* Get the address of the platform config vbt, B0:D2:F0;0xFC */
  118. pci_read_config_dword(pci_gfx_root, 0xFC, &addr);
  119. pci_dev_put(pci_gfx_root);
  120. dev_dbg(dev->dev, "drm platform config address is %x\n", addr);
  121. /* check for platform config address == 0. */
  122. /* this means fw doesn't support vbt */
  123. if (addr == 0) {
  124. vbt->size = 0;
  125. return;
  126. }
  127. /* get the virtual address of the vbt */
  128. vbt_virtual = ioremap(addr, sizeof(*vbt));
  129. if (vbt_virtual == NULL) {
  130. vbt->size = 0;
  131. return;
  132. }
  133. memcpy(vbt, vbt_virtual, sizeof(*vbt));
  134. iounmap(vbt_virtual); /* Free virtual address space */
  135. /* No matching signature don't process the data */
  136. if (memcmp(vbt->signature, "$GCT", 4)) {
  137. vbt->size = 0;
  138. return;
  139. }
  140. dev_dbg(dev->dev, "GCT revision is %x\n", vbt->revision);
  141. switch (vbt->revision) {
  142. case 0:
  143. vbt->oaktrail_gct = ioremap(addr + sizeof(*vbt) - 4,
  144. vbt->size - sizeof(*vbt) + 4);
  145. pGCT = vbt->oaktrail_gct;
  146. bpi = ((struct oaktrail_gct_v1 *)pGCT)->PD.BootPanelIndex;
  147. dev_priv->gct_data.bpi = bpi;
  148. dev_priv->gct_data.pt =
  149. ((struct oaktrail_gct_v1 *)pGCT)->PD.PanelType;
  150. memcpy(&dev_priv->gct_data.DTD,
  151. &((struct oaktrail_gct_v1 *)pGCT)->panel[bpi].DTD,
  152. sizeof(struct oaktrail_timing_info));
  153. dev_priv->gct_data.Panel_Port_Control =
  154. ((struct oaktrail_gct_v1 *)pGCT)->panel[bpi].Panel_Port_Control;
  155. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  156. ((struct oaktrail_gct_v1 *)pGCT)->panel[bpi].Panel_MIPI_Display_Descriptor;
  157. break;
  158. case 1:
  159. vbt->oaktrail_gct = ioremap(addr + sizeof(*vbt) - 4,
  160. vbt->size - sizeof(*vbt) + 4);
  161. pGCT = vbt->oaktrail_gct;
  162. bpi = ((struct oaktrail_gct_v2 *)pGCT)->PD.BootPanelIndex;
  163. dev_priv->gct_data.bpi = bpi;
  164. dev_priv->gct_data.pt =
  165. ((struct oaktrail_gct_v2 *)pGCT)->PD.PanelType;
  166. memcpy(&dev_priv->gct_data.DTD,
  167. &((struct oaktrail_gct_v2 *)pGCT)->panel[bpi].DTD,
  168. sizeof(struct oaktrail_timing_info));
  169. dev_priv->gct_data.Panel_Port_Control =
  170. ((struct oaktrail_gct_v2 *)pGCT)->panel[bpi].Panel_Port_Control;
  171. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  172. ((struct oaktrail_gct_v2 *)pGCT)->panel[bpi].Panel_MIPI_Display_Descriptor;
  173. break;
  174. case 0x10:
  175. /*header definition changed from rev 01 (v2) to rev 10h. */
  176. /*so, some values have changed location*/
  177. new_size = vbt->checksum; /*checksum contains lo size byte*/
  178. /*LSB of oaktrail_gct contains hi size byte*/
  179. new_size |= ((0xff & (unsigned int)(long)vbt->oaktrail_gct)) << 8;
  180. vbt->checksum = vbt->size; /*size contains the checksum*/
  181. if (new_size > 0xff)
  182. vbt->size = 0xff; /*restrict size to 255*/
  183. else
  184. vbt->size = new_size;
  185. /* number of descriptors defined in the GCT */
  186. number_desc = ((0xff00 & (unsigned int)(long)vbt->oaktrail_gct)) >> 8;
  187. bpi = ((0xff0000 & (unsigned int)(long)vbt->oaktrail_gct)) >> 16;
  188. vbt->oaktrail_gct = ioremap(addr + GCT_R10_HEADER_SIZE,
  189. GCT_R10_DISPLAY_DESC_SIZE * number_desc);
  190. pGCT = vbt->oaktrail_gct;
  191. pGCT = (u8 *)pGCT + (bpi*GCT_R10_DISPLAY_DESC_SIZE);
  192. dev_priv->gct_data.bpi = bpi; /*save boot panel id*/
  193. /*copy the GCT display timings into a temp structure*/
  194. memcpy(&ti, pGCT, sizeof(struct gct_r10_timing_info));
  195. /*now copy the temp struct into the dev_priv->gct_data*/
  196. dp_ti->pixel_clock = ti.pixel_clock;
  197. dp_ti->hactive_hi = ti.hactive_hi;
  198. dp_ti->hactive_lo = ti.hactive_lo;
  199. dp_ti->hblank_hi = ti.hblank_hi;
  200. dp_ti->hblank_lo = ti.hblank_lo;
  201. dp_ti->hsync_offset_hi = ti.hsync_offset_hi;
  202. dp_ti->hsync_offset_lo = ti.hsync_offset_lo;
  203. dp_ti->hsync_pulse_width_hi = ti.hsync_pulse_width_hi;
  204. dp_ti->hsync_pulse_width_lo = ti.hsync_pulse_width_lo;
  205. dp_ti->vactive_hi = ti.vactive_hi;
  206. dp_ti->vactive_lo = ti.vactive_lo;
  207. dp_ti->vblank_hi = ti.vblank_hi;
  208. dp_ti->vblank_lo = ti.vblank_lo;
  209. dp_ti->vsync_offset_hi = ti.vsync_offset_hi;
  210. dp_ti->vsync_offset_lo = ti.vsync_offset_lo;
  211. dp_ti->vsync_pulse_width_hi = ti.vsync_pulse_width_hi;
  212. dp_ti->vsync_pulse_width_lo = ti.vsync_pulse_width_lo;
  213. /* Move the MIPI_Display_Descriptor data from GCT to dev priv */
  214. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  215. *((u8 *)pGCT + 0x0d);
  216. dev_priv->gct_data.Panel_MIPI_Display_Descriptor |=
  217. (*((u8 *)pGCT + 0x0e)) << 8;
  218. break;
  219. default:
  220. dev_err(dev->dev, "Unknown revision of GCT!\n");
  221. vbt->size = 0;
  222. }
  223. }
  224. int mid_chip_setup(struct drm_device *dev)
  225. {
  226. struct drm_psb_private *dev_priv = dev->dev_private;
  227. mid_get_fuse_settings(dev);
  228. mid_get_vbt_data(dev_priv);
  229. mid_get_pci_revID(dev_priv);
  230. return 0;
  231. }