xref: /openbmc/phosphor-hwmon/msl/max31785-msl (revision c4f67be6a674dc2cc8f1236ef468055fe1bf2e8f)
1bc58decdSAnton D. Kachalov#!/bin/bash
27b587377SBrad Bishop#
37b587377SBrad Bishop# Copyright © 2017 IBM Corporation
47b587377SBrad Bishop#
57b587377SBrad Bishop# Licensed under the Apache License, Version 2.0 (the "License");
67b587377SBrad Bishop# you may not use this file except in compliance with the License.
77b587377SBrad Bishop# You may obtain a copy of the License at
87b587377SBrad Bishop#
97b587377SBrad Bishop#     http://www.apache.org/licenses/LICENSE-2.0
107b587377SBrad Bishop#
117b587377SBrad Bishop# Unless required by applicable law or agreed to in writing, software
127b587377SBrad Bishop# distributed under the License is distributed on an "AS IS" BASIS,
137b587377SBrad Bishop# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
147b587377SBrad Bishop# See the License for the specific language governing permissions and
157b587377SBrad Bishop# limitations under the License.
167b587377SBrad Bishop#
177b587377SBrad Bishop
187b587377SBrad Bishop# Check a max31785 firmware revision and set the MSL property
197b587377SBrad Bishop# on the specified inventory items.
207b587377SBrad Bishop
217b587377SBrad Bishopset -e
227b587377SBrad Bishop
23*c4f67be6SPatrick Williamsfunction main()
247b587377SBrad Bishop{
25bc58decdSAnton D. Kachalov    usage="Usage: $(basename "$0") -p PATH... -b BUS_NUMBER -r REVISION"
267b587377SBrad Bishop    while getopts p:b:r:h key; do
277b587377SBrad Bishop        case $key in
287b587377SBrad Bishop            p)
297b587377SBrad Bishop                paths=$OPTARG
307b587377SBrad Bishop                ;;
317b587377SBrad Bishop            b)
327b587377SBrad Bishop                bus=$OPTARG
337b587377SBrad Bishop                ;;
347b587377SBrad Bishop            r)
357b587377SBrad Bishop                revision=$OPTARG
367b587377SBrad Bishop                ;;
377b587377SBrad Bishop            h)
387b587377SBrad Bishop                echo "$usage" >&2
397b587377SBrad Bishop                exit
407b587377SBrad Bishop                ;;
417b587377SBrad Bishop            \?)
42bc58decdSAnton D. Kachalov                printf "\nUnrecognized option\n"
437b587377SBrad Bishop                echo "$usage" >&2
447b587377SBrad Bishop                exit 1
457b587377SBrad Bishop                ;;
467b587377SBrad Bishop        esac
477b587377SBrad Bishop    done
487b587377SBrad Bishop
497b587377SBrad Bishop    if [ -z "$paths" ] || [ -z "$bus" ] || [ -z "$revision" ]; then
507b587377SBrad Bishop        echo "Missing option" >&2
517b587377SBrad Bishop        echo "$usage" >&2
527b587377SBrad Bishop        exit 1
537b587377SBrad Bishop    fi
547b587377SBrad Bishop
557b587377SBrad Bishop    local state="false"
567b587377SBrad Bishop    local actual
577b587377SBrad Bishop    local dbus
587b587377SBrad Bishop
597b587377SBrad Bishop    dbus=$(mapper get-service /xyz/openbmc_project/inventory)
60bc58decdSAnton D. Kachalov    actual=$(i2cget -f -y "$bus" 0x52 0x9b w)
617b587377SBrad Bishop
627b587377SBrad Bishop    if (( actual >= revision )); then
637b587377SBrad Bishop        state="true"
647b587377SBrad Bishop    fi
657b587377SBrad Bishop
667b587377SBrad Bishop    for path in $paths; do
67bc58decdSAnton D. Kachalov        busctl call "$dbus" /xyz/openbmc_project/inventory \
687b587377SBrad Bishop            xyz.openbmc_project.Inventory.Manager Notify 'a{oa{sa{sv}}}' 1 \
69bc58decdSAnton D. Kachalov            "$path" 1 \
707b587377SBrad Bishop            xyz.openbmc_project.Inventory.Decorator.MeetsMinimumShipLevel \
71bc58decdSAnton D. Kachalov            1 MeetsMinimumShipLevel b "$state"
727b587377SBrad Bishop    done
737b587377SBrad Bishop}
747b587377SBrad Bishop
757b587377SBrad Bishopmain "$@"
76