| // Copyright 2020 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SRC_DEVICES_RTC_DRIVERS_PL031_RTC_PL031_RTC_H_ |
| #define SRC_DEVICES_RTC_DRIVERS_PL031_RTC_PL031_RTC_H_ |
| |
| #include <fuchsia/hardware/rtc/llcpp/fidl.h> |
| |
| #include <ddk/device.h> |
| #include <ddktl/device.h> |
| #include <lib/mmio/mmio.h> |
| |
| namespace rtc { |
| |
| class Pl031; |
| using RtcDeviceType = ddk::Device<Pl031, ddk::Messageable>; |
| namespace FidlRtc = llcpp::fuchsia::hardware::rtc; |
| |
| struct Pl031Regs { |
| uint32_t dr; |
| uint32_t mr; |
| uint32_t lr; |
| uint32_t cr; |
| uint32_t msc; |
| uint32_t ris; |
| uint32_t mis; |
| uint32_t icr; |
| }; |
| |
| class Pl031 : public FidlRtc::Device::Interface, public RtcDeviceType { |
| public: |
| static zx_status_t Bind(void*, zx_device_t* dev); |
| |
| Pl031(zx_device_t* parent, ddk::MmioBuffer mmio); |
| ~Pl031() = default; |
| |
| // FidlRtc::Device::Interface: |
| void Get(GetCompleter::Sync& completer) override; |
| void Set(FidlRtc::Time rtc, SetCompleter::Sync& completer) override; |
| |
| // DDK bindings. |
| zx_status_t DdkMessage(fidl_incoming_msg_t* msg, fidl_txn_t* txn); |
| void DdkRelease(); |
| |
| private: |
| zx_status_t SetRtc(FidlRtc::Time rtc); |
| |
| ddk::MmioBuffer mmio_; |
| MMIO_PTR Pl031Regs* regs_; |
| }; |
| |
| } // namespace rtc |
| |
| #endif // SRC_DEVICES_RTC_DRIVERS_PL031_RTC_PL031_RTC_H_ |