blob: 8d6f774c84611c02dcf240a3b7a2ad4c2d8d9cd6 [file] [log] [blame]
George Hungb5eef512021-03-10 16:04:46 +08001#!/bin/bash
2# Copyright 2021 Google LLC
3# Copyright 2021 Quanta Computer Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18target_pwm="$1"
19
20if [ -z "$target_pwm" ]; then
21 echo "Target_pwm is not set" >&2
22 exit 1
23fi
24
Patrick Williams8c226232023-04-15 20:05:21 -050025zone_num="$(busctl tree xyz.openbmc_project.State.FanCtrl | grep -c zone)"
George Hungb5eef512021-03-10 16:04:46 +080026result=0
27
Patrick Williams8c226232023-04-15 20:05:21 -050028for (( i = 0; i < zone_num; i++ )); do
George Hungb5eef512021-03-10 16:04:46 +080029 retries=4
30 busctl_error=-1
31
32 while (( retries > 0 )) && (( busctl_error != 0 )); do
33 busctl set-property xyz.openbmc_project.State.FanCtrl /xyz/openbmc_project/settings/fanctrl/zone${i} xyz.openbmc_project.Control.FanSpeed Target t "${target_pwm}"
34 busctl_error=$?
35
36 if (( busctl_error != 0 )); then
37 #Retry setting failsafe. Swampd may be running but zone aren't yet built
38 #so sleep a second to let them be built
39 sleep 1
40 fi
41
Patrick Williams8c226232023-04-15 20:05:21 -050042 (( retries-=1 )) || true
George Hungb5eef512021-03-10 16:04:46 +080043 done
44
45 if (( busctl_error != 0 )); then
46 echo "Failure setting zone${i} fan failsafe to ${target_pwm}" >&2
47 result=$busctl_error
48 else
49 echo "Setting zone${i} fan failsafe to ${target_pwm}"
50 fi
51done
52
53exit $result