Guest User

Intel GMA500/3600 backlight control for FreeBSD

a guest
May 18th, 2017
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. # Domian Public. IPR, 2017.
  4.  
  5. intel_bl_setpci="pciconf -w"
  6. intel_bl_getpci="pciconf -r"
  7. INTEL_BL_DEVICE="pci0:0:2:0"
  8. INTEL_BL_REGISTER="0xf4"
  9. INTEL_BL_MAX_VALUE="255"
  10. INTEL_BL_COMMAND="$1"
  11. INTEL_BL_SET_VALUE="$2"
  12.  
  13. [ "`id -u`" -eq "0" ] || { echo "Only root can run `basename $0`." ; exit 1 ; }
  14.  
  15. intel_bl_use() {
  16.     echo "Use: `basename $0` <+|-|=> <DEC_VALUE>"
  17.     echo "Final max value can be no more ${INTEL_BL_MAX_VALUE}"
  18.     exit 0
  19. }
  20.  
  21. INTEL_BL_CUR_VALUE="`${intel_bl_getpci} ${INTEL_BL_DEVICE} ${INTEL_BL_REGISTER}`"
  22. INTEL_BL_CUR_VALUE_DEC="`let 0x${INTEL_BL_CUR_VALUE}`"
  23.  
  24. if [ ! "$2" ] ; then
  25.     echo "Current value is ${INTEL_BL_CUR_VALUE_DEC}"
  26.     intel_bl_use
  27. fi
  28.  
  29. if [ "$1" = "+" -o "$1" = "-" ] ; then
  30.     INTEL_BL_EXP_VALUE="$((${INTEL_BL_CUR_VALUE_DEC} ${1} ${INTEL_BL_SET_VALUE}))"
  31. elif [ "$1" = "=" ] ; then
  32.     INTEL_BL_EXP_VALUE="${INTEL_BL_SET_VALUE}"
  33. else
  34.     intel_bl_use
  35. fi
  36.  
  37. if [ "${INTEL_BL_EXP_VALUE}" -gt "${INTEL_BL_MAX_VALUE}" ] ; then
  38.     echo "${INTEL_BL_EXP_VALUE} must not be greater than ${INTEL_BL_MAX_VALUE}" ; exit 1
  39. elif [ "${INTEL_BL_EXP_VALUE}" -lt "0" ] ; then
  40.     echo "${INTEL_BL_EXP_VALUE} must not be less than 0" ; exit 1
  41. fi
  42.  
  43. echo "Set backlight: ${INTEL_BL_CUR_VALUE_DEC} -> ${INTEL_BL_EXP_VALUE}"
  44. ${intel_bl_setpci} ${INTEL_BL_DEVICE} ${INTEL_BL_REGISTER} 0x`printf "%x" ${INTEL_BL_EXP_VALUE}`
RAW Paste Data