psb_lid.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**************************************************************************
  2. * Copyright (c) 2007, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Authors: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
  18. **************************************************************************/
  19. #include <drm/drmP.h>
  20. #include "psb_drv.h"
  21. #include "psb_reg.h"
  22. #include "psb_intel_reg.h"
  23. #include <linux/spinlock.h>
  24. static void psb_lid_timer_func(unsigned long data)
  25. {
  26. struct drm_psb_private * dev_priv = (struct drm_psb_private *)data;
  27. struct drm_device *dev = (struct drm_device *)dev_priv->dev;
  28. struct timer_list *lid_timer = &dev_priv->lid_timer;
  29. unsigned long irq_flags;
  30. u32 __iomem *lid_state = dev_priv->opregion.lid_state;
  31. u32 pp_status;
  32. if (readl(lid_state) == dev_priv->lid_last_state)
  33. goto lid_timer_schedule;
  34. if ((readl(lid_state)) & 0x01) {
  35. /*lid state is open*/
  36. REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | POWER_TARGET_ON);
  37. do {
  38. pp_status = REG_READ(PP_STATUS);
  39. } while ((pp_status & PP_ON) == 0 &&
  40. (pp_status & PP_SEQUENCE_MASK) != 0);
  41. if (REG_READ(PP_STATUS) & PP_ON) {
  42. /*FIXME: should be backlight level before*/
  43. psb_intel_lvds_set_brightness(dev, 100);
  44. } else {
  45. DRM_DEBUG("LVDS panel never powered up");
  46. return;
  47. }
  48. } else {
  49. psb_intel_lvds_set_brightness(dev, 0);
  50. REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & ~POWER_TARGET_ON);
  51. do {
  52. pp_status = REG_READ(PP_STATUS);
  53. } while ((pp_status & PP_ON) == 0);
  54. }
  55. dev_priv->lid_last_state = readl(lid_state);
  56. lid_timer_schedule:
  57. spin_lock_irqsave(&dev_priv->lid_lock, irq_flags);
  58. if (!timer_pending(lid_timer)) {
  59. lid_timer->expires = jiffies + PSB_LID_DELAY;
  60. add_timer(lid_timer);
  61. }
  62. spin_unlock_irqrestore(&dev_priv->lid_lock, irq_flags);
  63. }
  64. void psb_lid_timer_init(struct drm_psb_private *dev_priv)
  65. {
  66. struct timer_list *lid_timer = &dev_priv->lid_timer;
  67. unsigned long irq_flags;
  68. spin_lock_init(&dev_priv->lid_lock);
  69. spin_lock_irqsave(&dev_priv->lid_lock, irq_flags);
  70. init_timer(lid_timer);
  71. lid_timer->data = (unsigned long)dev_priv;
  72. lid_timer->function = psb_lid_timer_func;
  73. lid_timer->expires = jiffies + PSB_LID_DELAY;
  74. add_timer(lid_timer);
  75. spin_unlock_irqrestore(&dev_priv->lid_lock, irq_flags);
  76. }
  77. void psb_lid_timer_takedown(struct drm_psb_private *dev_priv)
  78. {
  79. del_timer_sync(&dev_priv->lid_timer);
  80. }