intel_opregion.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright 2010 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * FIXME: resolve with the i915 version
  24. */
  25. #include "psb_drv.h"
  26. #define PCI_ASLE 0xe4
  27. #define PCI_ASLS 0xfc
  28. #define OPREGION_HEADER_OFFSET 0
  29. #define OPREGION_ACPI_OFFSET 0x100
  30. #define ACPI_CLID 0x01ac /* current lid state indicator */
  31. #define ACPI_CDCK 0x01b0 /* current docking state indicator */
  32. #define OPREGION_SWSCI_OFFSET 0x200
  33. #define OPREGION_ASLE_OFFSET 0x300
  34. #define OPREGION_VBT_OFFSET 0x400
  35. #define OPREGION_SIGNATURE "IntelGraphicsMem"
  36. #define MBOX_ACPI (1<<0)
  37. #define MBOX_SWSCI (1<<1)
  38. #define MBOX_ASLE (1<<2)
  39. struct opregion_header {
  40. u8 signature[16];
  41. u32 size;
  42. u32 opregion_ver;
  43. u8 bios_ver[32];
  44. u8 vbios_ver[16];
  45. u8 driver_ver[16];
  46. u32 mboxes;
  47. u8 reserved[164];
  48. } __packed;
  49. /* OpRegion mailbox #1: public ACPI methods */
  50. struct opregion_acpi {
  51. u32 drdy; /* driver readiness */
  52. u32 csts; /* notification status */
  53. u32 cevt; /* current event */
  54. u8 rsvd1[20];
  55. u32 didl[8]; /* supported display devices ID list */
  56. u32 cpdl[8]; /* currently presented display list */
  57. u32 cadl[8]; /* currently active display list */
  58. u32 nadl[8]; /* next active devices list */
  59. u32 aslp; /* ASL sleep time-out */
  60. u32 tidx; /* toggle table index */
  61. u32 chpd; /* current hotplug enable indicator */
  62. u32 clid; /* current lid state*/
  63. u32 cdck; /* current docking state */
  64. u32 sxsw; /* Sx state resume */
  65. u32 evts; /* ASL supported events */
  66. u32 cnot; /* current OS notification */
  67. u32 nrdy; /* driver status */
  68. u8 rsvd2[60];
  69. } __attribute__((packed));
  70. /* OpRegion mailbox #2: SWSCI */
  71. struct opregion_swsci {
  72. u32 scic; /* SWSCI command|status|data */
  73. u32 parm; /* command parameters */
  74. u32 dslp; /* driver sleep time-out */
  75. u8 rsvd[244];
  76. } __attribute__((packed));
  77. /* OpRegion mailbox #3: ASLE */
  78. struct opregion_asle {
  79. u32 ardy; /* driver readiness */
  80. u32 aslc; /* ASLE interrupt command */
  81. u32 tche; /* technology enabled indicator */
  82. u32 alsi; /* current ALS illuminance reading */
  83. u32 bclp; /* backlight brightness to set */
  84. u32 pfit; /* panel fitting state */
  85. u32 cblv; /* current brightness level */
  86. u16 bclm[20]; /* backlight level duty cycle mapping table */
  87. u32 cpfm; /* current panel fitting mode */
  88. u32 epfm; /* enabled panel fitting modes */
  89. u8 plut[74]; /* panel LUT and identifier */
  90. u32 pfmb; /* PWM freq and min brightness */
  91. u8 rsvd[102];
  92. } __attribute__((packed));
  93. /* ASLE irq request bits */
  94. #define ASLE_SET_ALS_ILLUM (1 << 0)
  95. #define ASLE_SET_BACKLIGHT (1 << 1)
  96. #define ASLE_SET_PFIT (1 << 2)
  97. #define ASLE_SET_PWM_FREQ (1 << 3)
  98. #define ASLE_REQ_MSK 0xf
  99. /* response bits of ASLE irq request */
  100. #define ASLE_ALS_ILLUM_FAILED (1<<10)
  101. #define ASLE_BACKLIGHT_FAILED (1<<12)
  102. #define ASLE_PFIT_FAILED (1<<14)
  103. #define ASLE_PWM_FREQ_FAILED (1<<16)
  104. /* ASLE backlight brightness to set */
  105. #define ASLE_BCLP_VALID (1<<31)
  106. #define ASLE_BCLP_MSK (~(1<<31))
  107. /* ASLE panel fitting request */
  108. #define ASLE_PFIT_VALID (1<<31)
  109. #define ASLE_PFIT_CENTER (1<<0)
  110. #define ASLE_PFIT_STRETCH_TEXT (1<<1)
  111. #define ASLE_PFIT_STRETCH_GFX (1<<2)
  112. /* PWM frequency and minimum brightness */
  113. #define ASLE_PFMB_BRIGHTNESS_MASK (0xff)
  114. #define ASLE_PFMB_BRIGHTNESS_VALID (1<<8)
  115. #define ASLE_PFMB_PWM_MASK (0x7ffffe00)
  116. #define ASLE_PFMB_PWM_VALID (1<<31)
  117. #define ASLE_CBLV_VALID (1<<31)
  118. #define ACPI_OTHER_OUTPUT (0<<8)
  119. #define ACPI_VGA_OUTPUT (1<<8)
  120. #define ACPI_TV_OUTPUT (2<<8)
  121. #define ACPI_DIGITAL_OUTPUT (3<<8)
  122. #define ACPI_LVDS_OUTPUT (4<<8)
  123. int gma_intel_opregion_init(struct drm_device *dev)
  124. {
  125. struct drm_psb_private *dev_priv = dev->dev_private;
  126. struct psb_intel_opregion *opregion = &dev_priv->opregion;
  127. u32 opregion_phy;
  128. void *base;
  129. u32 *lid_state;
  130. dev_priv->lid_state = NULL;
  131. pci_read_config_dword(dev->pdev, 0xfc, &opregion_phy);
  132. if (opregion_phy == 0)
  133. return -ENOTSUPP;
  134. base = ioremap(opregion_phy, 8*1024);
  135. if (!base)
  136. return -ENOMEM;
  137. /* FIXME: should use _io ops - ditto on i915 */
  138. if (memcmp(base, OPREGION_SIGNATURE, 16)) {
  139. DRM_ERROR("opregion signature mismatch\n");
  140. iounmap(base);
  141. return -EINVAL;
  142. }
  143. lid_state = base + 0x01ac;
  144. dev_priv->lid_state = lid_state;
  145. dev_priv->lid_last_state = readl(lid_state);
  146. opregion->header = base;
  147. opregion->vbt = base + OPREGION_VBT_OFFSET;
  148. return 0;
  149. }
  150. int gma_intel_opregion_exit(struct drm_device *dev)
  151. {
  152. struct drm_psb_private *dev_priv = dev->dev_private;
  153. if (dev_priv->opregion.header)
  154. iounmap(dev_priv->opregion.header);
  155. return 0;
  156. }