Advertisement
Guest User

Untitled

a guest
Apr 7th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Copyright 2006-2007 Richard Hughes <richard@hughsie.com>
  4. # Copyright 2007 Peter Jones <pjones@redhat.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of version 2 of the GNU General Public License as
  8. # published by the Free Software Foundation.
  9.  
  10. # Handle video quirks. If you are having suspend/resume issues,
  11. # troubleshooting using this hook is probably the best place to start.
  12. # If it weren't for video card quirks, suspend/resume on Linux would be
  13. # a whole lot more stable.
  14.  
  15. . "${PM_FUNCTIONS}"
  16.  
  17. for opt in $PM_CMDLINE; do
  18. case "${opt##--quirk-}" in # just quirks, please
  19. dpms-on) QUIRK_DPMS_ON="true" ;;
  20. dpms-suspend) QUIRK_DPMS_SUSPEND="true" ;;
  21. radeon-off) QUIRK_RADEON_OFF="true" ;;
  22. reset-brightness) QUIRK_RESET_BRIGHTNESS="true" ;;
  23. s3-bios) QUIRK_S3_BIOS="true" ;;
  24. s3-mode) QUIRK_S3_MODE="true" ;;
  25. vbe-post) QUIRK_VBE_POST="true" ;;
  26. vbemode-restore) QUIRK_VBEMODE_RESTORE="true" ;;
  27. vbestate-restore) QUIRK_VBESTATE_RESTORE="true" ;;
  28. vga-mode-3) QUIRK_VGA_MODE_3="true" ;;
  29. no-fb) QUIRK_NOFB="true" ;;
  30. save-pci) QUIRK_SAVE_PCI="true" ;;
  31. no-chvt) QUIRK_NO_CHVT="true" ;;
  32. none) QUIRK_NONE="true" ;;
  33. *) continue ;;
  34. esac
  35. done
  36.  
  37. reset_brightness()
  38. {
  39. for bl in /sys/class/backlight/* ; do
  40. [ -f "$bl/brightness" ] || continue
  41. BR="$(cat $bl/brightness)"
  42. echo 0 > "$bl/brightness"
  43. # echo "$BR" > "$bl/brightness"
  44. done
  45. }
  46.  
  47. if command_exists vbetool; then
  48. vbe() { vbetool "$@"; }
  49. else
  50. vbe() { echo "vbetool not installed!" 1>&2; return 1; }
  51. fi
  52.  
  53. if command_exists radeontool; then
  54. radeon() { radeontool "$@"; }
  55. else
  56. radeon() { echo "radeontool not found" 1>&2; return 1; }
  57. fi
  58.  
  59. die_if_framebuffer()
  60. {
  61. [ -d "/sys/class/graphics/fb0" ] || return
  62. echo "--quirk-no-fb passed, but system is using a framebuffer."
  63. echo "Aborting."
  64. exit 1
  65. }
  66.  
  67.  
  68. save_fbcon()
  69. {
  70. local con
  71. for con in /sys/class/graphics/*/state; do
  72. [ -f $con ] || continue
  73. echo 1 >"${con}"
  74. done
  75. }
  76.  
  77. resume_fbcon()
  78. {
  79. local con
  80. for con in /sys/class/graphics/*/state; do
  81. [ -f $con ] || continue
  82. echo 0 >"${con}"
  83. done
  84. }
  85.  
  86. maybe_chvt()
  87. {
  88. is_set "$QUIRK_NO_CHVT" && return
  89. fgconsole |savestate console
  90. chvt 63
  91. }
  92.  
  93. maybe_deallocvt()
  94. {
  95. state_exists console || return 0
  96. chvt $(restorestate console)
  97. deallocvt 63
  98. }
  99.  
  100. # Some tiny helper functions for quirk handling
  101. quirk() { is_set "$1" && [ -z $QUIRK_NONE ]; }
  102.  
  103. # save/restore vbe state
  104. vbe_savestate() { vbe vbestate save |savestate vbestate; }
  105. vbe_restorestate() { restorestate vbestate |vbe vbestate restore; }
  106.  
  107. # save/restore the vbe mode
  108. vbe_savemode() { vbe vbemode get |savestate vbemode; }
  109. vbe_restoremode()
  110. {
  111. # this is a little mode complicated to handle special-casing mode 3.
  112. local vbemode=$(restorestate vbemode)
  113. if [ "$vbemode" = "3" ]; then
  114. vbe vgamode set $vbemode
  115. else
  116. vbe vbemode set $vbemode
  117. fi
  118. }
  119.  
  120. # post the video card
  121. vbe_post()
  122. {
  123. local rom="/var/run/video.rom"
  124. # if we do not have a romfile, do not post with it.
  125. [ -f "$rom" ] || unset rom
  126. vbe post $rom
  127. sleep 0.1
  128. }
  129.  
  130. # turn critical bits of radeon cards off/on
  131. radeon_off() { radeon dac off; radeon light off; }
  132. radeon_on() { radeon dac on; radeon light on; }
  133.  
  134. # save and restore video card PCI config state
  135. save_pci()
  136. {
  137. local pci="/sys/bus/pci/devices"
  138. for dev in "${pci}"/*; do
  139. [ -f "${dev}/class" ] || continue
  140. [ $(cat "${dev}/class") = "0x030000" ] || continue
  141. [ -f "${dev}/config" ] || continue
  142. # it is a video card, it has a configuration. Save it.
  143. savestate "pci_video_${dev##*/}" <${dev}/config
  144. done
  145. }
  146.  
  147. restore_pci()
  148. {
  149. local pci="/sys/bus/pci/devices"
  150. for dev in "${pci}"/*; do
  151. state_exists "pci_video_${dev##*/}" || continue
  152. restorestate "pci_video_${dev##*/}" > "${dev}/config"
  153. done
  154. }
  155.  
  156. suspend_video()
  157. {
  158. # 0=nothing, 1=s3_bios, 2=s3_mode, 3=both
  159. local acpi_flag=0
  160. quirk "${QUIRK_S3_BIOS}" && acpi_flag=$(($acpi_flag + 1))
  161. quirk "${QUIRK_S3_MODE}" && acpi_flag=$(($acpi_flag + 2))
  162. sysctl -w kernel.acpi_video_flags=$acpi_flag
  163.  
  164. quirk "${QUIRK_NOFB}" && die_if_framebuffer
  165. quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_savestate
  166. quirk "${QUIRK_VBEMODE_RESTORE}" && vbe_savemode
  167. quirk "${QUIRK_RADEON_OFF}" && radeon_off
  168. quirk "${QUIRK_SAVE_PCI}" && save_pci
  169. quirk "${QUIRK_VGA_MODE_3}" && vbe vbemode set 3
  170. quirk "${QUIRK_DPMS_SUSPEND}" && vbe dpms suspend
  171. save_fbcon
  172. }
  173. resume_video()
  174. {
  175. # We might need to do one or many of these quirks
  176. quirk "${QUIRK_SAVE_PCI}" && restore_pci
  177. quirk "${QUIRK_VBE_POST}" && vbe_post
  178. quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_restorestate
  179. quirk "${QUIRK_VBEMODE_RESTORE}" && vbe_restoremode
  180. resume_fbcon # also should be handled by a quirk.
  181. quirk "${QUIRK_RADEON_OFF}" && radeon_on
  182. quirk "${QUIRK_DPMS_ON}" && vbe dpms on
  183. quirk "${QUIRK_RESET_BRIGHTNESS}" && reset_brightness
  184. return 0 # avoid spurious hook exit failure message.
  185. }
  186.  
  187. help() {
  188. echo # first echo makes it look nicer.
  189. echo "Video quirk handler options:"
  190. echo
  191. echo " --quirk-dpms-on"
  192. echo " --quirk-dpms-suspend"
  193. echo " --quirk-radeon-off"
  194. echo " --quirk-reset-brightness"
  195. echo " --quirk-s3-bios"
  196. echo " --quirk-s3-mode"
  197. echo " --quirk-vbe-post"
  198. echo " --quirk-vbemode-restore"
  199. echo " --quirk-vbestate-restore"
  200. echo " --quirk-vga-mode-3"
  201. echo " --quirk-none"
  202. }
  203.  
  204. case "$1" in
  205. suspend) maybe_chvt; suspend_video ;;
  206. hibernate) maybe_chvt
  207. if is_set "$HIBERNATE_RESUME_POST_VIDEO"; then
  208. suspend_video
  209. fi
  210. ;;
  211. resume) resume_video; maybe_deallocvt;;
  212. thaw)
  213. if is_set "${HIBERNATE_RESUME_POST_VIDEO}"; then
  214. resume_video
  215. fi
  216. maybe_deallocvt
  217. ;;
  218. help) help ;;
  219. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement