blob: caceb5f788c6a774de1d1ff3052b25361130b3b1 [file] [log] [blame]
Tim Leef7fc57b2020-06-18 09:28:26 +08001#!/bin/bash
2
3string=''
4pmbus_read() {
Patrick Williams8c226232023-04-15 20:05:21 -05005 data=$(i2cget -f -y "$1" "$2" "$3" i "$4")
Tim Leef7fc57b2020-06-18 09:28:26 +08006
7 if [[ -z "$data" ]]; then
8 echo "i2c$1 device $2 command $3 error" >&2
9 exit 1
10 fi
11
Patrick Williams8c226232023-04-15 20:05:21 -050012 arry=$(echo "${data}" | sed -e "s/$4\: //" | sed -e "s/\0x00//g" | sed -e "s/\0xff//g" | sed -e "s/\0x7f//g" | sed -e "s/\0x0f//g" | sed -e "s/\0x14//g")
Tim Leef7fc57b2020-06-18 09:28:26 +080013
14 string=''
15 for d in ${arry}
16 do
Patrick Williams8c226232023-04-15 20:05:21 -050017 hex=${d/0x}
Tim Leef7fc57b2020-06-18 09:28:26 +080018 string+=$(echo -e "\x${hex}");
19 done
20}
21
22update_inventory() {
23 INVENTORY_SERVICE='xyz.openbmc_project.Inventory.Manager'
24 INVENTORY_OBJECT='/xyz/openbmc_project/inventory'
25 INVENTORY_PATH='xyz.openbmc_project.Inventory.Manager'
26 OBJECT_PATH="/system/chassis/motherboard/powersupply$1"
27 busctl call \
28 ${INVENTORY_SERVICE} \
29 ${INVENTORY_OBJECT} \
30 ${INVENTORY_PATH} \
Patrick Williams8c226232023-04-15 20:05:21 -050031 Notify "a{oa{sa{sv}}}" 1 \
32 "${OBJECT_PATH}" 1 "$2" "$3" \
33 "$4" "$5" "$6"
Tim Leef7fc57b2020-06-18 09:28:26 +080034}
35
36if [ $# -eq 0 ]; then
37 echo 'No PSU device is given' >&2
38 exit 1
39fi
40
Patrick Williams8c226232023-04-15 20:05:21 -050041IFS=" " read -ra arr <<< "${1//- /}"
Tim Leef7fc57b2020-06-18 09:28:26 +080042
Patrick Williams8c226232023-04-15 20:05:21 -050043pmbus_read "${arr[1]}" "${arr[2]}" 0x99 11
44update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "Manufacturer" "s" "$string"
Tim Leef7fc57b2020-06-18 09:28:26 +080045
Patrick Williams8c226232023-04-15 20:05:21 -050046pmbus_read "${arr[1]}" "${arr[2]}" 0x9a 11
47update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "Model" "s" "$string"
Tim Leef7fc57b2020-06-18 09:28:26 +080048
Patrick Williams8c226232023-04-15 20:05:21 -050049pmbus_read "${arr[1]}" "${arr[2]}" 0xad 21
50update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "PartNumber" "s" "$string"
Tim Leef7fc57b2020-06-18 09:28:26 +080051
Patrick Williams8c226232023-04-15 20:05:21 -050052pmbus_read "${arr[1]}" "${arr[2]}" 0x9e 18
53update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Decorator.Asset" 1 "SerialNumber" "s" "$string"
Tim Leef7fc57b2020-06-18 09:28:26 +080054
Patrick Williams8c226232023-04-15 20:05:21 -050055update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Decorator.Cacheable" 1 "Cached" "b" "true"
56update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Decorator.Replaceable" 1 "FieldReplaceable" "b" "true"
57update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Item" 1 "Present" "b" "true"
58update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Item" 1 "PrettyName" "s" "powersupply${arr[0]}"
59update_inventory "${arr[0]}" "xyz.openbmc_project.Inventory.Item.PowerSupply" 0