Howard Chiu | 0eb09a1 | 2021-12-09 13:27:04 +0800 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
| 3 | set_gpio() |
| 4 | { |
| 5 | NET_NAME=$1 |
| 6 | OUT_VAL=$2 |
| 7 | mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME") |
| 8 | if [ "${#GPIO_INFO[@]}" -ne 2 ]; then |
| 9 | echo "set_gpio: can not find gpio, $NET_NAME" |
| 10 | return 1 |
| 11 | fi |
| 12 | |
| 13 | echo -n "set_gpio: set $NET_NAME = $OUT_VAL" |
| 14 | if ! gpioset "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}"="$OUT_VAL"; then |
| 15 | echo " failed" |
| 16 | return 1 |
| 17 | fi |
| 18 | |
| 19 | echo " success" |
| 20 | return 0 |
| 21 | } |
| 22 | |
| 23 | set_fan() |
| 24 | { |
| 25 | FAN_ID=$1 |
| 26 | FAN_DUTY=$2 |
| 27 | SYSFA_PWM_PATH="" |
| 28 | |
| 29 | for file in /sys/devices/platform/pwm-fan"$FAN_ID"/hwmon/hwmon*/pwm1 |
| 30 | do |
| 31 | if [ -e "$file" ]; then |
| 32 | SYSFA_PWM_PATH="$file" |
| 33 | break |
| 34 | fi |
| 35 | done |
| 36 | |
| 37 | if [ -z "$SYSFA_PWM_PATH" ]; then |
| 38 | echo "set_fan: pwm file not found, chekc fan id ($FAN_ID)" |
| 39 | return 1 |
| 40 | fi |
| 41 | |
| 42 | if [ "$FAN_DUTY" -lt 0 ] || [ "$FAN_DUTY" -gt 100 ]; then |
| 43 | echo "set_fan: incorrect fan duty, $FAN_DUTY" |
| 44 | return 1 |
| 45 | fi |
| 46 | |
| 47 | # convert duty (0-100) to pwm value (0-255) |
| 48 | PWM_VAL=$(printf "%.0f" $((FAN_DUTY*255/100))) |
| 49 | |
| 50 | echo -n "set_fan: set fan$FAN_ID = $FAN_DUTY" |
| 51 | if ! echo "$PWM_VAL" > "$SYSFA_PWM_PATH"; then |
| 52 | echo " failed" |
| 53 | return 1 |
| 54 | fi |
| 55 | |
| 56 | echo " success" |
| 57 | return 0 |
| 58 | } |
| 59 | |
| 60 | # set initial value for GPIO output pins |
| 61 | set_gpio SEL_SPI2_MUX 1 |
| 62 | set_gpio SPI2_MUX1 1 |
| 63 | set_gpio SPI2_MUX2 1 |
| 64 | set_gpio SPI2_MUX3 1 |
| 65 | set_gpio SWITCH_FRU_MUX 1 |
| 66 | set_gpio BAT_DETECT 1 |
Potin Lai | 9428ff2 | 2022-05-10 12:19:46 +0800 | [diff] [blame^] | 67 | set_gpio BMC_BT_WP0_N 1 |
| 68 | set_gpio BMC_BT_WP1_N 1 |
Howard Chiu | 0eb09a1 | 2021-12-09 13:27:04 +0800 | [diff] [blame] | 69 | set_gpio USB2_SEL0_A 1 |
| 70 | set_gpio USB2_SEL1_A 1 |
| 71 | set_gpio USB2_SEL0_B 1 |
| 72 | set_gpio USB2_SEL1_B 1 |
Potin Lai | 9428ff2 | 2022-05-10 12:19:46 +0800 | [diff] [blame^] | 73 | set_gpio RST_FRONT_IOEXP_N 1 |
| 74 | set_gpio BSM_FLASH_LATCH_N 1 |
Howard Chiu | 0eb09a1 | 2021-12-09 13:27:04 +0800 | [diff] [blame] | 75 | |
| 76 | # set initial duty value for each fan |
| 77 | set_fan 0 70 |
| 78 | set_fan 1 70 |
| 79 | set_fan 2 70 |
| 80 | set_fan 3 70 |
| 81 | |
| 82 | exit 0; |