181 lines
3.1 KiB
Bash
181 lines
3.1 KiB
Bash
#!/bin/sh
|
|
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
|
|
# Copyright (C) 2026 Amlogic, Inc. All rights reserved
|
|
#
|
|
|
|
WIFI_PATH=/lib/modules/extramodules
|
|
|
|
module=$1
|
|
bus_type=$2
|
|
|
|
## POWER TYPE: POWER_EVENT_DEF '0' POWER_EVENT_RESET '1' POWER_EVENT_EN '2'
|
|
bt_power_path_1="/sys/module/amlogic_wireless/parameters/btpower_evt"
|
|
bt_power_path_2="/sys/module/bt_device/parameters/btpower_evt"
|
|
|
|
set_bt_power_type()
|
|
{
|
|
local power_type=""
|
|
local bt_power_path=""
|
|
|
|
case "$module" in
|
|
w1)
|
|
power_type=2
|
|
;;
|
|
w1u|w2|w2l)
|
|
case "$bus_type" in
|
|
usb)
|
|
power_type=2
|
|
;;
|
|
pcie)
|
|
power_type=1
|
|
;;
|
|
*)
|
|
power_type=0
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
if [ -f "$BT_POWER_PATH_1" ]; then
|
|
bt_power_path="$BT_POWER_PATH_1"
|
|
elif [ -f "$BT_POWER_PATH_2" ]; then
|
|
bt_power_path="$BT_POWER_PATH_2"
|
|
else
|
|
return 0
|
|
fi
|
|
|
|
echo "$power_type" > "$bt_power_path"
|
|
}
|
|
|
|
load_common_modules()
|
|
{
|
|
if [ "$bus_type" != "pcie" ]; then
|
|
if ! /bin/lsmod | grep -q "^aml_wireless"; then
|
|
/sbin/modprobe aml-wireless
|
|
fi
|
|
fi
|
|
|
|
if ! /bin/lsmod | grep -q "^cfg80211"; then
|
|
/sbin/modprobe cfg80211
|
|
fi
|
|
}
|
|
|
|
load_wifi_driver()
|
|
{
|
|
case "$module" in
|
|
w1)
|
|
/sbin/insmod "$WIFI_PATH/aml_sdio.ko"
|
|
/sbin/insmod "$WIFI_PATH/vlsicomm.ko" conf_path=w1
|
|
;;
|
|
w1u)
|
|
/sbin/insmod "$WIFI_PATH/w1u_comm.ko" bus_type="$bus_type"
|
|
/sbin/insmod "$WIFI_PATH/w1u.ko"
|
|
;;
|
|
w2)
|
|
/sbin/insmod "$WIFI_PATH/w2_comm.ko" bus_type="$bus_type"
|
|
/sbin/insmod "$WIFI_PATH/w2.ko"
|
|
;;
|
|
w2l)
|
|
/sbin/insmod "$WIFI_PATH/w2l_comm.ko" bus_type="$bus_type"
|
|
/sbin/insmod "$WIFI_PATH/w2l.ko"
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
|
|
set_bt_power_type
|
|
return 0
|
|
}
|
|
|
|
load_driver()
|
|
{
|
|
load_common_modules
|
|
|
|
if /bin/lsmod | grep -q "^wifi_comm"; then
|
|
/sbin/rmmod wifi_comm
|
|
fi
|
|
|
|
if [ -f /run/udev/wifi_module_name ]; then
|
|
local aml_mod_name
|
|
aml_mod_name=$(cat /run/udev/wifi_module_name)
|
|
|
|
case "$aml_mod_name" in
|
|
aml_w1)
|
|
module="w1"
|
|
bus_type="sdio"
|
|
;;
|
|
aml_w1u|aml_w1u_sdio)
|
|
module="w1u"
|
|
bus_type="sdio"
|
|
;;
|
|
aml_w1u_usb)
|
|
module="w1u"
|
|
bus_type="usb"
|
|
;;
|
|
aml_w2s)
|
|
module="w2"
|
|
bus_type="sdio"
|
|
;;
|
|
aml_w2p)
|
|
module="w2"
|
|
bus_type="pcie"
|
|
;;
|
|
aml_w2u)
|
|
module="w2"
|
|
bus_type="usb"
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
load_wifi_driver
|
|
}
|
|
|
|
|
|
update_module_name()
|
|
{
|
|
echo "$1" > /run/udev/wifi_module_name
|
|
|
|
if [ -e /run/udev/wifi_comm_ready ]; then
|
|
load_driver
|
|
fi
|
|
}
|
|
|
|
wifi_comm_ready()
|
|
{
|
|
echo "1" > /run/udev/wifi_comm_ready
|
|
|
|
if [ -e /run/udev/wifi_module_name ]; then
|
|
load_driver
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
module_name)
|
|
update_module_name "$2"
|
|
;;
|
|
|
|
wifi_common)
|
|
wifi_comm_ready "$2"
|
|
;;
|
|
|
|
w2|w2l|w1|w1u)
|
|
load_driver
|
|
;;
|
|
|
|
*)
|
|
echo "Usage:"
|
|
echo " $0 {w1|w1u|w2|w2l} [bus_type]"
|
|
echo " $0 module_name <aml_module>"
|
|
echo " $0 wifi_common <ready_flag>"
|
|
exit 1
|
|
esac
|
|
exit $?
|
|
|