Skip to content

Commit

Permalink
wlanpi-model lists Bluetooth and showds PCI device ID, Config M4+ at …
Browse files Browse the repository at this point in the history
…boot
  • Loading branch information
jiribrejcha authored Feb 19, 2024
1 parent bbd7e08 commit 0893ff8
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
wlanpi-common (1.1.8) unstable; urgency=medium

* Configure WLAN Pi M4+ features at boot - enable OTG, disable overlay, etc
* wlanpi-model now lists Bluetooth adapters and PCI device IDs of Wi-Fi adapters

-- Jiri Brejcha <[email protected]> Mon, 19 Feb 2024 10:53:00 +0100

wlanpi-common (1.1.7-3) unstable; urgency=medium

* wlan-model now detects WLAN Pi M4+
Expand Down
92 changes: 91 additions & 1 deletion opt/wlanpi-common/wlanpi-config-at-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fi

########## M4 ##########

# Apply Mcuzone platform specific settings
# Apply M4 platform specific settings
if [[ "$MODEL" == "Mcuzone" ]]; then
echo "Applying Mcuzone settings"

Expand Down Expand Up @@ -199,6 +199,95 @@ if [[ "$MODEL" == "Mcuzone" ]]; then

fi

########## M4+ ##########

# Apply M4+ platform specific settings
if [[ "$MODEL" == "Mcuzone M4+" ]]; then
echo "Applying M4+ settings"

# Enable Waveshare display
if [ ! -f "$WAVESHARE_FILE" ]; then
debugger "Creating Waveshare file to enable display and buttons"
touch "$WAVESHARE_FILE"
systemctl restart wlanpi-fpms.service
else
debugger "Waveshare file already exists, no action needed"
fi

# If WLAN Pi Pro fan controller is enabled, disable the controller
if grep -q -E "^\s*dtoverlay=gpio-fan,gpiopin=26" /boot/config.txt; then
debugger "Fan controller is enabled, disabling it now"
sed -i "s/^\s*dtoverlay=gpio-fan,gpiopin=26/#dtoverlay=gpio-fan,gpiopin=26/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "Fan controller is already disabled, no action needed"
fi

# Enable OTG by setting USB 2.0 controller OTG mode to 0
if grep -q -E "^\s*otg_mode=1" /boot/config.txt; then
debugger "otg_mode is currently set to 1, comment the line out"
sed -i "s/^\s*otg_mode=1/#otg_mode=1/" /boot/config.txt
REQUIRES_REBOOT=1
fi

# Set USB ports to otg mode
CM4_LINE_NUMBER=$(grep -n "\[cm4\]" /boot/config.txt | cut -d ":" -f1)
LINES_BELOW_CM4=$(sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -n "dtoverlay=dwc2,dr_mode=host" | cut -d ":" -f1)
if [[ $CM4_LINE_NUMBER -gt 0 ]] && [[ $LINES_BELOW_CM4 -gt 0 ]]; then
DR_MODE_LINE_NUMBER=$(($CM4_LINE_NUMBER + $LINES_BELOW_CM4 - 1))
debugger "Found \"dtoverlay=dwc2,dr_mode=host\" CM4 config on line $DR_MODE_LINE_NUMBER"
debugger "Setting CM4 USB to otg mode"
sed -i "${DR_MODE_LINE_NUMBER}s/.*/dtoverlay=dwc2,dr_mode=otg/" /boot/config.txt
REQUIRES_REBOOT=1
elif ! sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -q "^\s*dtoverlay=dwc2,dr_mode=otg"; then
debugger "USB mode setting not found in config file, creating a new line in CM4 section"
sed -i "s/\[cm4\]/&\ndtoverlay=dwc2,dr_mode=otg\n/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "USB mode is already set to otg mode, no action needed"
fi

