blob: 62830bfd0d5ee6bab1a027fbab8e22bd5c9fec2b [file] [log] [blame]
Potin Laifc738002022-05-25 19:42:58 +08001#!/bin/bash
2
3SLED_ID=$1
4SERVICE_NAME="xyz.openbmc_project.Inventory.Manager"
5PRESENT_OBJPATH="/xyz/openbmc_project/inventory/system/chassis/presence/presence_sled${SLED_ID}"
6DBUS_PROPERTY_INTF="org.freedesktop.DBus.Properties"
7
8bind_i2c_driver()
9{
10 I2C_BUS_ADDR=$1
11 DRIVER_NAME=$2
12 DRIVER_DIR="/sys/bus/i2c/drivers/${DRIVER_NAME}"
13 if [ ! -e "${DRIVER_DIR}/${I2C_BUS_ADDR}" ]; then
14 echo "${I2C_BUS_ADDR}" > "${DRIVER_DIR}"/bind
15 fi
16}
17
18unbind_i2c_driver()
19{
20 I2C_BUS_ADDR=$1
21 DRIVER_NAME=$2
22 DRIVER_DIR="/sys/bus/i2c/drivers/${DRIVER_NAME}"
23 if [ -e "${DRIVER_DIR}/${I2C_BUS_ADDR}" ]; then
24 echo "${I2C_BUS_ADDR}" > "${DRIVER_DIR}"/unbind
25 fi
26}
27
28sled_insert_action()
29{
30 SLED_ID=$1
31 I2C_BUS_NUM=$((SLED_ID-1))
32
33 # 0022: fusb302
34 bind_i2c_driver "${I2C_BUS_NUM}-0022" "typec_fusb302"
35
36 # 0045: ina230
37 bind_i2c_driver "${I2C_BUS_NUM}-0045" "ina2xx"
38
39 # 0040: mp5023
40 bind_i2c_driver "${I2C_BUS_NUM}-0040" "mp5023"
41
42 # 0041: pca9536
43 bind_i2c_driver "${I2C_BUS_NUM}-0041" "pca953x"
44
45 # 0076: pca9539
46 bind_i2c_driver "${I2C_BUS_NUM}-0076" "pca953x"
47
48 # 004f: tmp421
49 bind_i2c_driver "${I2C_BUS_NUM}-004f" "tmp421"
50
51 # 0067: pca9552
52 bind_i2c_driver "${I2C_BUS_NUM}-0067" "leds-pca955x"
53
54 # 0054: 24c64
55 bind_i2c_driver "${I2C_BUS_NUM}-0054" "at24"
56}
57
58sled_remove_action()
59{
60 SLED_ID=$1
61 I2C_BUS_NUM=$((SLED_ID-1))
62
63 # 0022: fusb302
64 unbind_i2c_driver "${I2C_BUS_NUM}-0022" "typec_fusb302"
65
66 # # 0045: ina230
67 # unbind_i2c_driver "${I2C_BUS_NUM}-0045" "ina2xx"
68
69 # # 0040: mp5023
70 # unbind_i2c_driver "${I2C_BUS_NUM}-0040" "mp5023"
71
72 # # 0041: pca9536
73 # unbind_i2c_driver "${I2C_BUS_NUM}-0041" "pca953x"
74
75 # # 0076: pca9539
76 # unbind_i2c_driver "${I2C_BUS_NUM}-0076" "pca953x"
77
78 # # 004f: tmp421
79 # unbind_i2c_driver "${I2C_BUS_NUM}-004f" "tmp421"
80
81 # # 0067: pca9552
82 # unbind_i2c_driver "${I2C_BUS_NUM}-0067" "leds-pca955x"
83
84 # # 0054: 24c64
85 # unbind_i2c_driver "${I2C_BUS_NUM}-0054" "at24"
86}
87
88
89dbus-monitor --system "type=signal,interface=${DBUS_PROPERTY_INTF},sender=${SERVICE_NAME},path=${PRESENT_OBJPATH}" |
90while read -r line; do
91 case "$line" in
92 *"boolean false"*)
93 echo "SLED${SLED_ID} Removal"
94 sled_remove_action "$SLED_ID"
95 ;;
96 *"boolean true"*)
97 echo "SLED${SLED_ID} Insertion"
98 sled_insert_action "$SLED_ID"
99 ;;
100 esac
101done
102
103exit 0