psb_lid.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 *lid_state = dev_priv->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. /*FIXME: should be backlight level before*/
  41. psb_intel_lvds_set_brightness(dev, 100);
  42. } else {
  43. psb_intel_lvds_set_brightness(dev, 0);
  44. REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & ~POWER_TARGET_ON);
  45. do {
  46. pp_status = REG_READ(PP_STATUS);
  47. } while ((pp_status & PP_ON) == 0);
  48. }
  49. dev_priv->lid_last_state = readl(lid_state);
  50. lid_timer_schedule:
  51. spin_lock_irqsave(&dev_priv->lid_lock, irq_flags);
  52. if (!timer_pending(lid_timer)) {
  53. lid_timer->expires = jiffies + PSB_LID_DELAY;
  54. add_timer(lid_timer);
  55. }
  56. spin_unlock_irqrestore(&dev_priv->lid_lock, irq_flags);
  57. }
  58. void psb_lid_timer_init(struct drm_psb_private *dev_priv)
  59. {
  60. struct timer_list *lid_timer = &dev_priv->lid_timer;
  61. unsigned long irq_flags;
  62. spin_lock_init(&dev_priv->lid_lock);
  63. spin_lock_irqsave(&dev_priv->lid_lock, irq_flags);
  64. init_timer(lid_timer);
  65. lid_timer->data = (unsigned long)dev_priv;
  66. lid_timer->function = psb_lid_timer_func;
  67. lid_timer->expires = jiffies + PSB_LID_DELAY;
  68. add_timer(lid_timer);
  69. spin_unlock_irqrestore(&dev_priv->lid_lock, irq_flags);
  70. }
  71. void psb_lid_timer_takedown(struct drm_psb_private *dev_priv)
  72. {
  73. del_timer_sync(&dev_priv->lid_timer);
  74. }