# Enable pcie-32bit-dma overlay for MediaTek Wi-Fi 6E MT7921K and MT7922A adapters to work
if lspci -nn | grep -q -E "14c3:0608|14c3:0616"; then
if ! sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -q "^\s*dtoverlay=pcie-32bit-dma"; then
debugger "pcie-32bit-dma overlay not enabled in cm4 config section, enabling it now"
if sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -q "^\s*#dtoverlay=pcie-32bit-dma"; then
sed -i "s/^\s*#dtoverlay=pcie-32bit-dma/dtoverlay=pcie-32bit-dma/" /boot/config.txt
else
sed -i "s/\[cm4\]/&\n# Allows MT7921K adapter to work with 64-bit kernel\ndtoverlay=pcie-32bit-dma\n/" /boot/config.txt
fi
REQUIRES_REBOOT=1
else
debugger "pcie-32bit-dma overlay is already enabled, no action needed"
fi
else
if sed -n '/\[cm4\]/,/\[*\]/p' /boot/config.txt | grep -q "^\s*dtoverlay=pcie-32bit-dma"; then
debugger "pcie-32bit-dma is enabled but non-MediaTek M.2 adapter is used, disabling 32-bit DMA overlay now"
sed -i "s/^\s*dtoverlay=pcie-32bit-dma/#dtoverlay=pcie-32bit-dma/" /boot/config.txt
REQUIRES_REBOOT=1
fi
fi

# Disable RTC
if grep -q -E "^\s*dtoverlay=i2c-rtc,pcf85063a,addr=0x51" /boot/config.txt; then
debugger "RTC is enabled, disabling it now"
sed -i "s/^\s*dtoverlay=i2c-rtc,pcf85063a,addr=0x51/#dtoverlay=i2c-rtc,pcf85063a,addr=0x51/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "RTC is already disabled, no action needed"
fi

# Disable battery gauge
if grep -q -E "^\s*dtoverlay=battery_gauge" /boot/config.txt; then
debugger "Battery gauge is enabled, disabling it now"
sed -i "s/^\s*dtoverlay=battery_gauge/#dtoverlay=battery_gauge/" /boot/config.txt
REQUIRES_REBOOT=1
else
debugger "Battery gauge is already disabled, no action needed"
fi

fi

########## Pro ##########

# Apply WLAN Pi Pro platform specific settings
Expand Down Expand Up @@ -244,6 +333,7 @@ if [[ "$MODEL" == "WLAN Pi Pro" ]]; then
debugger "USB mode is already set to otg mode, no action needed"
fi
fi

# Reboot if required
if [ "$REQUIRES_REBOOT" -gt 0 ]; then
echo "Reboot required, rebooting now"
Expand Down
13 changes: 11 additions & 2 deletions opt/wlanpi-common/wlanpi-model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ else
fi
fi

# List installed Wi-Fi adapters
# List installed adapters
USB_WIFI_ADAPTER=$(lsusb | grep -i -E "Wireless|Wi-Fi|Wi_Fi|WiFi" | grep -v -e "0608" | cut -d " " -f 6-)
M2_WIFI_ADAPTER=$(lspci | grep -i -E "Wireless|Wi-Fi|Wi_Fi|WiFi" | cut -d ":" -f 3- | cut -c 2-)
M2_WIFI_ADAPTER=$(lspci -nn | grep -i -E "Wireless|Wi-Fi|Wi_Fi|WiFi" | cut -d ":" -f 3- | cut -c 2-)
BLUETOOTH_ADAPTER=$(lsusb | grep -i "Bluetooth" | cut -d " " -f 6-)

IFS="
"
Expand All @@ -160,3 +161,11 @@ fi
if [ -z "$USB_WIFI_ADAPTER" ] && [ -z "$M2_WIFI_ADAPTER" ] && [ "$BRIEF_OUTPUT" -eq 0 ]; then
echo "No Wi-Fi adapter"
fi

if [ -n "$BLUETOOTH_ADAPTER" ] && [ "$BRIEF_OUTPUT" -eq 0 ]; then
debugger "Found Bluetooth adapter"
for item in $BLUETOOTH_ADAPTER
do
echo "Bluetooth adapter: $item"
done
fi

0 comments on commit 0893ff8

Please sign in to comment.