/* * Copyright (c) 2022, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Kernel { struct [[gnu::packed]] GMBusRegisters { u32 clock; u32 command; u32 status; u32 data; }; enum class GMBusStatus; class GMBusConnector { public: enum PinPair : u8 { None = 0, DedicatedControl = 1, DedicatedAnalog = 0b10, IntegratedDigital = 0b11, sDVO = 0b101, Dconnector = 0b111, }; public: static ErrorOr> create_with_physical_address(PhysicalAddress gmbus_start_address); ErrorOr write(unsigned address, u32 data); ErrorOr read(unsigned address, u8* buf, size_t length); void set_default_rate(); private: void set_pin_pair(PinPair pin_pair); bool wait_for(GMBusStatus desired_status, size_t milliseconds_timeout); explicit GMBusConnector(Memory::TypedMapping); Spinlock m_access_lock; Memory::TypedMapping m_gmbus_registers; }; }