mid_bios.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 <drm/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_SKU_MASK 0x7000
  39. #define FB_SKU_SHIFT 12
  40. #define FB_SKU_100 0
  41. #define FB_SKU_100L 1
  42. #define FB_SKU_83 2
  43. if (pci_root == NULL) {
  44. WARN_ON(1);
  45. return;
  46. }
  47. pci_write_config_dword(pci_root, 0xD0, FB_REG06);
  48. pci_read_config_dword(pci_root, 0xD4, &fuse_value);
  49. /* FB_MIPI_DISABLE doesn't mean LVDS on with Medfield */
  50. if (IS_MRST(dev))
  51. dev_priv->iLVDS_enable = fuse_value & FB_MIPI_DISABLE;
  52. DRM_INFO("internal display is %s\n",
  53. dev_priv->iLVDS_enable ? "LVDS display" : "MIPI display");
  54. /* Prevent runtime suspend at start*/
  55. if (dev_priv->iLVDS_enable) {
  56. dev_priv->is_lvds_on = true;
  57. dev_priv->is_mipi_on = false;
  58. } else {
  59. dev_priv->is_mipi_on = true;
  60. dev_priv->is_lvds_on = false;
  61. }
  62. dev_priv->video_device_fuse = fuse_value;
  63. pci_write_config_dword(pci_root, 0xD0, FB_REG09);
  64. pci_read_config_dword(pci_root, 0xD4, &fuse_value);
  65. dev_dbg(dev->dev, "SKU values is 0x%x.\n", fuse_value);
  66. fuse_value_tmp = (fuse_value & FB_SKU_MASK) >> FB_SKU_SHIFT;
  67. dev_priv->fuse_reg_value = fuse_value;
  68. switch (fuse_value_tmp) {
  69. case FB_SKU_100:
  70. dev_priv->core_freq = 200;
  71. break;
  72. case FB_SKU_100L:
  73. dev_priv->core_freq = 100;
  74. break;
  75. case FB_SKU_83:
  76. dev_priv->core_freq = 166;
  77. break;
  78. default:
  79. dev_warn(dev->dev, "Invalid SKU values, SKU value = 0x%08x\n",
  80. fuse_value_tmp);
  81. dev_priv->core_freq = 0;
  82. }
  83. dev_dbg(dev->dev, "LNC core clk is %dMHz.\n", dev_priv->core_freq);
  84. pci_dev_put(pci_root);
  85. }
  86. /*
  87. * Get the revison ID, B0:D2:F0;0x08
  88. */
  89. static void mid_get_pci_revID(struct drm_psb_private *dev_priv)
  90. {
  91. uint32_t platform_rev_id = 0;
  92. struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
  93. if (pci_gfx_root == NULL) {
  94. WARN_ON(1);
  95. return;
  96. }
  97. pci_read_config_dword(pci_gfx_root, 0x08, &platform_rev_id);
  98. dev_priv->platform_rev_id = (uint8_t) platform_rev_id;
  99. pci_dev_put(pci_gfx_root);
  100. dev_dbg(dev_priv->dev->dev, "platform_rev_id is %x\n",
  101. dev_priv->platform_rev_id);
  102. }
  103. struct mid_vbt_header {
  104. u32 signature;
  105. u8 revision;
  106. } __packed;
  107. /* The same for r0 and r1 */
  108. struct vbt_r0 {
  109. struct mid_vbt_header vbt_header;
  110. u8 size;
  111. u8 checksum;
  112. } __packed;
  113. struct vbt_r10 {
  114. struct mid_vbt_header vbt_header;
  115. u8 checksum;
  116. u16 size;
  117. u8 panel_count;
  118. u8 primary_panel_idx;
  119. u8 secondary_panel_idx;
  120. u8 __reserved[5];
  121. } __packed;
  122. static int read_vbt_r0(u32 addr, struct vbt_r0 *vbt)
  123. {
  124. void __iomem *vbt_virtual;
  125. vbt_virtual = ioremap(addr, sizeof(*vbt));
  126. if (vbt_virtual == NULL)
  127. return -1;
  128. memcpy_fromio(vbt, vbt_virtual, sizeof(*vbt));
  129. iounmap(vbt_virtual);
  130. return 0;
  131. }
  132. static int read_vbt_r10(u32 addr, struct vbt_r10 *vbt)
  133. {
  134. void __iomem *vbt_virtual;
  135. vbt_virtual = ioremap(addr, sizeof(*vbt));
  136. if (!vbt_virtual)
  137. return -1;
  138. memcpy_fromio(vbt, vbt_virtual, sizeof(*vbt));
  139. iounmap(vbt_virtual);
  140. return 0;
  141. }
  142. static int mid_get_vbt_data_r0(struct drm_psb_private *dev_priv, u32 addr)
  143. {
  144. struct vbt_r0 vbt;
  145. void __iomem *gct_virtual;
  146. struct gct_r0 gct;
  147. u8 bpi;
  148. if (read_vbt_r0(addr, &vbt))
  149. return -1;
  150. gct_virtual = ioremap(addr + sizeof(vbt), vbt.size - sizeof(vbt));
  151. if (!gct_virtual)
  152. return -1;
  153. memcpy_fromio(&gct, gct_virtual, sizeof(gct));
  154. iounmap(gct_virtual);
  155. bpi = gct.PD.BootPanelIndex;
  156. dev_priv->gct_data.bpi = bpi;
  157. dev_priv->gct_data.pt = gct.PD.PanelType;
  158. dev_priv->gct_data.DTD = gct.panel[bpi].DTD;
  159. dev_priv->gct_data.Panel_Port_Control =
  160. gct.panel[bpi].Panel_Port_Control;
  161. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  162. gct.panel[bpi].Panel_MIPI_Display_Descriptor;
  163. return 0;
  164. }
  165. static int mid_get_vbt_data_r1(struct drm_psb_private *dev_priv, u32 addr)
  166. {
  167. struct vbt_r0 vbt;
  168. void __iomem *gct_virtual;
  169. struct gct_r1 gct;
  170. u8 bpi;
  171. if (read_vbt_r0(addr, &vbt))
  172. return -1;
  173. gct_virtual = ioremap(addr + sizeof(vbt), vbt.size - sizeof(vbt));
  174. if (!gct_virtual)
  175. return -1;
  176. memcpy_fromio(&gct, gct_virtual, sizeof(gct));
  177. iounmap(gct_virtual);
  178. bpi = gct.PD.BootPanelIndex;
  179. dev_priv->gct_data.bpi = bpi;
  180. dev_priv->gct_data.pt = gct.PD.PanelType;
  181. dev_priv->gct_data.DTD = gct.panel[bpi].DTD;
  182. dev_priv->gct_data.Panel_Port_Control =
  183. gct.panel[bpi].Panel_Port_Control;
  184. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  185. gct.panel[bpi].Panel_MIPI_Display_Descriptor;
  186. return 0;
  187. }
  188. static int mid_get_vbt_data_r10(struct drm_psb_private *dev_priv, u32 addr)
  189. {
  190. struct vbt_r10 vbt;
  191. void __iomem *gct_virtual;
  192. struct gct_r10 *gct;
  193. struct oaktrail_timing_info *dp_ti = &dev_priv->gct_data.DTD;
  194. struct gct_r10_timing_info *ti;
  195. int ret = -1;
  196. if (read_vbt_r10(addr, &vbt))
  197. return -1;
  198. gct = kmalloc(sizeof(*gct) * vbt.panel_count, GFP_KERNEL);
  199. if (!gct)
  200. return -1;
  201. gct_virtual = ioremap(addr + sizeof(vbt),
  202. sizeof(*gct) * vbt.panel_count);
  203. if (!gct_virtual)
  204. goto out;
  205. memcpy_fromio(gct, gct_virtual, sizeof(*gct));
  206. iounmap(gct_virtual);
  207. dev_priv->gct_data.bpi = vbt.primary_panel_idx;
  208. dev_priv->gct_data.Panel_MIPI_Display_Descriptor =
  209. gct[vbt.primary_panel_idx].Panel_MIPI_Display_Descriptor;
  210. ti = &gct[vbt.primary_panel_idx].DTD;
  211. dp_ti->pixel_clock = ti->pixel_clock;
  212. dp_ti->hactive_hi = ti->hactive_hi;
  213. dp_ti->hactive_lo = ti->hactive_lo;
  214. dp_ti->hblank_hi = ti->hblank_hi;
  215. dp_ti->hblank_lo = ti->hblank_lo;
  216. dp_ti->hsync_offset_hi = ti->hsync_offset_hi;
  217. dp_ti->hsync_offset_lo = ti->hsync_offset_lo;
  218. dp_ti->hsync_pulse_width_hi = ti->hsync_pulse_width_hi;
  219. dp_ti->hsync_pulse_width_lo = ti->hsync_pulse_width_lo;
  220. dp_ti->vactive_hi = ti->vactive_hi;
  221. dp_ti->vactive_lo = ti->vactive_lo;
  222. dp_ti->vblank_hi = ti->vblank_hi;
  223. dp_ti->vblank_lo = ti->vblank_lo;
  224. dp_ti->vsync_offset_hi = ti->vsync_offset_hi;
  225. dp_ti->vsync_offset_lo = ti->vsync_offset_lo;
  226. dp_ti->vsync_pulse_width_hi = ti->vsync_pulse_width_hi;
  227. dp_ti->vsync_pulse_width_lo = ti->vsync_pulse_width_lo;
  228. ret = 0;
  229. out:
  230. kfree(gct);
  231. return ret;
  232. }
  233. static void mid_get_vbt_data(struct drm_psb_private *dev_priv)
  234. {
  235. struct drm_device *dev = dev_priv->dev;
  236. u32 addr;
  237. u8 __iomem *vbt_virtual;
  238. struct mid_vbt_header vbt_header;
  239. struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
  240. int ret = -1;
  241. /* Get the address of the platform config vbt */
  242. pci_read_config_dword(pci_gfx_root, 0xFC, &addr);
  243. pci_dev_put(pci_gfx_root);
  244. dev_dbg(dev->dev, "drm platform config address is %x\n", addr);
  245. if (!addr)
  246. goto out;
  247. /* get the virtual address of the vbt */
  248. vbt_virtual = ioremap(addr, sizeof(vbt_header));
  249. if (!vbt_virtual)
  250. goto out;
  251. memcpy_fromio(&vbt_header, vbt_virtual, sizeof(vbt_header));
  252. iounmap(vbt_virtual);
  253. if (memcmp(&vbt_header.signature, "$GCT", 4))
  254. goto out;
  255. dev_dbg(dev->dev, "GCT revision is %02x\n", vbt_header.revision);
  256. switch (vbt_header.revision) {
  257. case 0x00:
  258. ret = mid_get_vbt_data_r0(dev_priv, addr);
  259. break;
  260. case 0x01:
  261. ret = mid_get_vbt_data_r1(dev_priv, addr);
  262. break;
  263. case 0x10:
  264. ret = mid_get_vbt_data_r10(dev_priv, addr);
  265. break;
  266. default:
  267. dev_err(dev->dev, "Unknown revision of GCT!\n");
  268. }
  269. out:
  270. if (ret)
  271. dev_err(dev->dev, "Unable to read GCT!");
  272. else
  273. dev_priv->has_gct = true;
  274. }
  275. int mid_chip_setup(struct drm_device *dev)
  276. {
  277. struct drm_psb_private *dev_priv = dev->dev_private;
  278. mid_get_fuse_settings(dev);
  279. mid_get_vbt_data(dev_priv);
  280. mid_get_pci_revID(dev_priv);
  281. return 0;
  282. }