From bb8092d6a1994f4dd2f8df464eb20de6e60d4694 Mon Sep 17 00:00:00 2001 From: Marco Cutecchia Date: Thu, 16 Mar 2023 11:12:11 +0100 Subject: Kernel: Allow enabling high level detection on GPIOs Co-authored-by: Timon Kruiper Co-authored-by: Ollrogge --- Kernel/Arch/aarch64/RPi/GPIO.cpp | 15 +++++++++++++++ Kernel/Arch/aarch64/RPi/GPIO.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Kernel/Arch/aarch64/RPi/GPIO.cpp b/Kernel/Arch/aarch64/RPi/GPIO.cpp index 7878729b06..aef8d3e5c4 100644 --- a/Kernel/Arch/aarch64/RPi/GPIO.cpp +++ b/Kernel/Arch/aarch64/RPi/GPIO.cpp @@ -94,4 +94,19 @@ void GPIO::internal_enable_pins(u32 enable[2], PullUpDownState state) // I don't know if the RPi3 has that already, so this uses the old BCM2835 approach for now. } +void GPIO::set_pin_high_detect_enable(unsigned pin_number, bool enable) +{ + if (enable) { + if (pin_number < 32) + m_registers->high_detect_enable.bits[0] = m_registers->high_detect_enable.bits[0] | (1 << pin_number); + else + m_registers->high_detect_enable.bits[1] = m_registers->high_detect_enable.bits[1] | (1 << (pin_number - 32)); + } else { + if (pin_number < 32) + m_registers->high_detect_enable.bits[0] = m_registers->high_detect_enable.bits[0] & ~(1 << pin_number); + else + m_registers->high_detect_enable.bits[1] = m_registers->high_detect_enable.bits[1] & ~(1 << (pin_number - 32)); + } +} + } diff --git a/Kernel/Arch/aarch64/RPi/GPIO.h b/Kernel/Arch/aarch64/RPi/GPIO.h index a24a51dbdb..a01e276251 100644 --- a/Kernel/Arch/aarch64/RPi/GPIO.h +++ b/Kernel/Arch/aarch64/RPi/GPIO.h @@ -50,6 +50,8 @@ public: internal_enable_pins(enable, state); } + void set_pin_high_detect_enable(unsigned pin_number, bool enable); + private: GPIO(); void internal_enable_pins(u32 enable[2], PullUpDownState state); -- cgit v1.2.3