#!/bin/bash
#
# Copyright (C) 2018 Purism SPC
#
# SPDX-License-Identifier: GPL-3.0+
#

rsi_path=/lib/modules/$(uname -r)/kernel/drivers/net/wireless/rsi

mv ${rsi_path}/rsi_91x.ko ${rsi_path}/rsi_91x.ko.bak
mv ${rsi_path}/rsi_sdio.ko ${rsi_path}/rsi_sdio.ko.bak
mv ${rsi_path}/rsi_usb.ko ${rsi_path}/rsi_usb.ko.bak

rmmod rsi_sdio rsi_usb rsi_91x

tar -xf /usr/src/rsi_upgrade.tar.gz -C ${rsi_path}
mkdir -p /lib/firmware
tar -xf /usr/src/rsi_firmware.tar.gz -C /lib/firmware

modprobe rsi_91x dev_oper_mode=13 rsi_zone_enabled=1
modprobe rsi_sdio

mv ${rsi_path}/rsi_91x.ko.bak ${rsi_path}/rsi_91x.ko
mv ${rsi_path}/rsi_sdio.ko.bak ${rsi_path}/rsi_sdio.ko
mv ${rsi_path}/rsi_usb.ko.bak ${rsi_path}/rsi_usb.ko

rmmod rsi_sdio rsi_usb rsi_91x
modprobe rsi_91x dev_oper_mode=13 rsi_zone_enabled=1
modprobe rsi_sdio

