Advertisement
trixur

jmb38x_d3e.sh

Sep 5th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.39 KB | None | 0 0
  1. ----------------------------------------------
  2. #!/bin/bash
  3.  
  4. # Setup delay time (minutes)
  5. delay=5
  6.  
  7. function chk_pciehp ()
  8. {
  9. check=`lsmod | grep pciehp`
  10. if [ -z "$check" ] ; then
  11. echo "Loading PCIe Hotplug driver..."
  12. modprobe pciehp pciehp_force=1
  13. else
  14. echo "PCIe Hotplug driver was loaded."
  15. fi
  16. }
  17.  
  18. function scan_dev ()
  19. {
  20. i=1
  21. host=`lspci -d 197b:2382 | wc -l`
  22. while [ $i -le $host ]
  23. do
  24. dev[$i]=`lspci -d 197b:2382 | awk '{print $1}' | head -n$i | tail -n1`
  25. #   echo ${dev[$i]}
  26. i=`echo "$i+1" | bc`
  27. done
  28. }
  29.  
  30. function acdc ()
  31. {
  32. i=1
  33.  
  34. while [ $i -le $host ]
  35. do
  36. dev=${dev[$i]}
  37. if [ -z "$dev" ] ; then
  38. echo "JMicron JMB38x is not found!"
  39. else
  40. probe=`lspci -s $dev -xxx | grep a0: | awk '{print $14}'`
  41. if [ -n "$probe" ] ; then
  42. if [ $probe = 40 ] ||
  43. [ $probe = 41 ] ||
  44. [ $probe = 42 ] ||
  45. [ $probe = 43 ] ||
  46. [ $probe = 44 ] ||
  47. [ $probe = 45 ] ||
  48. [ $probe = 46 ] ||
  49. [ $probe = 47 ] ||
  50. [ $probe = 48 ] ||
  51. [ $probe = 49 ] ||
  52. [ $probe = 4a ] ||
  53. [ $probe = 4b ] ||
  54. [ $probe = 4c ] ||
  55. [ $probe = 4d ] ||
  56. [ $probe = 4e ] ||
  57. [ $probe = 4f ] ; then
  58. PWRMODE=1
  59. echo "JMB38X: Battery mode!!"
  60. else
  61. PWRMODE=0
  62. echo "JMB38X: AC power pluged!!"
  63. fi
  64. fi
  65. fi
  66. i=`echo "$i+1" | bc`
  67. done
  68. }
  69.  
  70. function d3e ()
  71. {
  72. i=1
  73.  
  74. while [ $i -le $host ]
  75. do
  76. dev=${dev[$i]}
  77. if [ -z "$dev" ] ; then
  78. echo "JMicron JMB38x is not found!"
  79. else
  80. probe=`lspci -s $dev -xxx | grep e0: | awk '{print $3}'`
  81. if [ -n "$probe" ] ; then
  82. if [ $probe = 0c ] ||
  83. [ $probe = 1c ] ||
  84. [ $probe = 1c ] ||
  85. [ $probe = 2c ] ||
  86. [ $probe = 3c ] ||
  87. [ $probe = 4c ] ||
  88. [ $probe = 5c ] ||
  89. [ $probe = 6c ] ||
  90. [ $probe = 7c ] ||
  91. [ $probe = 8c ] ||
  92. [ $probe = 9c ] ||
  93. [ $probe = ac ] ||
  94. [ $probe = bc ] ||
  95. [ $probe = cc ] ||
  96. [ $probe = dc ] ||
  97. [ $probe = ec ] ||
  98. [ $probe = fc ] ; then
  99. setpci -s $dev D4=10:F0
  100. setpci -s $dev AD=FF
  101. setpci -s $dev AE=69
  102. echo "JMB38X: JMB38X D3e function is enabled!"
  103. else
  104. echo "JMB38X: There is a card inserted!"
  105. fi
  106. fi
  107. fi
  108. i=`echo "$i+1" | bc`
  109. done
  110. }
  111.  
  112. function poll ()
  113. {
  114. i=1
  115. time=`echo "$delay*60" | bc`
  116. while :
  117. do
  118. scan_dev
  119. if [ -f /sys/bus/usb/devices/1-5/power/level ]; then
  120. echo auto > /sys/bus/usb/devices/1-5/power/level
  121. fi
  122.  
  123. if [ -f /sys/bus/usb/devices/5-5/power/level ]; then
  124. echo auto > /sys/bus/usb/devices/5-5/power/level
  125. fi
  126. sleep $time
  127. acdc
  128. if [ $PWRMODE -eq 1 ] ; then
  129. d3e
  130. fi
  131. done
  132. }
  133.  
  134. function main ()
  135. {
  136. chk_pciehp
  137. poll
  138. }
  139.  
  140. main
  141. --------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement