blob: 2d41c94ce387530f9ae50c2db839d5ab4fa189de [file] [log] [blame]
Howard Chiu0eb09a12021-12-09 13:27:04 +08001#!/bin/bash -e
2
3set_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
23set_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
61set_gpio SEL_SPI2_MUX 1
62set_gpio SPI2_MUX1 1
63set_gpio SPI2_MUX2 1
64set_gpio SPI2_MUX3 1
65set_gpio SWITCH_FRU_MUX 1
66set_gpio BAT_DETECT 1
Potin Lai9428ff22022-05-10 12:19:46 +080067set_gpio BMC_BT_WP0_N 1
68set_gpio BMC_BT_WP1_N 1
Howard Chiu0eb09a12021-12-09 13:27:04 +080069set_gpio USB2_SEL0_A 1
70set_gpio USB2_SEL1_A 1
71set_gpio USB2_SEL0_B 1
72set_gpio USB2_SEL1_B 1
Potin Lai9428ff22022-05-10 12:19:46 +080073set_gpio RST_FRONT_IOEXP_N 1
74set_gpio BSM_FLASH_LATCH_N 1
Howard Chiu0eb09a12021-12-09 13:27:04 +080075
76# set initial duty value for each fan
77set_fan 0 70
78set_fan 1 70
79set_fan 2 70
80set_fan 3 70
81
82exit 0;