#!/bin/sh
# Enabling or disabling autosuspend

# find a port we know exists, for example the nm port
nm_port=`hal-find-by-capability --capability mbm_nm`

if [ "$nm_port" = "" ]; then
	echo "$0: Didn't find any MBM modules to handle"
	exit 0
fi

# find its parent
nm_parent=`hal-device $nm_port | grep parent | cut -d\' -f2`

# now, the nm_parent parent is the root of the hal info block for MBM module
root_uid=`hal-device $nm_parent | grep parent | cut -d\' -f2`

# get the path to MBM module sysfs location
sysfs_path=`hal-device $root_uid | grep usb_device.linux.sysfs_path | cut -d\' -f2`

if [ -f /etc/f3507g.conf -a "$1" = "use" ]; then
	. /etc/f3507g.conf
	if [ "$USE_AUTOSUSPEND" = "1" ]; then
		AUTO=1
	fi
fi

if [ "$1" = "" ]; then
	autosuspend=`cat $sysfs_path/power/autosuspend`
	echo "$0: pm autosuspend $autosuspend"

	level=`cat $sysfs_path/power/level`
	echo "$0: pm level $level"

	wakeup=`cat $sysfs_path/power/wakeup`
	echo "$0: pm wakeup $wakeup"

elif [ "$1" = "on" -o "$AUTO" = "1" ]; then
	level=`cat $sysfs_path/power/level`
	echo auto > $sysfs_path/power/level 

elif [ "$1" = "off" ]; then
	echo on > $sysfs_path/power/level 

elif [ "$1" != "use" ]; then
	echo "$0: Parameters: on or off"

fi

