From 4f4b1e523ab59e6acc3bbafe6bd2f336594edbe5 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 21 Jun 2022 21:21:18 +0200 Subject: [PATCH] Kobo: Handle the new Libra 2 hardware revision properly (#9234) Includes a base bump for KoboUSBMS (https://github.com/koreader/koreader-base/pull/1493) Fix #9218 --- base | 2 +- frontend/device/kobo/device.lua | 84 +++++++++++++++++++++++++++++---- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/base b/base index df5325794..8a8722a49 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit df53257942c6fd4c22b4ae86f808beafabfaa121 +Subproject commit 8a8722a491ed7897bb8eaa0c2e9e8c05b54e1104 diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 2b75a6137..f1e43704f 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -1,8 +1,9 @@ local Generic = require("device/generic/device") local Geom = require("ui/geometry") local WakeupMgr = require("device/wakeupmgr") +local ffiUtil = require("ffi/util") local logger = require("logger") -local util = require("ffi/util") +local util = require("util") local _ = require("gettext") -- We're going to need a few & constants... @@ -105,12 +106,16 @@ local Kobo = Generic:new{ ntx_dev = "/dev/input/event0", -- Stable path to the Touch input device touch_dev = "/dev/input/event1", + -- Stable path to the Power Button input device + power_dev = nil, -- Event code to use to detect contact pressure pressure_event = nil, -- Device features multiple CPU cores isSMP = no, -- Device supports "eclipse" waveform modes (i.e., optimized for nightmode). hasEclipseWfm = no, + -- Device ships with various hardware revisions under the same device code, requirign automatic hardware detection... + automagic_sysfs = false, unexpected_wakeup_count = 0 } @@ -414,7 +419,6 @@ local KoboIo = Kobo:new{ hasNaturalLight = yes, frontlight_settings = { frontlight_white = "/sys/class/backlight/mxc_msp430.0/brightness", - frontlight_mixer = "/sys/class/backlight/lm3630a_led/color", -- Warmth goes from 0 to 10 on the device's side (our own internal scale is still normalized to [0...100]) -- NOTE: Those three extra keys are *MANDATORY* if frontlight_mixer is set! nl_min = 0, @@ -424,6 +428,10 @@ local KoboIo = Kobo:new{ -- It would appear that the Libra 2 inherited its ancestor's quirks, and more... -- c.f., https://github.com/koreader/koreader/issues/8414 & https://github.com/koreader/koreader/issues/8664 hasReliableMxcWaitFor = no, + -- NOTE: There are at least two hardware revisions of this device (*without* a device code change, this time), + -- with *significant* hardware changes, so we'll handle this by making the sysfs path discovery automagic. + -- c.f., https://github.com/koreader/koreader/issues/9218 + automagic_sysfs = true, } function Kobo:setupChargingLED() @@ -514,6 +522,57 @@ function Kobo:init() end end + -- Automagic sysfs discovery + if self.automagic_sysfs then + -- Battery + if util.pathExists("/sys/class/power_supply/battery") then + -- Newer devices (circa sunxi) + self.battery_sysfs = "/sys/class/power_supply/battery" + else + self.battery_sysfs = "/sys/class/power_supply/mc13892_bat" + end + + -- Frontlight + if self:hasNaturalLight() then + if util.fileExists("/sys/class/leds/aw99703-bl_FL1/color") then + -- HWConfig FL_PWM is AW99703x2 + self.frontlight_settings.frontlight_mixer = "/sys/class/leds/aw99703-bl_FL1/color" + elseif util.fileExists("/sys/class/backlight/lm3630a_led/color") then + -- HWConfig FL_PWM is LM3630 + self.frontlight_settings.frontlight_mixer = "/sys/class/backlight/lm3630a_led/color" + elseif util.fileExists("/sys/class/backlight/tlc5947_bl/color") then + -- HWConfig FL_PWM is TLC5947 + self.frontlight_settings.frontlight_mixer = "/sys/class/backlight/tlc5947_bl/color" + end + end + + -- Input + if util.fileExists("/dev/input/by-path/platform-1-0010-event") then + -- Elan (HWConfig TouchCtrl is ekth6) + self.touch_dev = "/dev/input/by-path/platform-1-0010-event" + else + self.touch_dev = "/dev/input/event1" + end + + if util.fileExists("/dev/input/by-path/platform-gpio-keys-event") then + -- Libra 2 w/ a BD71828 PMIC + self.ntx_dev = "/dev/input/by-path/platform-gpio-keys-event" + elseif util.fileExists("/dev/input/by-path/platform-ntx_event0-event") then + -- sunxi & Mk. 7 + self.ntx_dev = "/dev/input/by-path/platform-ntx_event0-event" + elseif util.fileExists("/dev/input/by-path/platform-mxckpd-event") then + -- circa Mk. 5 i.MX + self.ntx_dev = "/dev/input/by-path/platform-mxckpd-event" + else + self.ntx_dev = "/dev/input/event0" + end + + if util.fileExists("/dev/input/by-path/platform-bd71828-pwrkey-event") then + -- Libra 2 w/ a BD71828 PMIC + self.power_dev = "/dev/input/by-path/platform-bd71828-pwrkey-event" + end + end + -- Automagically set this so we never have to remember to do it manually ;p if self:hasNaturalLight() and self.frontlight_settings and self.frontlight_settings.frontlight_mixer then self.hasNaturalLightMixer = yes @@ -563,10 +622,19 @@ function Kobo:init() Generic.init(self) - -- When present, event2 is the raw accelerometer data (3-Axis Orientation/Motion Detection) - self.ntx_fd = self.input.open(self.ntx_dev) -- Various HW Buttons, Switches & Synthetic NTX events + -- Various HW Buttons, Switches & Synthetic NTX events + self.ntx_fd = self.input.open(self.ntx_dev) + -- Dedicated Power Button input device (if any) + if self.power_dev then + self.input.open(self.power_dev) + end + -- Touch panel self.input.open(self.touch_dev) - -- fake_events is only used for usb plug event so far + -- NOTE: On devices with a gyro, there may be a dedicated input device outputting the raw accelerometer data + -- (3-Axis Orientation/Motion Detection). + -- We skip it because we don't need it (synthetic rotation change events are sent to the main ntx input device), + -- and it's usually *extremely* verbose, so it'd just be a waste of processing power. + -- fake_events is only used for usb plug & charge events so far (generated via uevent, c.f., input/iput-kobo.h in base). -- NOTE: usb hotplug event is also available in /tmp/nickel-hardware-status (... but only when Nickel is running ;p) self.input.open("fake_events") @@ -753,7 +821,7 @@ function Kobo:getFirmwareVersion() version_file:close() local i = 0 - for field in util.gsplit(version_str, ",", false, false) do + for field in ffiUtil.gsplit(version_str, ",", false, false) do i = i + 1 if (i == 3) then self.firmware_rev = field @@ -901,7 +969,7 @@ function Kobo:suspend() logger.warn("Kobo suspend: the kernel refused to flag subsystems for suspend!") end - util.sleep(2) + ffiUtil.sleep(2) logger.info("Kobo suspend: waited for 2s because of reasons...") os.execute("sync") @@ -996,7 +1064,7 @@ function Kobo:resume() end -- HACK: wait a bit (0.1 sec) for the kernel to catch up - util.usleep(100000) + ffiUtil.usleep(100000) if self.hasIRGrid then -- cf. #1862, I can reliably break IR touch input on resume...