#!/bin/sh
#

#logger check_driver called with: $1 - $2 - $3 -

wanted=$1
devpath=$2
bustype=$3

device=$(readlink /sys/$devpath/device)
device=${device##*/}
driver=$(readlink /sys/$devpath/device/driver)
driver=${driver##*/}

logger device $device is bound to the $driver driver

if [ "$driver" != "$wanted" ]; then
    logger must rebind
    echo -n "$device" > /sys/$devpath/device/driver/unbind
    echo -n "$device" > /sys/bus/$bustype/drivers/$wanted/bind
else
    logger no need to rebind
fi

