#!/bin/bash

if test $# -eq 0; then
    echo "Usage: $0 - [--all] [--iax] [--dsa]"
    exit 1
fi

if [[ $@ =~ "--all" ]] || [[ $@ =~ "--dsa" ]]; then
    for d in /sys/bus/dsa/devices/dsa[[:digit:]]*;
    do
	dev=$(basename "${d}")
	for w in ${d}/wq*;
	do
	    wq=$(basename "${w}")
	    if test "$(cat ${w}/state)" = "enabled"; then
		accel-config disable-wq "${dev}/${wq}"
	    fi
	done
	if test "$(cat ${d}/state)" = "enabled"; then
	    accel-config disable-device "${dev}"		
	fi
    done
fi

if [[ $@ =~ "--all" ]] || [[ $@ =~ "--iax" ]]; then
    for d in /sys/bus/dsa/devices/iax[[:digit:]]*;
    do
	dev=$(basename "${d}")
	for w in ${d}/wq*;
	do
	    wq=$(basename "${w}")
	    if test "$(cat ${w}/state)" = "enabled"; then
		accel-config disable-wq "${dev}/${wq}"
	    fi
	done
	if test "$(cat ${d}/state)" = "enabled"; then
	    accel-config disable-device "${dev}"		
	fi
    done
fi
