From 8fcc712c76dcb65609fd31226fed85d7298ddd02 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 28 Sep 2022 21:31:52 +0200 Subject: [PATCH] Kobo: Clara 2E fixes (#9559) * Handle the power button input device * Handle the charging LED properly * Handle the new Wi-Fi chip properly * Handle frontlight warmth adjustments * Handle the battery gauge properly * Bump base (a lot of third-party updates) [https://github.com/koreader/koreader-base/pull/1523] * Bump android-luajit-launcher to match the LuaJIT update [https://github.com/koreader/android-luajit-launcher/pull/386] Fix #9552 (many thanks to @Bartvelp for bearing with my stupid tests ;)). --- base | 2 +- frontend/device/kobo/device.lua | 12 ++-- platform/android/luajit-launcher | 2 +- platform/kobo/disable-wifi.sh | 52 ++++++++++----- platform/kobo/enable-wifi.sh | 107 +++++++++++++++++++++++++------ platform/kobo/koreader.sh | 5 ++ platform/kobo/nickel.sh | 40 +++++++++--- 7 files changed, 170 insertions(+), 50 deletions(-) diff --git a/base b/base index 2ed9aba5d..9e4e7e899 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 2ed9aba5de31e5e60f18bf451df735fe91ddde3a +Subproject commit 9e4e7e899e06853305d0a2e4b1f103d2a0840068 diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 99a54d0da..44f4fd88d 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -364,6 +364,7 @@ local KoboEuropa = Kobo:new{ isSunxi = yes, hasEclipseWfm = yes, canToggleChargingLED = yes, + led_uses_channel_3 = true, hasFrontlight = yes, hasGSensor = yes, canToggleGSensor = yes, @@ -383,6 +384,7 @@ local KoboCadmus = Kobo:new{ isSunxi = yes, hasEclipseWfm = yes, canToggleChargingLED = yes, + led_uses_channel_3 = true, hasFrontlight = yes, hasKeys = yes, hasGSensor = yes, @@ -447,17 +449,19 @@ local KoboGoldfinch = Kobo:new{ isMk7 = yes, hasEclipseWfm = yes, canToggleChargingLED = yes, + led_uses_channel_3 = true, hasFrontlight = yes, display_dpi = 300, - --- @fixme: to be confirmed! hasNaturalLight = yes, frontlight_settings = { frontlight_white = "/sys/class/backlight/mxc_msp430.0/brightness", - frontlight_mixer = "/sys/class/backlight/lm3630a_led/color", + frontlight_mixer = "/sys/class/leds/aw99703-bl_FL1/color", nl_min = 0, nl_max = 10, nl_inverted = true, }, + battery_sysfs = "/sys/class/power_supply/battery", + power_dev = "/dev/input/by-path/platform-bd71828-pwrkey-event", } function Kobo:setupChargingLED() @@ -1155,13 +1159,13 @@ function Kobo:toggleChargingLED(toggle) return false end - -- c.f., strace -fittvyy -e trace=ioctl,file,signal,ipc,desc -s 256 -o /tmp/nickel.log -p $(pidof -s nickel) & + -- c.f., strace -fittTvyy -e trace=ioctl,file,signal,ipc,desc -s 256 -o /tmp/nickel.log -p $(pidof -s nickel) & -- This was observed on a Forma, so I'm mildly hopeful that it's safe on other Mk. 7 devices ;). -- NOTE: ch stands for channel, cur for current, dc for duty cycle. c.f., the driver source. if toggle == true then -- NOTE: Technically, Nickel forces a toggle off before that, too. -- But since we do that on startup, it shouldn't be necessary here... - if self:isSunxi() then + if self.led_uses_channel_3 then f:write("ch 3") f:flush() f:write("cur 1") diff --git a/platform/android/luajit-launcher b/platform/android/luajit-launcher index ee4cca8b8..76ba54461 160000 --- a/platform/android/luajit-launcher +++ b/platform/android/luajit-launcher @@ -1 +1 @@ -Subproject commit ee4cca8b81b4bd9cf3a299edb920d41cbfcd5a5a +Subproject commit 76ba5446108112a81de38b2aad9a271440eace2c diff --git a/platform/kobo/disable-wifi.sh b/platform/kobo/disable-wifi.sh index df3dcad37..30a23d087 100755 --- a/platform/kobo/disable-wifi.sh +++ b/platform/kobo/disable-wifi.sh @@ -33,7 +33,7 @@ else rm -f "/tmp/resolv.ko" fi -wpa_cli terminate +wpa_cli -i "${INTERFACE}" terminate [ "${WIFI_MODULE}" = "dhd" ] && wlarm_le -i "${INTERFACE}" down ifconfig "${INTERFACE}" down @@ -44,23 +44,45 @@ if grep -q "^${WIFI_MODULE}" "/proc/modules"; then usleep 250000 rmmod "${WIFI_MODULE}" fi -if grep -q "^sdio_wifi_pwr" "/proc/modules"; then - # Handle the shitty DVFS switcheroo... - if [ -n "${CPUFREQ_DVFS}" ]; then - echo "0" >"/sys/devices/platform/mxc_dvfs_core.0/enable" - if [ -n "${CPUFREQ_CONSERVATIVE}" ]; then - echo "conservative" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" - else - echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" - cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" - fi + +# Handle dependencies, if any +WIFI_DEP_MOD="" +SKIP_SDIO_PWR_MODULE="" +case "${WIFI_MODULE}" in + "moal") + WIFI_DEP_MOD="mlan" + SKIP_SDIO_PWR_MODULE="1" + ;; +esac +if [ -n "${WIFI_DEP_MOD}" ]; then + if grep -q "^${WIFI_DEP_MOD}" "/proc/modules"; then + usleep 250000 + rmmod "${WIFI_DEP_MOD}" fi - usleep 250000 - rmmod sdio_wifi_pwr fi -# Poke the kernel via ioctl on platforms without the dedicated power module... -if [ ! -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then +if [ -n "${SKIP_SDIO_PWR_MODULE}" ]; then usleep 250000 ./luajit frontend/device/kobo/ntx_io.lua 208 0 +else + if grep -q "^sdio_wifi_pwr" "/proc/modules"; then + # Handle the shitty DVFS switcheroo... + if [ -n "${CPUFREQ_DVFS}" ]; then + echo "0" >"/sys/devices/platform/mxc_dvfs_core.0/enable" + if [ -n "${CPUFREQ_CONSERVATIVE}" ]; then + echo "conservative" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" + else + echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" + cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" + fi + fi + usleep 250000 + rmmod sdio_wifi_pwr + fi + + # Poke the kernel via ioctl on platforms without the dedicated power module... + if [ ! -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then + usleep 250000 + ./luajit frontend/device/kobo/ntx_io.lua 208 0 + fi fi diff --git a/platform/kobo/enable-wifi.sh b/platform/kobo/enable-wifi.sh index 7cd8e112d..4b854b859 100755 --- a/platform/kobo/enable-wifi.sh +++ b/platform/kobo/enable-wifi.sh @@ -13,24 +13,42 @@ for fd in /proc/"$$"/fd/*; do fi done -# Load wifi modules and enable wifi. -if ! grep -q "^sdio_wifi_pwr" "/proc/modules"; then - if [ -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then - # Handle the shitty DVFS switcheroo... - if [ -n "${CPUFREQ_DVFS}" ]; then - echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" - echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable" - fi +# Some platforms do *NOT* use sdio_wifi_pwr, even when it is physically there... +SKIP_SDIO_PWR_MODULE="" +# We also want to choose the wpa_supplicant driver depending on the module... +WPA_SUPPLICANT_DRIVER="wext" +case "${WIFI_MODULE}" in + "moal") + SKIP_SDIO_PWR_MODULE="1" + WPA_SUPPLICANT_DRIVER="nl80211" + ;; +esac + +# Power up WiFi chip +if [ -n "${SKIP_SDIO_PWR_MODULE}" ]; then + # 208 is CM_WIFI_CTRL + ./luajit frontend/device/kobo/ntx_io.lua 208 1 +else + if ! grep -q "^sdio_wifi_pwr" "/proc/modules"; then + if [ -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then + # Handle the shitty DVFS switcheroo... + if [ -n "${CPUFREQ_DVFS}" ]; then + echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" + echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable" + fi - insmod "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" - else - # Poke the kernel via ioctl on platforms without the dedicated power module... - # 208 is CM_WIFI_CTRL - ./luajit frontend/device/kobo/ntx_io.lua 208 1 + insmod "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" + else + # Poke the kernel via ioctl on platforms without the dedicated power module... + # 208 is CM_WIFI_CTRL + ./luajit frontend/device/kobo/ntx_io.lua 208 1 + fi fi fi # Moar sleep! usleep 250000 + +# Load WiFi modules # NOTE: Used to be exported in WIFI_MODULE_PATH before FW 4.23 if ! grep -q "^${WIFI_MODULE}" "/proc/modules"; then # Set the Wi-Fi regulatory domain properly if necessary... @@ -42,30 +60,81 @@ if ! grep -q "^${WIFI_MODULE}" "/proc/modules"; then "8821cs") WIFI_COUNTRY_CODE_PARM="rtw_country_code=${WIFI_COUNTRY_CODE}" ;; + "moal") + WIFI_COUNTRY_CODE_PARM="reg_alpha2=${WIFI_COUNTRY_CODE}" + ;; esac fi + VENDOR_WIFI_PARM="" + case "${WIFI_MODULE}" in + "moal") + # NXP's driver for the Marvell 88W8987 RF SoC needs to be told what to choose between client, AP & WiFi DIRECT mode. + VENDOR_WIFI_PARM="mod_para=nxp/wifi_mod_para_sd8987.conf" + + # And, of course, it requires a submodule... + WIFI_DEP_MOD="mlan" + if [ -e "/drivers/${PLATFORM}/wifi/${WIFI_DEP_MOD}.ko" ]; then + insmod "/drivers/${PLATFORM}/wifi/${WIFI_DEP_MOD}.ko" + elif [ -e "/drivers/${PLATFORM}/${WIFI_DEP_MOD}.ko" ]; then + insmod "/drivers/${PLATFORM}/${WIFI_DEP_MOD}.ko" + fi + # NOTE: Nickel sleeps for two whole seconds after each module loading. + # Let's try our usual timing instead... + usleep 250000 + ;; + esac + + WIFI_PARM="" + if [ -n "${WIFI_COUNTRY_CODE_PARM}" ]; then + if [ -n "${WIFI_PARM}" ]; then + WIFI_PARM="${WIFI_PARM} ${WIFI_COUNTRY_CODE_PARM}" + else + WIFI_PARM="${WIFI_COUNTRY_CODE_PARM}" + fi + fi + if [ -n "${VENDOR_WIFI_PARM}" ]; then + if [ -n "${WIFI_PARM}" ]; then + WIFI_PARM="${WIFI_PARM} ${VENDOR_WIFI_PARM}" + else + WIFI_PARM="${VENDOR_WIFI_PARM}" + fi + fi + if [ -e "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" ]; then - if [ -n "${WIFI_COUNTRY_CODE_PARM}" ]; then - insmod "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" "${WIFI_COUNTRY_CODE_PARM}" + if [ -n "${WIFI_PARM}" ]; then + # shellcheck disable=SC2086 + insmod "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" ${WIFI_PARM} else insmod "/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" fi elif [ -e "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ]; then # NOTE: Modules are unsorted on Mk. 8 - if [ -n "${WIFI_COUNTRY_CODE_PARM}" ]; then - insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" "${WIFI_COUNTRY_CODE_PARM}" + if [ -n "${WIFI_PARM}" ]; then + # shellcheck disable=SC2086 + insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" ${WIFI_PARM} else insmod "/drivers/${PLATFORM}/${WIFI_MODULE}.ko" fi fi fi + # Race-y as hell, don't try to optimize this! -sleep 1 +# NOTE: We're after a module insert, meaning Nickel may sleep for two whole seconds here. +case "${WIFI_MODULE}" in + "moal") + # NOTE: Bringup may be genuinely slower than usual with this chip, so, mimic Nickel's sleep patterns. + sleep 2 + ;; + *) + sleep 1 + ;; +esac +# Bring the network interface up & setup WiFi ifconfig "${INTERFACE}" up [ "${WIFI_MODULE}" = "dhd" ] && wlarm_le -i "${INTERFACE}" up pkill -0 wpa_supplicant || env -u LD_LIBRARY_PATH \ - wpa_supplicant -D wext -s -i "${INTERFACE}" -c /etc/wpa_supplicant/wpa_supplicant.conf -O /var/run/wpa_supplicant -B + wpa_supplicant -D "${WPA_SUPPLICANT_DRIVER}" -s -i "${INTERFACE}" -c /etc/wpa_supplicant/wpa_supplicant.conf -C /var/run/wpa_supplicant -B diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index d2ac31caa..0cb56b9a4 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -191,6 +191,7 @@ if [ "${VIA_NICKEL}" = "true" ]; then # If bluetooth is enabled, kill it. if [ -e "/sys/devices/platform/bt/rfkill/rfkill0/state" ]; then + # That's on sunxi, at least IFS= read -r bt_state <"/sys/devices/platform/bt/rfkill/rfkill0/state" if [ "${bt_state}" = "1" ]; then echo "0" >"/sys/devices/platform/bt/rfkill/rfkill0/state" @@ -199,6 +200,10 @@ if [ "${VIA_NICKEL}" = "true" ]; then ./luajit frontend/device/kobo/ntx_io.lua 126 0 fi fi + if grep -q "^sdio_bt_pwr" "/proc/modules"; then + # And that's on NXP SoCs + rmmod sdio_bt_pwr + fi # Flush disks, might help avoid trashing nickel's DB... sync diff --git a/platform/kobo/nickel.sh b/platform/kobo/nickel.sh index 4b81c77a3..0950e00b6 100755 --- a/platform/kobo/nickel.sh +++ b/platform/kobo/nickel.sh @@ -66,21 +66,41 @@ if grep -q "^${WIFI_MODULE}" "/proc/modules"; then usleep 250000 rmmod "${WIFI_MODULE}" - if grep -q "^sdio_wifi_pwr" "/proc/modules"; then - if [ -n "${CPUFREQ_DVFS}" ]; then - echo "0" >"/sys/devices/platform/mxc_dvfs_core.0/enable" - # Leave Nickel in its usual state, don't try to use conservative - echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" - cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" + WIFI_DEP_MOD="" + SKIP_SDIO_PWR_MODULE="" + case "${WIFI_MODULE}" in + "moal") + WIFI_DEP_MOD="mlan" + SKIP_SDIO_PWR_MODULE="1" + ;; + esac + if [ -n "${WIFI_DEP_MOD}" ]; then + if grep -q "^${WIFI_DEP_MOD}" "/proc/modules"; then + usleep 250000 + rmmod "${WIFI_DEP_MOD}" fi - usleep 250000 - rmmod sdio_wifi_pwr fi - # Poke the kernel via ioctl on platforms without the dedicated power module... - if [ ! -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then + if [ -n "${SKIP_SDIO_PWR_MODULE}" ]; then usleep 250000 "${KOREADER_DIR}"/luajit "${KOREADER_DIR}"/frontend/device/kobo/ntx_io.lua 208 0 + else + if grep -q "^sdio_wifi_pwr" "/proc/modules"; then + if [ -n "${CPUFREQ_DVFS}" ]; then + echo "0" >"/sys/devices/platform/mxc_dvfs_core.0/enable" + # Leave Nickel in its usual state, don't try to use conservative + echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" + cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" + fi + usleep 250000 + rmmod sdio_wifi_pwr + fi + + # Poke the kernel via ioctl on platforms without the dedicated power module... + if [ ! -e "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" ]; then + usleep 250000 + "${KOREADER_DIR}"/luajit "${KOREADER_DIR}"/frontend/device/kobo/ntx_io.lua 208 0 + fi fi fi