mid_bios.c 8.6 KB

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