#!/bin/sh
# set -x

# Get lsb functions
. /lib/lsb/init-functions
alias log_begin_msg="/etc/redhat-lsb/lsb_log_message"
alias log_end_msg="/etc/redhat-lsb/lsb_log_message"

SDADDR="06:01.3"
# SDADDR="06:01"

case "$1" in

start)
        log_begin_msg "Configuring card reader"
        # modprobe fakephp || return 1
		# setpci -s 06:01.3 4c=0x22
        # setpci -s $SDADDR 86.b=90
        # setpci -s $SDADDR 4c.b=02 # FlashMedia SD disable
        # setpci -s $SDADDR 04.b=06 # SDHCI Mem+ BusMaster+
        # setpci -s $SDADDR 88.b=01 # SDHCI DMA enable
		modprobe mmc_core || return 1
		modprobe tifm_sd || return 1
		modprobe sdhci || return 1
		modprobe mmc_block  || return 1
		;;


stop)
        log_begin_msg "Shutting down card reader"
		modprobe -r mmc_block  
		modprobe -r sdhci 
		modprobe -r tifm_sd 
		modprobe -r mmc_core 
        lsmod | grep -q sdhci && return 1
        # setpci -s $SDADDR 88.b=00 # SDHCI DMA disable
        # setpci -s $SDADDR 04.b=07 # SDHCI Mem- BusMaster-
        # setpci -s $SDADDR 4c.b=20 # FlashMedia SD enable
        # setpci -s $SDADDR 86.b=d0
        # modprobe -r fakephp
        log_end_msg $?
	;;


*)
    log_success_msg "Usage: /etc/init.d/sdhci start|stop"
    exit 1
    ;;
esac

exit 0

