xref: /openbmc/phosphor-hwmon/msl/max31785-msl (revision 7b5873779dda5b525e74e18fe582808053e6b7b4)
1*7b587377SBrad Bishop#!/bin/sh
2*7b587377SBrad Bishop#
3*7b587377SBrad Bishop# Copyright © 2017 IBM Corporation
4*7b587377SBrad Bishop#
5*7b587377SBrad Bishop# Licensed under the Apache License, Version 2.0 (the "License");
6*7b587377SBrad Bishop# you may not use this file except in compliance with the License.
7*7b587377SBrad Bishop# You may obtain a copy of the License at
8*7b587377SBrad Bishop#
9*7b587377SBrad Bishop#     http://www.apache.org/licenses/LICENSE-2.0
10*7b587377SBrad Bishop#
11*7b587377SBrad Bishop# Unless required by applicable law or agreed to in writing, software
12*7b587377SBrad Bishop# distributed under the License is distributed on an "AS IS" BASIS,
13*7b587377SBrad Bishop# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*7b587377SBrad Bishop# See the License for the specific language governing permissions and
15*7b587377SBrad Bishop# limitations under the License.
16*7b587377SBrad Bishop#
17*7b587377SBrad Bishop
18*7b587377SBrad Bishop# Check a max31785 firmware revision and set the MSL property
19*7b587377SBrad Bishop# on the specified inventory items.
20*7b587377SBrad Bishop
21*7b587377SBrad Bishopset -e
22*7b587377SBrad Bishop
23*7b587377SBrad Bishopmain()
24*7b587377SBrad Bishop{
25*7b587377SBrad Bishop    usage="Usage: $(basename $0) -p PATH... -b BUS_NUMBER -r REVISION"
26*7b587377SBrad Bishop    while getopts p:b:r:h key; do
27*7b587377SBrad Bishop        case $key in
28*7b587377SBrad Bishop            p)
29*7b587377SBrad Bishop                paths=$OPTARG
30*7b587377SBrad Bishop                ;;
31*7b587377SBrad Bishop            b)
32*7b587377SBrad Bishop                bus=$OPTARG
33*7b587377SBrad Bishop                ;;
34*7b587377SBrad Bishop            r)
35*7b587377SBrad Bishop                revision=$OPTARG
36*7b587377SBrad Bishop                ;;
37*7b587377SBrad Bishop            h)
38*7b587377SBrad Bishop                echo "$usage" >&2
39*7b587377SBrad Bishop                exit
40*7b587377SBrad Bishop                ;;
41*7b587377SBrad Bishop            \?)
42*7b587377SBrad Bishop                echo -e \\n"Unrecognized option"
43*7b587377SBrad Bishop                echo "$usage" >&2
44*7b587377SBrad Bishop                exit 1
45*7b587377SBrad Bishop                ;;
46*7b587377SBrad Bishop        esac
47*7b587377SBrad Bishop    done
48*7b587377SBrad Bishop
49*7b587377SBrad Bishop    if [ -z "$paths" ] || [ -z "$bus" ] || [ -z "$revision" ]; then
50*7b587377SBrad Bishop        echo "Missing option" >&2
51*7b587377SBrad Bishop        echo "$usage" >&2
52*7b587377SBrad Bishop        exit 1
53*7b587377SBrad Bishop    fi
54*7b587377SBrad Bishop
55*7b587377SBrad Bishop    local state="false"
56*7b587377SBrad Bishop    local actual
57*7b587377SBrad Bishop    local dbus
58*7b587377SBrad Bishop
59*7b587377SBrad Bishop    dbus=$(mapper get-service /xyz/openbmc_project/inventory)
60*7b587377SBrad Bishop    actual=$(i2cget -f -y $bus 0x52 0x9b w)
61*7b587377SBrad Bishop
62*7b587377SBrad Bishop    if (( actual >= revision )); then
63*7b587377SBrad Bishop        state="true"
64*7b587377SBrad Bishop    fi
65*7b587377SBrad Bishop
66*7b587377SBrad Bishop    for path in $paths; do
67*7b587377SBrad Bishop        busctl call $dbus /xyz/openbmc_project/inventory \
68*7b587377SBrad Bishop            xyz.openbmc_project.Inventory.Manager Notify 'a{oa{sa{sv}}}' 1 \
69*7b587377SBrad Bishop            $path 1 \
70*7b587377SBrad Bishop            xyz.openbmc_project.Inventory.Decorator.MeetsMinimumShipLevel \
71*7b587377SBrad Bishop            1 MeetsMinimumShipLevel b $state
72*7b587377SBrad Bishop    done
73*7b587377SBrad Bishop}
74*7b587377SBrad Bishop
75*7b587377SBrad Bishopmain "$@"
76