xref: /openbmc/openbmc/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/device-util (revision 44a5ddc0de5927322fa83c5e8c9ab830c903b258)
1#!/bin/bash
2
3SYSFS_I2C_ROOT="/sys/bus/i2c"
4SYSFS_I2C_DEVICES="${SYSFS_I2C_ROOT}/devices"
5SYSFS_I2C_DRIVERS="${SYSFS_I2C_ROOT}/drivers"
6
7i2c_bind_driver() {
8
9  driver_name="$1"
10  i2c_device="$2"
11  driver_dir="${SYSFS_I2C_DRIVERS}/${driver_name}"
12
13  if [ -n "$3" ]; then
14    retries="$3"
15  else
16    retries=1
17  fi
18
19  if [ ! -d "${driver_dir}" ]; then
20    echo "unable to locate i2c driver ${driver_name} in sysfs"
21    return 1
22  fi
23
24  retry=0
25  while [ "$retry" -lt "$retries" ]; do
26    if echo "${i2c_device}" > "${driver_dir}/bind"; then
27      return 0
28    fi
29
30    usleep 50000  # sleep for 50 milliseconds
31    retry=$((retry + 1))
32  done
33
34  return 1
35}
36
37rebind_i2c_dev() {
38  dev="$1-00$2"
39  dri=$3
40
41  if [ ! -L "${SYSFS_I2C_DEVICES}/$dev/driver" ]; then
42    if i2c_bind_driver "$dri" "$dev" >/dev/null; then
43      echo "rebind $dev to driver $dri successfully"
44    else
45      echo "rebind $dev to driver $dri fail"
46    fi
47
48  fi
49}
50
51mb_power_lose_reprobe() {
52  # Mux
53  echo "Bind Mux..."
54  rebind_i2c_dev  3 70 "pca954x"
55  rebind_i2c_dev  6 70 "pca954x"
56  rebind_i2c_dev 13 70 "pca954x"
57
58  echo "Bind Fru..."
59  rebind_i2c_dev  1 50 "at24"
60  rebind_i2c_dev  4 52 "at24"
61  rebind_i2c_dev  9 52 "at24"
62  rebind_i2c_dev 11 52 "at24"
63  rebind_i2c_dev 15 50 "at24"
64  rebind_i2c_dev 15 56 "at24"
65  rebind_i2c_dev 29 54 "at24"
66
67  # Sensors
68  echo "Bind MB Sensors..."
69
70  # MB_E1S
71  rebind_i2c_dev 22 45 ina2xx
72  rebind_i2c_dev 23 45 ina2xx
73
74  # MB VR_CPU_VCORE0_SOC, VR_CPU_VCORE1_SOC, VR_CPU_PVDD11
75  # (isl69260/xdpe152c)
76  rebind_i2c_dev 28 61 isl68137
77  rebind_i2c_dev 28 62 isl68137
78  rebind_i2c_dev 28 63 isl68137
79  rebind_i2c_dev 28 64 xdpe152c4
80  rebind_i2c_dev 28 66 xdpe152c4
81  rebind_i2c_dev 28 68 xdpe152c4
82  # MB_RETIMER_TEMP_C
83  rebind_i2c_dev 12 24 pt5161l
84  rebind_i2c_dev 21 24 pt5161l
85
86  # MB SBRMI, SBTSI, CPU & DIMM
87  rebind_i2c_dev  7 3c sbrmi
88  rebind_i2c_dev  7 4c sbrti
89
90  # MB Voltage Monitor
91  rebind_i2c_dev 29 1d adc128d818
92  rebind_i2c_dev 29 1f adc128d818
93}
94