1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 10:47:44 +00:00
serenity/Kernel/Arch/aarch64/GPIO.h
Jakub V. Flasar 6d2c298b66 Kernel: Move aarch64 Prekernel into Kernel
As there is no need for a Prekernel on aarch64, the Prekernel code was
moved into Kernel itself. The functionality remains the same.

SERENITY_KERNEL_AND_INITRD in run.sh specifies a kernel and an inital
ramdisk to be used by the emulator. This is needed because aarch64
does not need a Prekernel and the other ones do.
2022-03-12 14:54:12 -08:00

60 lines
1.2 KiB
C++

/*
* Copyright (c) 2021, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Array.h>
#include <AK/Types.h>
namespace Prekernel {
struct GPIOControlRegisters;
// Can configure the general-purpose I/O registers on a Raspberry Pi.
class GPIO {
public:
enum class PinFunction {
Input = 0,
Output = 1,
Alternate0 = 0b100,
Alternate1 = 0b101,
Alternate2 = 0b110,
Alternate3 = 0b111,
Alternate4 = 0b011,
Alternate5 = 0b010,
};
static GPIO& the();
void set_pin_function(unsigned pin_number, PinFunction);
enum class PullUpDownState {
Disable = 0,
PullDown = 1,
PullUp = 2,
};
template<size_t N>
void set_pin_pull_up_down_state(Array<int, N> pins, PullUpDownState state)
{
u32 enable[2] = {};
for (int pin : pins) {
if (pin < 32)
enable[0] |= (1 << pin);
else
enable[1] |= (1 << (pin - 32));
}
internal_enable_pins(enable, state);
}
private:
GPIO();
void internal_enable_pins(u32 enable[2], PullUpDownState state);
GPIOControlRegisters volatile* m_registers;
};
}